Skip to content

fix(Spanner): Live: handle SQL Server datetime records and shard ids - #4498

Merged
pratickchokhani merged 3 commits into
GoogleCloudPlatform:mainfrom
pratickchokhani:sqlserver-live-migration-datatime
Nov 4, 2026
Merged

pratickchokhani merged 3 commits into
GoogleCloudPlatform:mainfrom
pratickchokhani:sqlserver-live-migration-datatime

Conversation

@pratickchokhani

@pratickchokhani pratickchokhani commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
  • FormatDatastreamRecordToJson: decode Datastream's SQL Server datetime Avro RECORD ({date: epoch days, time: micros}) into an ISO-8601 UTC wall-clock string (using floorDiv/floorMod, so pre-1970 values are correct). Downstream ChangeEventTypeConvertor already parses that string for TIMESTAMP, DATE and STRING targets, and custom transformations now receive a string instead of a nested map.
  • ChangeEventSessionConvertor: populate migration_shard_id for sqlserver sources (previously only mysql/oracle).
  • SQLServerDatastreamToSpannerDataTypesIT: assert datetime, datetime2 and smalldatetime values (TIMESTAMP, STRING and PK variants) instead of NULL only.

@pratickchokhani pratickchokhani added the addition New feature or request label Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 57.06%. Comparing base (7516e85) to head (48d1be4).

Files with missing lines Patch % Lines
...ations/convertors/ChangeEventSessionConvertor.java 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4498      +/-   ##
============================================
+ Coverage     57.04%   57.06%   +0.02%     
- Complexity     7687     8145     +458     
============================================
  Files          1167     1167              
  Lines         74470    74484      +14     
  Branches       8810     8812       +2     
============================================
+ Hits          42481    42504      +23     
+ Misses        29149    29142       -7     
+ Partials       2840     2838       -2     
Components Coverage Δ
spanner-templates 84.01% <80.00%> (+<0.01%) ⬆️
spanner-import-export 72.31% <ø> (+0.12%) ⬆️
spanner-live-forward-migration 87.66% <80.00%> (+0.01%) ⬆️
spanner-live-reverse-replication 79.85% <80.00%> (+0.01%) ⬆️
spanner-bulk-migration 88.30% <80.00%> (+0.01%) ⬆️
gcs-spanner-dv 86.56% <80.00%> (+0.02%) ⬆️
Files with missing lines Coverage Δ
...tream/transforms/FormatDatastreamRecordToJson.java 60.25% <100.00%> (+1.12%) ⬆️
...ations/convertors/ChangeEventSessionConvertor.java 87.50% <80.00%> (+1.03%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pratickchokhani
pratickchokhani marked this pull request as ready for review October 29, 2026 11:27
@pratickchokhani
pratickchokhani requested a review from a team as a code owner October 29, 2026 11:27
@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 improves the migration process from SQL Server to Spanner by addressing issues with how datetime data types are handled and enabling shard ID support. It ensures that complex datetime records are correctly parsed and converted, and it expands the support for sharding logic to include SQL Server sources, which improves the robustness of the migration pipeline.

Highlights

  • SQL Server Datetime Handling: Updated ChangeEventTypeConvertor to correctly decode Datastream's SQL Server datetime Avro RECORD format (date and time fields) into TIMESTAMP, DATE, and STRING targets, while also treating empty strings as NULL.
  • Migration Shard ID Support: Enabled migration_shard_id population for SQL Server sources in ChangeEventSessionConvertor, ensuring consistency with MySQL and Oracle sources.
  • Integration Test Updates: Updated SQLServerDatastreamToSpannerDataTypesIT to assert actual datetime, datetime2, and smalldatetime values instead of skipping them or asserting NULL only.
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 adds support for replicating SQL Server datetime, datetime2, and smalldatetime columns from Datastream to Spanner by parsing the nested Avro datetime record (containing date and time fields) into UTC wall-clock values. It also enables SQL Server sharding support in ChangeEventSessionConvertor and updates integration tests to assert these changes. The review feedback highlights critical improvements to prevent silent data loss and corruption: specifically, ensuring that empty string checks for timestamp and date conversions only apply to textual nodes (to avoid misinterpreting failed parses of non-textual nodes as null), and making the parseDatetimeRecord helper more robust by verifying that the JSON node has exactly two numeric fields.

@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-datatime branch from b25e435 to de746b9 Compare November 2, 2026 05:59
@pratickchokhani
pratickchokhani requested a review from a team as a code owner November 2, 2026 13:53
@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-datatime branch from 7a90f70 to 76d3895 Compare November 3, 2026 05:53

@bharadwaj-aditya bharadwaj-aditya 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.

Couple of minor comments. Rest looks fine.

Pratick Chokhani added 2 commits November 3, 2026 11:34
- ChangeEventTypeConvertor: decode Datastream's SQL Server datetime Avro RECORD
  ({date: epoch days, time: micros}) for TIMESTAMP, DATE and STRING targets and
  treat empty strings as NULL.
- ChangeEventSessionConvertor: populate migration_shard_id for sqlserver sources
  (previously only mysql/oracle).
- SQLServerDatastreamToSpannerDataTypesIT: assert datetime, datetime2 and
  smalldatetime values (TIMESTAMP, STRING and PK variants) instead of NULL only.
…treamRecordToJson

Address review feedback: match the Datastream datetime Avro RECORD by its schema
name where the record is flattened to JSON (next to timestampTz/timeTz) and emit
an ISO-8601 UTC string, consistent with GenericRecordTypeConvertor in bulk
migration. This removes the JSON-shape heuristic from ChangeEventTypeConvertor,
which could misfire on user JSON containing date/time keys and swallowed
unparsed objects as NULL, and it also fixes custom transformations receiving a
nested Map for these columns.
@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-datatime branch from 1f52776 to ff836a7 Compare November 3, 2026 11:39
…ot swallowed

executeSqlScript joins the script lines with spaces before splitting on ';',
so a '--' comment that is not terminated by ';' comments out the following
statement. The comments added before the datetime2_table and datetime_table
inserts swallowed those inserts, leaving the tables empty on the source and
timing out SQLServerDatastreamToSpannerDataTypesIT. End them with ';' like the
other comment blocks in the file.
@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-datatime branch from 25822d9 to 48d1be4 Compare November 3, 2026 14:41

@bharadwaj-aditya bharadwaj-aditya 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.

LGTM

@pratickchokhani
pratickchokhani merged commit c41b4d9 into GoogleCloudPlatform:main Nov 4, 2026
48 checks passed
@pratickchokhani
pratickchokhani deleted the sqlserver-live-migration-datatime branch November 4, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition New feature or request size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants