Skip to content

[Iceberg] Make timestamptz return new Timestamp.MICROS logical type#39344

Open
ahmedabu98 wants to merge 7 commits into
apache:masterfrom
ahmedabu98:iceberg_micros_timestamp
Open

[Iceberg] Make timestamptz return new Timestamp.MICROS logical type#39344
ahmedabu98 wants to merge 7 commits into
apache:masterfrom
ahmedabu98:iceberg_micros_timestamp

Conversation

@ahmedabu98

Copy link
Copy Markdown
Contributor

The new Timestamp logical type was added in #36705. This PR integrates it in IcebergIO and makes it the return type when reading timestamptz Iceberg columns. It's a breaking change, but we gate it with upgradeCompatibilityVersion pipeline option


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.

@ahmedabu98

Copy link
Copy Markdown
Contributor Author

R: @claudevdm can you take a look?

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 timestamptz columns. By migrating from the legacy Joda-based DATETIME type to the newer Timestamp.MICROS logical type, the connector now preserves microsecond-level data that was previously truncated. To ensure stability for existing pipelines, this change is gated behind the updateCompatibilityVersion pipeline option, allowing users to opt-out of the change by specifying an older version.

Highlights

  • Logical Type Update: Updated IcebergIO to use the new Timestamp.MICROS logical type for timestamptz columns, replacing the legacy DATETIME type to preserve microsecond precision.
  • Compatibility Gating: Implemented a version-gated mechanism using the updateCompatibilityVersion pipeline option, allowing users to retain the legacy behavior if needed.
  • Test Coverage: Added comprehensive tests to verify the new timestamp mapping and ensure that legacy compatibility settings correctly trigger the old behavior.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 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.

@github-actions github-actions Bot added the gcp label Jul 16, 2026
.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())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see some other call sites that do not use the update compat override

return IcebergUtils.icebergSchemaToBeamSchema(table.schema());

.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())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove?

.put("gcp_project", OPTIONS.getProject())
.put("gcp_location", "us-central1")
.put("warehouse", warehouse)
.put("io-impl", "org.apache.iceberg.gcp.gcs.GCSFileIO")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is this for?

}
} else if (fieldType.isLogicalType(Timestamp.IDENTIFIER)) {
return VAR_PRECISION_FORMATTER.parse(jsonBQString, java.time.Instant::from);
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add a negative epoch and micros with leading zeros (e.g. .012345) test?


@Test
@SuppressWarnings("JavaInstantGetSecondsGetNano")
public void testToBeamRow_timestampMicros_utcSuffix() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Update test name since it doesnt just test UTC anymore?

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