Skip to content

feat(spanner/spansql): support struct literal#13766

Merged
rahul2393 merged 3 commits intogoogleapis:mainfrom
anicoll:feat/support-struct-literal
Feb 10, 2026
Merged

feat(spanner/spansql): support struct literal#13766
rahul2393 merged 3 commits intogoogleapis:mainfrom
anicoll:feat/support-struct-literal

Conversation

@anicoll
Copy link
Copy Markdown
Contributor

@anicoll anicoll commented Feb 4, 2026

SpanSQL does not currently support STRUCT type.

This PR aims to add support for this with adequate tests for subqueries as well.

Closes #13765

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @anicoll, 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 significantly expands the capabilities of the SpanSQL parser by integrating full support for STRUCT types and ARRAY subqueries. The changes enable the parser to correctly interpret and generate SQL for complex data structures, including nested structs, typed structs, and array subqueries, which were previously unsupported. This enhancement ensures that SpanSQL can handle a broader range of advanced SQL queries, improving its utility and alignment with modern database features.

Highlights

  • STRUCT Literal Support: Introduced comprehensive support for STRUCT literals, allowing both untyped STRUCT(value1, value2) and typed STRUCT<type1, type2>(value1, value2) forms to be parsed and generated.
  • SELECT AS STRUCT Clause: Added parsing and SQL generation for the SELECT AS STRUCT clause, including its combination with DISTINCT (e.g., SELECT DISTINCT AS STRUCT ...).
  • ARRAY Subquery Enhancement: Enhanced ARRAY parsing to support ARRAY(SELECT ...) subqueries and typed array literals (e.g., ARRAY<INT64>[1, 2, 3]), providing more flexibility for array construction.
  • New AST Nodes: Defined new Abstract Syntax Tree (AST) nodes, StructLiteral and ArraySubquery, to accurately represent these new SQL constructs within the spansql package.
Changelog
  • spanner/spansql/parser.go
    • Modified parseSelect() to correctly parse AS STRUCT clauses, including when preceded by DISTINCT.
    • Introduced parseStructLit() to handle the parsing of STRUCT literals, both with and without explicit type declarations.
    • Refactored array parsing logic into parseArrayOrArraySubquery() to support ARRAY(SELECT ...) subqueries and typed array literals, replacing previous parseArrayLit() calls in relevant contexts.
  • spanner/spansql/sql.go
    • Updated Select.addSQL() to include the AS STRUCT keyword in the generated SQL when applicable.
    • Added SQL() and addSQL() methods for the new ArraySubquery type to facilitate SQL generation.
    • Implemented SQL() and addSQL() methods for the new StructLiteral type, supporting both untyped and typed struct literal SQL output.
  • spanner/spansql/sql_test.go
    • Added a comprehensive suite of new test cases for STRUCT literals, covering various scenarios such as basic, typed, null values, nested structs, and arrays of structs.
    • Included new test cases for SELECT AS STRUCT and ARRAY(SELECT AS STRUCT ...) subqueries to validate parsing and SQL generation.
  • spanner/spansql/types.go
    • Added a new boolean field AsStruct to the Select struct to indicate the presence of the AS STRUCT clause.
    • Defined the ArraySubquery struct to represent ARRAY(SELECT ...) constructs in the AST.
    • Introduced the StructLiteral struct, including Fields and an optional FieldTypes slice, to represent STRUCT literals in the AST.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 STRUCT literals and SELECT AS STRUCT in SpanSQL, which is a great addition. The implementation includes parsing logic, SQL generation, and extensive test cases covering various scenarios like nested structs, arrays of structs, and typed structs.

My review focuses on a potential issue in the parsing logic for SELECT modifiers. I've left one comment with a suggestion to improve the robustness of parsing combinations of DISTINCT and AS STRUCT. The rest of the changes look solid.

@anicoll anicoll marked this pull request as ready for review February 4, 2026 04:59
@anicoll anicoll requested a review from a team February 4, 2026 04:59
@anicoll anicoll requested review from a team as code owners February 4, 2026 04:59
@anicoll
Copy link
Copy Markdown
Contributor Author

anicoll commented Feb 5, 2026

@rahul2393 🥺

@rahul2393 rahul2393 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 5, 2026
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 5, 2026
@rahul2393 rahul2393 changed the title Feat: support struct literal feat(spanner/spansql): support struct literal Feb 5, 2026
@anicoll
Copy link
Copy Markdown
Contributor Author

anicoll commented Feb 10, 2026

Is there any movement on this getting an approval?

@rahul2393 rahul2393 merged commit b4a6f4c into googleapis:main Feb 10, 2026
10 of 11 checks passed
@anicoll anicoll deleted the feat/support-struct-literal branch February 10, 2026 08:32
rahul2393 added a commit that referenced this pull request Feb 11, 2026
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v1.0.0
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian-go@sha256:19bb93e8f1f916c61b597db2bad65dc432f79baaabb210499d7d0e4ad1dffe29
<details><summary>spanner: 1.88.0</summary>

##
[1.88.0](spanner/v1.87.0...spanner/v1.88.0)
(2026-02-11)

### Features

* Adding Send and Ack Mutation Support for Cloud Spanner Queue (#13616)
([1cf600d](1cf600d6))

* include cache updates into the ResultSet response (PiperOrigin-RevId:
865546011)
([6f31019](6f310199))

* add a ClientContext field to Spanner requests (PiperOrigin-RevId:
853323071)
([80379ed](80379edb))

* add Secure Parameters to the ClientContext (PiperOrigin-RevId:
853323071)
([80379ed](80379edb))

* PGNumeric implements Scanner and Valuer (#13722)
([85bc9db](85bc9dbf))

* support struct literal (#13766)
([b4a6f4c](b4a6f4c5))

* Exposing total CPU related fields in AutoscalingConfig
(PiperOrigin-RevId: 845819318)
([db65e79](db65e792))

* add ClientContext support (#13775)
([e85d706](e85d7061))

### Bug Fixes

* disable config logging by default (#13478)
([ad19592](ad19592e))

* decode PG JSONB array to PGJsonB struct (#13602)
([d72d0f4](d72d0f45))

### Performance Improvements

* only create sessions if multiplexed sessions are disabled (#13477)
([e44e58f](e44e58f6))

### Documentation

* A comment for field `param_types` in message
`.google.spanner.v1.PartitionQueryRequest` is changed
(PiperOrigin-RevId: 865546011)
([6f31019](6f310199))

* A comment for field `transaction_tag` in message
`.google.spanner.v1.RequestOptions` is changed (PiperOrigin-RevId:
865546011)
([6f31019](6f310199))

* A comment for field `commit_timestamp` in message
`.google.spanner.v1.BatchWriteResponse` is changed (PiperOrigin-RevId:
865546011)
([6f31019](6f310199))

* A comment for field `params` in message
`.google.spanner.v1.PartitionQueryRequest` is changed
(PiperOrigin-RevId: 865546011)
([6f31019](6f310199))

* Update client side metrics and permission issues in README (#13491)
([ab56892](ab56892e))

* Update high_priority_cpu_utilization_percent in AutoscalingConfig to
be Optional and clarify its behavior when not specified
(PiperOrigin-RevId: 845819318)
([db65e79](db65e792))

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spansql: support struct

4 participants