fix: zero-pad years below 1000 in date/datetime formatting - #277
Open
Danish-sarwar1 wants to merge 1 commit into
Open
fix: zero-pad years below 1000 in date/datetime formatting#277Danish-sarwar1 wants to merge 1 commit into
Danish-sarwar1 wants to merge 1 commit into
Conversation
convertDebeziumDate, convertDebeziumMilliseconds and convertDebeziumMicroseconds printed the year with %d, so a MySQL value like 0202-04-17 was serialized to S3 as "202-04-17" (9 chars). Redshift COPY (json 'auto') rejects such values with err 1205 "Invalid Date Format - length must be 10 or more" and the loader retries the same batch forever, stalling the sink and burning cluster cycles. Pad the year with %04d so years below 1000 serialize as valid YYYY-MM-DD and load faithfully. Years 1000-9999 are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughChangesDebezium temporal formatting
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Source MySQL tables contain typo'd temporal values with years < 1000 (e.g.
dob = '0979-02-15',active_start_date = '0202-04-17'). Debezium emits these faithfully as epoch-days/millis/micros, but the batcher's formatters print the year with%d(unpadded), so the S3 JSON carries"202-04-17"— 9 characters.Redshift
COPY … json 'auto'rejects such values ondate/timestampcolumns:The loader then aborts and retries the same batch forever — the sink stalls and Redshift burns cycles re-running the same COPY every ~40s.
This stalled 9 sinks in production (availability, contacts ×2, payments, posttreatment ×2, soap_notes ×2) for 20–30+ hours each during the new-pipeline reloads. The bug has been latent since 2020 (
01d02bb); day-to-day streaming rarely carries such rows, but full re-snapshots push every historical row through this path.Fix
%04dfor the year inconvertDebeziumDate,convertDebeziumMilliseconds,convertDebeziumMicroseconds. Years 1000–9999 format byte-identically to before (the pre-existing test cases pass unchanged); years < 1000 now serialize as validYYYY-MM-DDand load into Redshift faithfully (0202-04-17is a valid Redshift date).Tests
Extended
TestConvertDebeziumFormattedTime:1970-01-01), recent (2022-07-08), max (9999-12-31) — plus the pre-existing 1934/1988/2020 cases, all unchanged0999-12-31/1000-01-010202-04-17,0979-02-15; DATETIME (ms path)0204-10-15 00:00:00; DATETIME(6) (µs path)0201-08-01 10:30:00.757000gofmt,go vet, and the fullgo test ./cmd/... ./pkg/...suite pass in the CI image (public.ecr.aws/practo/golang:1.17.1-alpine).Note on already-produced batches
This fixes files the batcher writes after rollout. Batches already uploaded to S3 with unpadded years still fail COPY — currently being drained by padding them in place in S3; adding
ACCEPTANYDATEto the loader COPY options is a possible follow-up safety net.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests