-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add timestamp-nanos avro logical type support in bigquery avro utils. #36892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
bcdd5ea to
d234446
Compare
d234446 to
1d0a0ef
Compare
88b51f4 to
e8c61c5
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for the timestamp-nanos Avro logical type as a workaround until the Avro version can be upgraded. The changes are primarily in AvroUtils and BigQueryAvroUtils. The implementation is functionally correct and includes good test coverage for edge cases. However, some parts of the implementation rely on implicit behaviors of java.time.Instant, which can be obscure. I've provided a few suggestions to make the code more explicit and maintainable. Additionally, I've suggested a cleaner way to construct an Avro schema programmatically instead of parsing a JSON string.
...tensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java
Outdated
Show resolved
Hide resolved
...tensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java
Outdated
Show resolved
Hide resolved
...ogle-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryAvroUtils.java
Outdated
Show resolved
Hide resolved
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
R: @Abacn |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
timestamp-nanos avro logical type was introduced in avro 1.12, but beam cannot upgrade avro versions until java 8 support is dropped #34993
There are workarounds here to handle the timestamp-nanos logical type until we can update avro version.
AvroUtils changes:
toBeamFieldType(): Recognizestimestamp-nanosproperty and maps toTimestamp.NANOStoAvroSchema(): ConvertsTimestamp.NANOSto Avro schema withtimestamp-nanoslogical typetoGenericRecord(): ConvertsInstantvalues to nanoseconds since epochtoBeamRowStrict(): Converts nanosecond values back toInstantobjectsBigQueryAvroUtils changes:
TimestampPrecisionenumNANOSECONDSprecision level alongside existingMILLISECONDSandMICROSECONDSconvertRequiredField()to handletimestamp-nanoslogical typeformatDatetime()to dynamically format fractional seconds (3, 6, or 9 digits)fromGenericAvroSchema()to maptimestamp-nanosto BigQuery TIMESTAMP typeThank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.