Skip to content

Fetch variable metadata from Spanner#1797

Open
n-h-diaz wants to merge 4 commits intodatacommonsorg:masterfrom
n-h-diaz:vm
Open

Fetch variable metadata from Spanner#1797
n-h-diaz wants to merge 4 commits intodatacommonsorg:masterfrom
n-h-diaz:vm

Conversation

@n-h-diaz
Copy link
Contributor

@n-h-diaz n-h-diaz commented Mar 9, 2026

This PR adds support for fetching variable metadata by variable from Spanner

It reads from the new VariableMetadata table which has aggregated data per variable x facet computed via BQ federation. (Currently it's only loaded with data from CensusACS5YearSurvey import)

Note: this table is based on existing requirements to support (v1) BulkVariableInfo. If additional metadata is needed, we can modify the BQ query + Spanner schema

@gemini-code-assist
Copy link
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 introduces the capability to fetch variable metadata from Spanner, utilizing a new VariableMetadata table. This table aggregates data per variable and facet, initially populated from the CensusACS5YearSurvey import, and is designed to support existing requirements for bulk variable information.

Highlights

  • Spanner Client Interface Extension: The SpannerClient interface has been extended with a new method, GetVariableMetadata, enabling the retrieval of variable-specific metadata from the Spanner database.
  • Variable Metadata Model: A new Go struct, VariableMetadata, was introduced to accurately model the schema of the VariableMetadata table in Spanner, facilitating structured data handling.
  • Query Implementation: The GetVariableMetadata method has been implemented within the spannerDatabaseClient, including the necessary logic to query the Spanner database and map the returned data to the VariableMetadata struct.
  • SQL Query Builder: A new function, GetVariableMetadataQuery, was added to programmatically construct the appropriate SQL statement for fetching variable metadata based on a list of provided variable IDs.
  • Golden File Testing: Comprehensive golden file tests were introduced for both the SQL query generation and the data retrieval process, ensuring the correctness and consistency of the new functionality.
Changelog
  • internal/server/spanner/client.go
    • Added GetVariableMetadata method to the SpannerClient interface.
  • internal/server/spanner/golden/query/get_variable_metadata.json
    • Added a golden JSON file containing example variable metadata for testing.
  • internal/server/spanner/golden/query_builder/get_variable_metadata.sql
    • Added a golden SQL file for the GetVariableMetadata query builder.
  • internal/server/spanner/golden/query_builder_test.go
    • Added a new test function TestGetVariableMetadataQuery to validate the SQL query builder.
  • internal/server/spanner/golden/query_cases_test.go
    • Added variableMetadataTestCases to define test inputs for variable metadata queries.
  • internal/server/spanner/golden/query_test.go
    • Added a new test function TestGetVariableMetadata to validate the Spanner client's metadata retrieval.
  • internal/server/spanner/model.go
    • Defined the VariableMetadata struct with fields corresponding to the Spanner table.
  • internal/server/spanner/query.go
    • Implemented the GetVariableMetadata method to query Spanner and process results.
  • internal/server/spanner/query_builder.go
    • Added the GetVariableMetadataQuery function to generate Spanner SQL statements.
  • internal/server/spanner/statements.go
    • Declared and initialized the getVariableMetadata SQL template string.
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
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 functionality to fetch variable metadata from Spanner, complete with a new data model, query logic, and comprehensive tests using golden files. The implementation is clean and follows existing patterns. I've provided a couple of suggestions to enhance robustness and consistency: one regarding the use of SELECT * in SQL queries, and another to align error handling with other functions in the module.

@n-h-diaz n-h-diaz marked this pull request as ready for review March 9, 2026 21:32
@n-h-diaz n-h-diaz requested review from keyurva and vish-cs March 9, 2026 21:32
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.

1 participant