Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

clairemcginty
Copy link
Contributor

I noticed that in Beam 2.63, TIME types were being encoded incorrectly when using the Storage Write API. For example, I'd try to write a value of 6:30 and it would get written to BQ as 5:28. See #34038.

I looked at what the other *ToStorageApiProto classes were doing (TableRowToStorageApiProto, BeamRowToStorageApiProto) and noticed they were using this CivilTimeEncoder class to translate TIME types to Longs, whereas AvroGenericRecordToStorageApiProto was trying to compute manually from milliseconds/microseconds of day. It's a small difference but it accounts for the BQ discrepancies.

I've tested this out locally when writing to BQ and the values look correct now, but I would definitely appreciate someone with more domain knowledge checking in! Also, looks should maybe be using this encoder for DATETIME types, too?


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

.put("datevalue", 42)
.put("timemicrosvalue", 42_000_000L)
.put("timemillisvalue", 42_000_000L)
.put("timemicrosvalue", CivilTimeEncoder.encodePacked64TimeMicros(localTime))
Copy link
Contributor Author

@clairemcginty clairemcginty Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious so I checked the difference here. CivilTimeEncoder translates this value to 44,040,192 compared to the original 42,000,000. I do not know why but doing a test write to BQ shows seemingly correct values now 😅

Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@clairemcginty clairemcginty force-pushed the fix-storage-proto-time-encoding branch from b2f0894 to 6fd52aa Compare February 25, 2025 02:43
@Abacn
Copy link
Contributor

Abacn commented Feb 27, 2025

Thanks for the fix! Could you please run './gradlew :sdks:java:io:google-cloud-platform:spotlessApply' then push a new commit to format code?

@clairemcginty clairemcginty force-pushed the fix-storage-proto-time-encoding branch from 6fd52aa to 5b992a0 Compare February 27, 2025 17:07
@clairemcginty
Copy link
Contributor Author

ah forgot to mention, the format violations seemed to be in an unrelated file, but it looks like they were just fixed here. Just rebased my PR!

Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @kennknowles for label java.
R: @shunping for label io.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@Abacn Abacn merged commit 6fbdaa2 into apache:master Feb 28, 2025
17 checks passed
VardhanThigle pushed a commit to VardhanThigle/beam that referenced this pull request Mar 21, 2025
…GenericRecordToStorageApiProto (apache#34059)

* (fix apache#34038) Use CivilTimeEncoder to encode Time values in AvroGenericRecordToStorageApiProto

* Update CHANGES

* Don't throw away precision
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants