Skip to content

Support search indexes partitioned by repeated values in Spanner export - #4671

Open
pinthekin wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
pinthekin:search-index-unnest
Open

pinthekin wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
pinthekin:search-index-unnest

Conversation

@pinthekin

Copy link
Copy Markdown

Cloud Spanner search indexes can be partitioned by the elements of an array column using an UNNEST clause, for example:

CREATE SEARCH INDEX AlbumsByTracks ON Albums(AlbumTitle_Tokens)
UNNEST(Tracks) AS Track PARTITION BY Track

The export scanner did not read the UNNEST clause, so it emitted "... PARTITION BY Track" without it, and importing that DDL failed because Track is not a column.

InformationSchemaScanner now reads INFORMATION_SCHEMA.INDEXES.SEARCH_UNNEST (when the column exists) and Index prints the UNNEST clauses after the indexed columns, before STORING (GoogleSQL) or INCLUDE (PostgreSQL), matching GetDatabaseDdl. The column is probed first so export keeps working against databases and environments (e.g. the emulator) that don't expose it.

Cloud Spanner search indexes can be partitioned by the elements of an array
column using an UNNEST clause, for example:

  CREATE SEARCH INDEX AlbumsByTracks ON Albums(AlbumTitle_Tokens)
  UNNEST(Tracks) AS Track PARTITION BY Track

The export scanner did not read the UNNEST clause, so it emitted
"... PARTITION BY Track" without it, and importing that DDL failed because
Track is not a column.

InformationSchemaScanner now reads INFORMATION_SCHEMA.INDEXES.SEARCH_UNNEST
(when the column exists) and Index prints the UNNEST clauses after the indexed
columns, before STORING (GoogleSQL) or INCLUDE (PostgreSQL), matching
GetDatabaseDdl. The column is probed first so export keeps working against
databases and environments (e.g. the emulator) that don't expose it.
@pinthekin
pinthekin force-pushed the search-index-unnest branch from 5b786d7 to 527fc28 Compare December 1, 2026 21:56
@pinthekin
pinthekin marked this pull request as ready for review December 1, 2026 21:57
@pinthekin
pinthekin requested a review from a team as a code owner December 1, 2026 21:57
@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 an issue where Cloud Spanner search indexes partitioned by repeated values were failing to export/import correctly due to missing UNNEST clause information. The changes introduce logic to detect and extract this information from the database schema and ensure it is correctly represented in the generated DDL, while maintaining compatibility with environments that do not yet support this schema column.

Highlights

  • Support for UNNEST clauses in search indexes: Updated the Spanner export scanner to correctly read and include UNNEST clauses for search indexes, preventing DDL import failures.
  • Schema compatibility: Implemented a check for the existence of the SEARCH_UNNEST column in INFORMATION_SCHEMA.INDEXES to ensure backward compatibility with older databases and the emulator.
  • DDL generation updates: Modified the Index model to properly format and print UNNEST clauses for 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 UNNEST clauses in Spanner search indexes, allowing partitioning by repeated values. It updates the Index model to include unnest fields, implements dialect-specific pretty-printing, and updates InformationSchemaScanner to dynamically query the SEARCH_UNNEST column if supported. Comprehensive unit and integration tests are also added. A critical issue was identified in Index.java where quoting a dotted column path (e.g., nested fields) as a single identifier is invalid in Spanner; each part of the path should be quoted individually to prevent DDL import failures.

@pinthekin

Copy link
Copy Markdown
Author

cc @n-d-joshi

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