Skip to content

feat: Bring API parity to v3/observation for existence checks in Spanner#1823

Merged
SandeepTuniki merged 6 commits intomasterfrom
optimize-spanner-observation
Mar 26, 2026
Merged

feat: Bring API parity to v3/observation for existence checks in Spanner#1823
SandeepTuniki merged 6 commits intomasterfrom
optimize-spanner-observation

Conversation

@SandeepTuniki
Copy link
Copy Markdown
Contributor

@SandeepTuniki SandeepTuniki commented Mar 24, 2026

This PR implements API parity for existence checks within the Spanner backend (b/49252083). This effectively helps us to remove the /v2/variable/filter, used to filter down the variables that are associated with specific entities.

Following feedback on the initial approach in #1819, this implementation optimizes the existing /v3/observation (and /v2/observation) api rather than introducing a new v3/variable/filter endpoint.

@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 enhances the Spanner backend's observation API by introducing an optimized mechanism for checking the existence of observations for given variables and entities. Instead of creating a new endpoint, this change integrates the existence check functionality directly into the existing /v3/observation and /v2/observation APIs, improving efficiency and maintaining API consistency. This allows clients to quickly determine if specific data points exist without retrieving full observation details, addressing a previous feedback item.

Highlights

  • API Parity for Existence Checks: Implemented API parity for existence checks within the Spanner backend for /v3/observation and /v2/observation APIs, optimizing existing endpoints rather than introducing new ones.
  • New Spanner Client Method: Added a new CheckVariableExistence method to the SpannerClient interface and its concrete implementation to query for the existence of observations.
  • Observation Handler Enhancement: Modified the SpannerDataSource.Observation method to conditionally perform existence checks when specific select fields (date, value, facet) are not requested, returning a simplified response.
  • New Spanner Query: Introduced a new Spanner query, FilterStatVarsByEntityQuery, and its corresponding SQL statement to efficiently filter statistical variables by entity.
  • Comprehensive Test Coverage: Added new golden files and extensive test cases for TestSpannerObservation to validate the new existence check functionality across various scenarios, including single entity, multi-entity, and error conditions.
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.

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 an optimization for observation existence checks in the Spanner backend by enhancing the existing /v3/observation API instead of adding a new endpoint. The changes are well-structured and include new queries, interface methods, and tests. My review includes a couple of suggestions: one to improve the robustness and performance of observation processing in datasource.go, and another to enhance the accuracy of the mock client in datasource_test.go to better reflect real-world filtering behavior, which will improve test quality.

@SandeepTuniki
Copy link
Copy Markdown
Contributor Author

/gemini review

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 a new feature to efficiently check for the existence of observations for specified statistical variables and entities within the Spanner data source. This includes adding a CheckVariableExistence method to the SpannerClient interface and its implementation, integrating this check into the Observation function under specific conditions (when only variable and entity existence is requested), and adding new validation to ensure entities are specified. Corresponding SQL query builders, Spanner statements, and comprehensive golden tests have been added to support this functionality. A review comment suggests improving error handling in internal/server/spanner/datasource.go by using %w for error wrapping to allow for better error inspection up the call stack.

@SandeepTuniki SandeepTuniki marked this pull request as ready for review March 24, 2026 16:51
Copy link
Copy Markdown
Contributor

@n-h-diaz n-h-diaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick update!

Generally looks good, just had a small comment on supporting stat vars per place

@SandeepTuniki
Copy link
Copy Markdown
Contributor Author

/gemini review

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 an optimized mechanism to check for the existence of observations based on variables and entities. It adds a new CheckVariableExistence method to the Spanner client interface and its implementation, which is utilized in the Observation handler for specific existence-only requests. A new FilterStatVarsByEntityQuery function was added to construct the necessary SQL queries, accompanied by new golden files and comprehensive tests. The review suggests adding a defensive error check to FilterStatVarsByEntityQuery to prevent potential full table scans if called with empty variable and entity lists.

@SandeepTuniki
Copy link
Copy Markdown
Contributor Author

SandeepTuniki commented Mar 25, 2026

Hi @n-h-diaz, I addressed your feedback. Could you take a look at this PR again?

Also, the CI is failing on Codacy checks, related to SQL queries. I wasn't sure if I should apply the suggested changes. We're not really following the suggested patterns in the rest of the codebase. What do you suggest regarding this?

Copy link
Copy Markdown
Contributor

@n-h-diaz n-h-diaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

(Codacy often complains about sql/gql - I think safe to ignore)

Let's see if this is efficient enough for existence requests (both v3 observation and variable filter) and can discuss alternatives if latency is too high

@SandeepTuniki SandeepTuniki added this pull request to the merge queue Mar 26, 2026
Merged via the queue into master with commit 2f2d6a6 Mar 26, 2026
8 of 9 checks passed
@SandeepTuniki SandeepTuniki deleted the optimize-spanner-observation branch March 26, 2026 03:13
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.

2 participants