Skip to content

format Datastream timestamp literals for MySQL - #4520

Open
mvanhorn wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
mvanhorn:fix/2942-mysql-datastream-timestamp-literals
Open

mvanhorn wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
mvanhorn:fix/2942-mysql-datastream-timestamp-literals

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 3, 2026

Copy link
Copy Markdown

Background

Rows containing timestamp values fail to write to MySQL because it rejects ISO timestamp literals with a trailing Z or offset.

The MySQL DML handler passed offset timestamp literals through without converting them to MySQL's datetime format.

Summary of the fix

The MySQL handler now formats quoted TIMESTAMP values as UTC datetime literals with up to six fractional digits. Local timestamps, unparseable values, other column types, and PostgreSQL behavior remain unchanged.

Verification

The command mvn -B -ntp -pl v2/datastream-to-sql -am test -Dtest=DatastreamToDMLTest -Dsurefire.failIfNoSpecifiedTests=false passed all 71 tests. The tests in v2/datastream-to-sql/src/test/java/com/google/cloud/teleport/v2/utils/DatastreamToDMLTest.java fail without the fix in the DataflowTemplates DatastreamToMySQLDML change (checked by reverting the source changes).

Fixes #2942

The MySQL handler now formats quoted TIMESTAMP values as UTC datetime
literals with up to six fractional digits. Local timestamps, unparseable
values, other column types, and PostgreSQL behavior remain unchanged.

Fixes GoogleCloudPlatform#2942
@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 addresses an issue where Datastream rows containing timestamp values failed to write to MySQL due to incompatible ISO timestamp literal formats. The changes introduce a dedicated formatting utility within the MySQL DML handler to sanitize these values into a format accepted by MySQL, ensuring reliable data migration while maintaining backward compatibility for other data types and PostgreSQL behavior.

Highlights

  • MySQL Timestamp Formatting: Implemented a new formatter in DatastreamToMySQLDML to convert ISO timestamp literals into MySQL-compatible datetime format, ensuring compatibility by removing trailing 'Z' or offset indicators.
  • Data Integrity: Added logic to convert timestamps to UTC and support up to six fractional digits, while preserving existing behavior for non-timestamp columns and invalid formats.
  • Verification: Added comprehensive unit tests in DatastreamToDMLTest to validate timestamp conversion, edge cases, and column casing scenarios.
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. ↩

@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 introduces timestamp formatting logic in DatastreamToMySQLDML to parse ISO-8601 timestamp literals and format them to UTC for MySQL TIMESTAMP columns, along with comprehensive unit tests. The review feedback suggests adding a defensive null check for tableSchema to prevent potential NullPointerExceptions, extending this formatting logic to support DATETIME columns as well, and updating the unit tests to cover both column types.

@pull-request-size pull-request-size Bot added size/L and removed size/M labels Nov 3, 2026
@mvanhorn
mvanhorn force-pushed the fix/2942-mysql-datastream-timestamp-literals branch from 3141e32 to fd89a9c Compare November 3, 2026 19:53
@pull-request-size pull-request-size Bot added size/M and removed size/L labels Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 participant