Skip to content

feat(spanner): Adds support for Cloud Spanner Locality Groups across INFORMATION_SCHEMA scanning, DDL generation, and Avro export/import - #4461

Merged
darshan-sj merged 9 commits into
GoogleCloudPlatform:mainfrom
finnzzf:localitygroup
Nov 13, 2026
Merged

darshan-sj merged 9 commits into
GoogleCloudPlatform:mainfrom
finnzzf:localitygroup

Conversation

@finnzzf

@finnzzf finnzzf commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds support for Cloud Spanner Locality Groups across INFORMATION_SCHEMA scanning, DDL generation, and Avro export/import for both GoogleSQL and PostgreSQL dialects.

Note on the XXL size PR: the majority of the ~1,650 lines are unit/integration test cases across both dialects (LocalityGroupTest, DdlTest, InformationSchemaScannerTest, Avro converter tests, and InformationSchemaScannerIT), while the core production code changes are self-contained.

Key Changes

  • DDL Model (LocalityGroup, Ddl, Table, Column, Index):
    • Added LocalityGroup value class and builder to represent locality groups in Ddl.
    • Emits CREATE LOCALITY GROUP for user-created locality groups (with or without options) and ALTER LOCALITY GROUP for the default locality group when its options have been customized.
    • Formats locality group definitions and options for both GoogleSQL (OPTIONS (storage="...", ssd_to_hdd_spill_timespan="...")) and PostgreSQL (STORAGE '...' SSD_TO_HDD_SPILL_TIMESPAN '...').
    • Added PostgreSQL LOCALITY GROUP "..." DDL rendering on Table, Column, and Index.
    • Ordered createLocalityGroupStatements() before createTableStatements() and createIndexStatements() in Ddl.statements() so locality groups exist before being referenced by tables, columns, or indexes.
  • Information Schema Scanning (InformationSchemaScanner):
    • Added listLocalityGroups() querying information_schema.locality_group_options.
    • Preserves user-created locality groups with no explicit options (CREATE LOCALITY GROUP <name>) and altered default locality groups (is_inherited = FALSE / 'NO'), while skipping unmodified default locality groups.
    • Enabled PostgreSQL option scanning in listTableOptions(), listColumnOptions(), and listIndexOptions().
    • Updated listColumnOptions() to filter out inherited column options (is_inherited = TRUE / 'YES') so columns inheriting a table's locality group do not emit redundant column-level options.
  • Avro Export & Import (DdlToAvroSchemaConverter, AvroSchemaToDdlConverter, ExportTransform, ImportTransform, export.proto):
    • Serializes LocalityGroup entities as schema-only Avro records ("spannerEntity": "LocalityGroup") and reconstructs them back into Ddl.
    • Added locality_groups to the Export manifest proto and wired locality group DDL creation into ImportTransform prior to table creation.

Testing

  • Unit Tests:
    • LocalityGroupTest & DdlTest: DDL formatting and statement ordering for custom, optionless, and altered default locality groups, plus table, column, and index locality group options in GoogleSQL and PostgreSQL.
    • InformationSchemaScannerTest: Unit tests for listLocalityGroups, listTableOptions, listColumnOptions (verifying inherited column options are skipped and explicit overrides are kept), and listIndexOptions across both dialects.
    • DdlToAvroSchemaConverterTest, AvroSchemaToDdlConverterTest, & ExportTransformTest: Avro schema conversion, manifest generation, and round-trip DDL reconstruction for locality groups (with and without options) and table/column/index assignments.
  • Integration Tests:
    • InformationSchemaScannerIT: End-to-end Spanner ITs (localityGroups and pgLocalityGroups) verifying INFORMATION_SCHEMA scanning $\rightarrow$ Ddl $\rightarrow$ Avro $\rightarrow$ Ddl round-trip in both GoogleSQL and PostgreSQL.

Production Readiness & Manual Testing (per Import/Export PR Review Guide)

  • Backward Compatibility: No new required parameters or breaking changes to spanner-export.json (locality_groups is an optional repeated field in Export proto; existing exports without locality_groups import cleanly).
  • Production INFORMATION_SCHEMA Availability: Verified that INFORMATION_SCHEMA.LOCALITY_GROUP_OPTIONS (including LOCALITY_GROUP_NAME, OPTION_NAME, OPTION_TYPE, OPTION_VALUE, and IS_INHERITED) is already GA and available in production Spanner for both GoogleSQL and PostgreSQL dialects.

Manual Dataflow Template Test Results (Production Spanner)

Staged both Cloud_Spanner_to_GCS_Avro and GCS_Avro_to_Cloud_Spanner from this branch and executed end-to-end Export → Import jobs on production Spanner:

  1. Baseline Database (Without Locality Groups — Backward Compatibility):

    • Export Job ID: 2026-11-02_15_22_59-17383155262102986919 (Succeeded)
    • Import Job ID: 2026-11-02_15_28_14-10411673572410755602 (Succeeded)
    • Result: Verified that databases with no user-defined locality groups and unmodified default locality group export and import with zero CREATE/ALTER LOCALITY GROUP DDL statements emitted and all table data intact.
  2. GoogleSQL Database With Locality Groups:

    • Source DDL Tested: Custom locality groups (hdd, ssd with ssd_to_hdd_spill_timespan, and optionless CREATE LOCALITY GROUP), altered default locality group (ALTER LOCALITY GROUP \default`), plus table-level, column-level override, inherited column-level, and index-level locality_group` options.
    • Export Job ID: 2026-11-02_15_23_01-1297557795690250884 (Succeeded)
    • Import Job ID: 2026-11-02_15_28_18-14807786884967534449 (Succeeded)
    • Result: Verified spanner-export.json and .avro schema artifacts; confirmed gcloud spanner databases ddl describe on destination DB matches source DDL (inherited column options were not redundantly emitted) and all rows were imported.
  3. PostgreSQL Database With Locality Groups:

    • Source DDL Tested: Custom locality groups (STORAGE 'hdd', SSD_TO_HDD_SPILL_TIMESPAN, and optionless), altered default locality group, and LOCALITY GROUP "..." on tables, columns, and indexes.
    • Export Job ID: 2026-11-02_15_23_03-10411673572410756259 (Succeeded)
    • Import Job ID: 2026-11-02_15_28_22-12493404610820383706 (Succeeded)
    • Result: Confirmed destination PG database DDL and table data match source database after Export → Import round-trip.

@finnzzf
finnzzf requested a review from a team as a code owner October 21, 2026 19:42
@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 adds comprehensive support for Cloud Spanner Locality Groups, allowing for the preservation and migration of locality group configurations. The changes span the entire pipeline, including schema scanning, DDL generation, and Avro-based export/import processes, ensuring full compatibility for both GoogleSQL and PostgreSQL dialects.

Highlights

  • Locality Group Model: Introduced a new LocalityGroup value class and builder to represent locality groups within the DDL model.
  • Information Schema Scanning: Updated InformationSchemaScanner to query and preserve locality group options from information_schema.locality_group_options.
  • Avro Export/Import: Enhanced Avro conversion logic to serialize and reconstruct LocalityGroup entities, ensuring they are correctly handled during data migration.
  • DDL Rendering: Updated DDL generation for Tables, Columns, and Indexes to support locality group assignments in both GoogleSQL and PostgreSQL dialects.
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 support for Cloud Spanner Locality Groups across the Spanner Teleport templates, including schema conversion, import/export transforms, and information schema scanning. Feedback on the changes suggests simplifying the extraction of numbered options in AvroSchemaToDdlConverter by reusing the getNumberedPropsWithPrefix helper. Additionally, it is recommended to wrap the ResultSet objects in try-with-resources blocks within InformationSchemaScanner's listTableOptions and listLocalityGroups methods to prevent potential resource leaks.

@shreyakhajanchi shreyakhajanchi added the addition New feature or request label Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.27273% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.57%. Comparing base (0fdf3df) to head (2044c1d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...google/cloud/teleport/spanner/ImportTransform.java 40.00% 15 Missing ⚠️
...google/cloud/teleport/spanner/ExportTransform.java 50.00% 11 Missing ⚠️
...ogle/cloud/teleport/spanner/ddl/LocalityGroup.java 90.19% 3 Missing and 2 partials ⚠️
...ava/com/google/cloud/teleport/spanner/ddl/Ddl.java 88.88% 0 Missing and 3 partials ⚠️
.../com/google/cloud/teleport/spanner/ddl/Column.java 88.88% 0 Missing and 2 partials ⚠️
...a/com/google/cloud/teleport/spanner/ddl/Index.java 93.75% 0 Missing and 2 partials ⚠️
...a/com/google/cloud/teleport/spanner/ddl/Table.java 94.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4461      +/-   ##
============================================
+ Coverage     58.04%   58.57%   +0.53%     
+ Complexity     8275     8041     -234     
============================================
  Files          1152     1153       +1     
  Lines         73713    74680     +967     
  Branches       8801     9039     +238     
============================================
+ Hits          42784    43743     +959     
+ Misses        28092    27995      -97     
- Partials       2837     2942     +105     
Components Coverage Δ
spanner-templates 84.00% <ø> (-0.02%) ⬇️
spanner-import-export 72.73% <82.27%> (+0.40%) ⬆️
spanner-live-forward-migration 87.63% <ø> (-0.03%) ⬇️
spanner-live-reverse-replication 79.83% <ø> (-0.03%) ⬇️
spanner-bulk-migration 88.28% <ø> (-0.02%) ⬇️
gcs-spanner-dv 86.53% <ø> (-0.04%) ⬇️
Files with missing lines Coverage Δ
...oud/teleport/spanner/AvroSchemaToDdlConverter.java 88.67% <100.00%> (+0.22%) ⬆️
...va/com/google/cloud/teleport/spanner/AvroUtil.java 93.75% <ø> (ø)
...oud/teleport/spanner/DdlToAvroSchemaConverter.java 97.68% <100.00%> (+0.11%) ⬆️
...a/com/google/cloud/teleport/spanner/ddl/Table.java 95.03% <94.73%> (+5.69%) ⬆️
.../com/google/cloud/teleport/spanner/ddl/Column.java 90.90% <88.88%> (+4.46%) ⬆️
...a/com/google/cloud/teleport/spanner/ddl/Index.java 82.89% <93.75%> (+3.52%) ⬆️
...ava/com/google/cloud/teleport/spanner/ddl/Ddl.java 78.80% <88.88%> (+1.30%) ⬆️
...ogle/cloud/teleport/spanner/ddl/LocalityGroup.java 90.19% <90.19%> (ø)
...google/cloud/teleport/spanner/ExportTransform.java 53.10% <50.00%> (-0.13%) ⬇️
...google/cloud/teleport/spanner/ImportTransform.java 23.69% <40.00%> (+0.74%) ⬆️

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

@darshan-sj darshan-sj added the improvement Making existing code better label Nov 5, 2026

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

Change looks good overall

@finnzzf

finnzzf commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

The smoke test failure seems to be unrelated this PR and is happening in other runs as well: https://github.com/GoogleCloudPlatform/DataflowTemplates/actions/runs/42613751848/job/129155248992

@finnzzf
finnzzf requested a review from darshan-sj November 9, 2026 22:25

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

Looks good

@darshan-sj
darshan-sj merged commit 4f9638e into GoogleCloudPlatform:main Nov 13, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition New feature or request improvement Making existing code better size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants