Skip to content

feat(datastream-to-SQL): Support DELETE replication for tables without Primary Keys using ROWID - #4232

Open
yonatandt wants to merge 5 commits into
mainfrom
feat/sql-rowid-fallback
Open

yonatandt wants to merge 5 commits into
mainfrom
feat/sql-rowid-fallback

Conversation

@yonatandt

Copy link
Copy Markdown
Contributor
  • Fix regression in DatastreamToDML where tables lacking primary keys produced empty WHERE clauses for DELETE events.
  • Add ROWID fallback in getPrimaryKeyToValueFilterSql when primaryKeys is empty or unmapped.
  • Allow getDmlTemplate to generate DELETE DML when rowid or _metadata_row_id is present.
  • Make DatastreamRow getPrimaryKeys and getStringValue null-safe against missing metadata fields.
  • Add unit tests verifying ROWID fallback in DatastreamToDMLTest and DatastreamRowTest.

Fixes b/506993545

@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 a regression in the DatastreamToDML component where DELETE events for tables without primary keys were failing due to empty WHERE clauses. By implementing a ROWID fallback mechanism, the system can now correctly identify and process these deletions. Additionally, the changes improve the robustness of metadata field handling within DatastreamRow to ensure more reliable data processing.

Highlights

  • ROWID Support for DELETE: Added support for using ROWID as a fallback identifier for DELETE operations on tables that lack primary keys.
  • Null-Safety Improvements: Enhanced DatastreamRow to be null-safe when accessing metadata fields, preventing potential crashes during record processing.
  • Unit Testing: Introduced comprehensive unit tests in DatastreamToDMLTest and DatastreamRowTest to verify the new ROWID fallback logic and null-safety fixes.
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.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.27451% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.89%. Comparing base (39361e9) to head (255c22e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...oogle/cloud/teleport/v2/utils/DatastreamToDML.java 83.72% 0 Missing and 7 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4232      +/-   ##
============================================
+ Coverage     55.86%   55.89%   +0.03%     
- Complexity     7490     7507      +17     
============================================
  Files          1135     1135              
  Lines         70313    70357      +44     
  Branches       8040     8061      +21     
============================================
+ Hits          39282    39329      +47     
+ Misses        28480    28472       -8     
- Partials       2551     2556       +5     
Components Coverage Δ
spanner-templates 84.20% <ø> (ø)
spanner-import-export 69.01% <ø> (-0.02%) ⬇️
spanner-live-forward-migration 88.65% <ø> (ø)
spanner-live-reverse-replication 80.36% <ø> (ø)
spanner-bulk-migration 89.06% <ø> (ø)
gcs-spanner-dv 87.98% <ø> (ø)
Files with missing lines Coverage Δ
...d/teleport/v2/datastream/values/DatastreamRow.java 50.00% <100.00%> (+11.42%) ⬆️
...oogle/cloud/teleport/v2/utils/DatastreamToDML.java 42.44% <83.72%> (+7.57%) ⬆️

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

@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 null-safety improvements in DatastreamRow when parsing JSON fields and primary keys, and adds fallback support for row IDs (rowid or _metadata_row_id) when generating DML templates and filters in DatastreamToDML for tables without primary keys. The feedback recommends handling column casing in the row ID fallback logic of getValueSql to prevent issues when casing rules are applied, and refactoring the primary key extraction in DatastreamRow to avoid redundant JSON node lookups.

- Fix regression in DatastreamToDML where tables lacking primary keys produced empty WHERE clauses for DELETE events.
- Add ROWID fallback in getPrimaryKeyToValueFilterSql when primaryKeys is empty or unmapped.
- Allow getDmlTemplate to generate DELETE DML when rowid or _metadata_row_id is present.
- Make DatastreamRow getPrimaryKeys and getStringValue null-safe against missing metadata fields.
- Add unit tests verifying ROWID fallback in DatastreamToDMLTest and DatastreamRowTest.

Fixes b/506993545
@yonatandt
yonatandt force-pushed the feat/sql-rowid-fallback branch from da8f43e to 20c621d Compare September 8, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants