Skip to content

4 Byte PK support - #4010

Open
sm745052 wants to merge 17 commits into
mainfrom
4b_support
Open

4 Byte PK support#4010
sm745052 wants to merge 17 commits into
mainfrom
4b_support

Conversation

@sm745052

@sm745052 sm745052 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This PR updates the uniform splitter to correctly handle 4-byte string characters (like emojis) in primary keys during SourceDB to Spanner migrations.
Previously, the string mapper used Java char types. Since char is limited to 2 bytes, it cannot represent 4-byte characters without surrogate pairs. Refactored CollationIndex, CollationMapper, and CollationOrderRow to use String representations instead. This removes the byte length constraints.
I also updated the MySQL and PostgreSQL collation order SQL queries to accurately handle these characters in range calculations.

To verify the fixes, I added two new integration tests that copy tables with 4-byte primary keys:

  • MySQLSourceDbToSpanner4ByteStringPKIT
  • PostgreSQLSourceDbToSpanner4ByteStringPKIT

Logs showing all characters were captured:

MySQL

Initialized Index ALL_POSITIONS for CollationReference{dbCharacterSet=`utf8mb4`, dbCollation=`utf8mb4_bin`, padSpace=true}, with 1112064 characters, 1112064 unique characters, and {} empty characters

PG

Initialized Index ALL_POSITIONS for CollationReference{dbCharacterSet=UTF8, dbCollation=default, padSpace=false}, with 1112063 characters, 1112063 unique characters, and {} empty characters

I increased the DirectRunner test timeout to 15 minutes in SourceDbToSpannerITBase although the tests use DataflowRunner in github actions so that we can test these tests locally using direct runner (the default timeout there was 4 min)

@sm745052
sm745052 requested a review from a team as a code owner July 10, 2026 05:55
@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 introduces support for 4-byte character sets (such as emojis) in primary keys during source database to Spanner migrations. The changes involve refining the collation order logic for both MySQL and PostgreSQL to ensure these characters are correctly processed and validated, alongside new integration tests to validate the end-to-end migration flow.

Highlights

  • 4-Byte Character Support: Updated SQL collation queries for MySQL and PostgreSQL to correctly handle 4-byte UTF-8 characters (like emojis) in primary keys.
  • Integration Testing: Added new integration tests for both MySQL and PostgreSQL to verify the migration of tables containing 4-byte string primary keys.
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.

@sm745052
sm745052 marked this pull request as draft July 10, 2026 05:55

@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 the collation order queries for MySQL and PostgreSQL to support 4-byte UTF-8 characters and adds corresponding integration tests. Feedback highlights a significant performance concern in the MySQL query due to the massive increase in rows (to over 1.1 million) processed during 4-byte codepoint generation, which could cause high CPU/IO load and disk sorting. Additionally, the new integration tests should be refactored to use instance fields instead of static fields for resource managers and to declare the Dataflow job info as a local variable.

Comment thread v2/sourcedb-to-spanner/src/main/resources/sql/mysql_collation_order_query.sql Outdated
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.87%. Comparing base (a73f5e5) to head (b14d2b8).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
...niformsplitter/stringmapper/CollationOrderRow.java 50.00% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4010      +/-   ##
============================================
+ Coverage     55.74%   63.87%   +8.12%     
+ Complexity     7241     2685    -4556     
============================================
  Files          1124      556     -568     
  Lines         68476    31520   -36956     
  Branches       7726     3483    -4243     
============================================
- Hits          38173    20132   -18041     
+ Misses        27826    10353   -17473     
+ Partials       2477     1035    -1442     
Components Coverage Δ
spanner-templates 87.54% <87.87%> (-0.13%) ⬇️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 89.24% <ø> (-0.05%) ⬇️
spanner-live-reverse-replication 83.43% <ø> (-0.04%) ⬇️
spanner-bulk-migration 92.21% <87.87%> (-0.28%) ⬇️
gcs-spanner-dv 88.52% <ø> (-0.03%) ⬇️
Files with missing lines Coverage Δ
...c/uniformsplitter/stringmapper/CollationIndex.java 97.29% <100.00%> (+0.11%) ⬆️
.../uniformsplitter/stringmapper/CollationMapper.java 98.26% <100.00%> (+0.98%) ⬆️
...niformsplitter/stringmapper/CollationOrderRow.java 86.66% <50.00%> (-9.89%) ⬇️

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

@sm745052
sm745052 force-pushed the 4b_support branch 8 times, most recently from 88454e5 to 5c85c66 Compare July 10, 2026 07:44
@sm745052
sm745052 force-pushed the 4b_support branch 2 times, most recently from 818d1f6 to 64bdb18 Compare July 13, 2026 06:08
@sm745052
sm745052 force-pushed the 4b_support branch 2 times, most recently from bce030a to 1b0a869 Compare July 13, 2026 07:37
@sm745052
sm745052 marked this pull request as ready for review July 22, 2026 08:13

@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 the collation mapping classes to use String instead of Character to support multi-byte characters (such as 4-byte UTF-8 emojis) and adds corresponding integration tests for MySQL and PostgreSQL. The review feedback highlights a critical bug where reference equality (== and !=) is used with BigInteger.ZERO instead of .equals(), which can lead to infinite loops during deserialization. Additionally, suggestions are provided to simplify padding calculations and use Java 8 streams for more idiomatic code point extraction.

@bharadwaj-aditya
bharadwaj-aditya requested review from bharadwaj-aditya and removed request for dhwanilpatel July 23, 2026 08:12

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

Thanks for putting this together. This flow looks a lot simpler.

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