[Iceberg] Make timestamptz return new Timestamp.MICROS logical type#39344
[Iceberg] Make timestamptz return new Timestamp.MICROS logical type#39344ahmedabu98 wants to merge 7 commits into
Conversation
|
R: @claudevdm can you take a look? |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request updates the IcebergIO connector to improve timestamp precision when reading Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
There was a problem hiding this comment.
Code Review
This pull request updates IcebergIO to read timestamptz columns as the Timestamp.MICROS Beam logical type to preserve microsecond precision, while providing backward compatibility via the --updateCompatibilityVersion option. The review feedback highlights two main improvements: first, using OffsetDateTime.parse(strValue).toInstant() in IcebergUtils to avoid DateTimeParseException when parsing strings with non-UTC timezone offsets; second, refactoring the new test in IcebergIOReadTest into two separate test methods to avoid sequential pipeline executions and properly utilize the TestPipeline rule.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| .put(SqlTypes.DATETIME.getIdentifier(), Types.TimestampType.withoutZone()) | ||
| .put(SqlTypes.UUID.getIdentifier(), Types.UUIDType.get()) | ||
| .put(MicrosInstant.IDENTIFIER, Types.TimestampType.withZone()) | ||
| .put(Timestamp.IDENTIFIER, Types.TimestampType.withZone()) |
There was a problem hiding this comment.
Will using timestamp logical type break xlang python reads?
| * Converts an Iceberg {@link org.apache.iceberg.Schema} to a Beam {@link Schema}, accounting for | ||
| * update compatibility. | ||
| */ | ||
| public static Schema icebergSchemaToBeamSchema( |
There was a problem hiding this comment.
I see some other call sites that do not use the update compat override
| .put(SqlTypes.DATETIME.getIdentifier(), Types.TimestampType.withoutZone()) | ||
| .put(SqlTypes.UUID.getIdentifier(), Types.UUIDType.get()) | ||
| .put(MicrosInstant.IDENTIFIER, Types.TimestampType.withZone()) | ||
| .put(Timestamp.IDENTIFIER, Types.TimestampType.withZone()) |
There was a problem hiding this comment.
What if it is a Timestamp.NANOS? Should we throw if the logical type is not explicitly MICROS?
| .map(tr -> BigQueryUtils.toBeamRow(BEAM_SCHEMA, tr)) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| System.out.println("returned: " + beamRows); |
| .put("gcp_project", OPTIONS.getProject()) | ||
| .put("gcp_location", "us-central1") | ||
| .put("warehouse", warehouse) | ||
| .put("io-impl", "org.apache.iceberg.gcp.gcs.GCSFileIO") |
| } | ||
| } else if (fieldType.isLogicalType(Timestamp.IDENTIFIER)) { | ||
| return VAR_PRECISION_FORMATTER.parse(jsonBQString, java.time.Instant::from); | ||
| try { |
There was a problem hiding this comment.
This is also used by load jobs and direct reads and both of them use the UTC string version right?
I am a bit concerned about cost of try to parse -> throw exception (expensive) -> try again for every single row in those cases.
Can we either do a conditional (check if ends with UTC or if contains :) to infer which approach we should take?
Maybe a future improvement we can make is the caller can pass the API they used to read so we know what type to expect.
| assertEquals(52, actual.atZone(java.time.ZoneOffset.UTC).getMinute()); | ||
| assertEquals(7, actual.atZone(java.time.ZoneOffset.UTC).getSecond()); | ||
| assertEquals(123456000, actual.getNano()); | ||
| String parsableTimestamp = "2024-08-10T16:52:07.123456Z"; |
There was a problem hiding this comment.
Can we add a negative epoch and micros with leading zeros (e.g. .012345) test?
|
|
||
| @Test | ||
| @SuppressWarnings("JavaInstantGetSecondsGetNano") | ||
| public void testToBeamRow_timestampMicros_utcSuffix() { |
There was a problem hiding this comment.
Update test name since it doesnt just test UTC anymore?
The new Timestamp logical type was added in #36705. This PR integrates it in IcebergIO and makes it the return type when reading
timestamptzIceberg columns. It's a breaking change, but we gate it with upgradeCompatibilityVersion pipeline optionThank 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.