Skip to content

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

Open
finnzzf wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
finnzzf:localitygroup
Open

finnzzf wants to merge 6 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.

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.

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

Comment thread v1/src/main/java/com/google/cloud/teleport/spanner/AvroSchemaToDdlConverter.java Outdated
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.

1 participant