Skip to content

Conversation

@aasthabharill
Copy link
Member

@aasthabharill aasthabharill commented Dec 1, 2025

b/464837828
Spanner allows NULL values in Primary key columns (From documentation: "For GoogleSQL-dialect databases, primary key columns are usually annotated with NOT NULL (though you can omit this annotation if you want to allow NULL values in key columns.").

Scenario: Insert a row in Spanner in which one of the PK columns is nullable and has value NULL.

Current behaviour: The query errors out with severe error in AssignShardId step and DLQ com.google.cloud.teleport.v2.spanner.migrations.exceptions.ChangeEventConvertorException: Required key userId not found in change event, Caused by: Required key userId not found in change event

Problem: This error message is incorrect as the changestream shouldnt error out, the source should (in case NULL is not supported)

Expected Behaviour: A row with null PK should pass through spanner and changestream to source and then error out if source does not support NULLs in primary key columns.

Testing

Tested by making a flex container image: gs://ea-functional-tests/templates-aastha-2025-08-12/flex/Spanner_to_SourceDb

After changes, on inserting a row in Spanner with a compound PK in which one of the PK columns is nullable and has value NULL, this is the retriable error that is inserted in DLQ:

{"message":{"commitTimestamp":{"seconds":1765176539,"nanos":325359000},"serverTransactionId":"MTY5NTE4NTU3MjYzOTg1OTM4NQ==","recordSequence":"00000000","tableName":"unified_lgm_event_data","mod":{"keysJson":"{\"ddrkey\":\"-532\",\"slotId\":\"50\",\"userId\":null}","oldValuesJson":"{}","newValuesJson":"{\"attempts\":\"70\",\"createTime\":\"0\",\"eventId\":\"80\",\"intAttrib0\":\"-1\",\"intAttrib1\":\"-1\",\"intAttrib2\":\"-1\",\"intAttrib3\":\"-1\",\"intAttrib4\":\"-1\",\"intAttrib5\":\"-1\",\"intAttrib6\":\"-1\",\"intAttrib7\":\"-1\",\"intAttrib8\":\"-1\",\"intAttrib9\":\"-1\",\"lastAttemptedTime\":\"0\",\"lastCompletedTime\":\"0\",\"lastUpdateTime\":\"0\",\"round\":\"80\",\"status\":\"60\",\"stringAttrib0\":\"\",\"stringAttrib1\":\"\",\"stringAttrib2\":\"\",\"stringAttrib3\":\"\",\"stringAttrib4\":\"\",\"timesAttemptedInInterval\":\"0\"}"},"modType":"INSERT","numberOfRecordsInTransaction":1,"transactionTag":"","shard":"shard1_00","isRetryRecord":false,"_metadata_retry_count":0},"error_message":"UNKNOWN: Column 'userId' cannot be null, Caused by: Column 'userId' cannot be null"}

@aasthabharill aasthabharill requested a review from a team as a code owner December 1, 2025 10:34
@aasthabharill aasthabharill marked this pull request as draft December 1, 2025 10:34
@gemini-code-assist
Copy link

Summary of Changes

Hello @aasthabharill, 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 Spanner change events would incorrectly generate an error when a required SQL primary key column contained a NULL value. The changes refine the logic for handling NULL values in required fields during change event conversion, ensuring that a field present with a NULL value is treated distinctly from a completely missing field. Additionally, comprehensive integration tests have been introduced to validate that records with NULL values in primary key columns are correctly identified and routed to the Dead Letter Queue, maintaining data integrity and expected behavior.

Highlights

  • Refined NULL Handling in Change Event Conversion: The ChangeEventTypeConvertor.java file has been updated to differentiate between a missing required field and a required field explicitly set to NULL. Previously, both scenarios could lead to an error, but now an error is only thrown if the key is entirely absent, not if it exists with a NULL value.
  • New Test Case for Required Null Fields: A new unit test, canConvertRequiredNullFieldToLong, has been added to ChangeEventTypeConvertorTest.java to specifically verify that a required field containing a NULL value is correctly processed without throwing an exception, returning null as expected.
  • Integration Test for Nullable Primary Keys: The SpannerToSourceDbDatatypeIT.java integration test now includes a new table (PkWithNull) with a nullable primary key component. This test confirms that when a Spanner row with a NULL value in a primary key column is processed, it is correctly routed to the Dead Letter Queue (DLQ) with an appropriate error message, aligning with Spanner's primary key constraints.
  • Schema Updates for New Test Table: Corresponding schema definitions for the new SpannerPkWithNull table have been added to mysql-schema.sql, session.json, and spanner-schema.sql to support the new integration test scenario.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.42%. Comparing base (efb574a) to head (dce1609).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3034      +/-   ##
============================================
+ Coverage     50.26%   50.42%   +0.15%     
- Complexity     5024     5395     +371     
============================================
  Files           967      970       +3     
  Lines         59271    59576     +305     
  Branches       6459     6497      +38     
============================================
+ Hits          29794    30040     +246     
- Misses        27376    27410      +34     
- Partials       2101     2126      +25     
Components Coverage Δ
spanner-templates 70.62% <100.00%> (+0.15%) ⬆️
spanner-import-export 68.97% <ø> (-0.05%) ⬇️
spanner-live-forward-migration 80.01% <100.00%> (+0.31%) ⬆️
spanner-live-reverse-replication 77.40% <100.00%> (+0.30%) ⬆️
spanner-bulk-migration 88.23% <100.00%> (-0.10%) ⬇️
Files with missing lines Coverage Δ
...igrations/convertors/ChangeEventTypeConvertor.java 90.00% <100.00%> (-0.10%) ⬇️
...es/changestream/DataChangeRecordTypeConvertor.java 95.74% <100.00%> (-0.09%) ⬇️

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

@pull-request-size pull-request-size bot added size/S and removed size/L labels Dec 8, 2025
VardhanThigle
VardhanThigle previously approved these changes Dec 8, 2025
Copy link
Contributor

@VardhanThigle VardhanThigle left a comment

Choose a reason for hiding this comment

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

LGTM

@VardhanThigle
Copy link
Contributor

LGTM.
Please do not merge untill all the ITs have passed.

@aasthabharill aasthabharill merged commit cdd3164 into GoogleCloudPlatform:main Dec 9, 2025
42 of 44 checks passed
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