Skip to content

Conversation

@aseering
Copy link

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the samples format.

@aseering aseering requested review from a team as code owners January 28, 2026 05:27
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/java-spanner API. labels Jan 28, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aseering, 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 enhances the Java Spanner client library by adding robust support for ClientContext. This feature enables users to embed secure, context-specific metadata with their database requests, facilitating advanced use cases like secure views that require dynamic, user-specific parameters. The implementation provides flexible configuration options and ensures seamless integration and correct behavior across the client's various operational layers.

Highlights

  • ClientContext Support: Introduced a new ClientContext option within RequestOptions to allow passing side-channel or configuration information to the backend, such as user IDs for parameterized secure views.
  • Flexible Configuration: The ClientContext can now be configured at multiple levels: as a default in SpannerOptions, on a Connection object, or as an Options parameter for individual queries and updates, with merging logic to handle precedence.
  • API Integration: Integrated ClientContext propagation throughout the client library, affecting request building in AbstractReadContext, SessionImpl, TransactionRunnerImpl, and various UnitOfWork implementations in the connection layer.
  • Public API Extension: Added setClientContext and getClientContext methods to the Connection interface, providing a public API for managing the client context on a per-connection basis.
  • Comprehensive Testing: New and updated unit tests, including a dedicated ClientContextMockServerTest, ensure correct propagation, merging, and persistence of ClientContext across different operations and configuration scenarios.
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 support for ClientContext in the Spanner Java client, enabling the use of secure parameters. The changes add a clientContext option at both the global SpannerOptions level and the per-request Options level, with logic to merge them. My review identifies a potential issue where the default ClientContext is not being applied to CommitRequests, which is inconsistent with other request types. I've also included a couple of suggestions to refactor duplicated and verbose code for better maintainability.

I am having trouble creating individual review comments. Click here to see my feedback.

google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java (467-470)

high

The RequestOptions for the CommitRequest are built from per-transaction options but do not appear to merge with the default ClientContext that can be configured on SpannerOptions. This is inconsistent with how BeginTransactionRequest and ExecuteSqlRequest are handled in this PR. This could lead to the ClientContext being unexpectedly missing from commit requests when a default is expected to be applied.

Consider applying the same merge logic used in SessionImpl.beginTransactionAsync here to ensure consistent behavior.

          RequestOptions requestOptions = options.toRequestOptionsProto(true);
          RequestOptions.ClientContext defaultClientContext =
              session.getSpanner().getOptions().getClientContext();
          if (defaultClientContext != null) {
            RequestOptions.ClientContext.Builder clientContextBuilder =
                defaultClientContext.toBuilder();
            if (requestOptions.hasClientContext()) {
              clientContextBuilder.mergeFrom(requestOptions.getClientContext());
            }
            requestOptions =
                requestOptions.toBuilder().setClientContext(clientContextBuilder.build()).build();
          }
          if (!requestOptions.equals(RequestOptions.getDefaultInstance())) {
            requestBuilder.setRequestOptions(requestOptions);
          }

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java (488-497)

medium

The logic for merging the default ClientContext from SpannerOptions with the request-specific ClientContext is also present in AbstractReadContext.buildRequestOptions. To improve maintainability and reduce code duplication, consider extracting this logic into a shared helper method.

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java (2091-2098)

medium

The logic for appending the clientContext as an UpdateOption is a bit verbose. For consistency with mergeQueryRequestOptions, which uses an appendQueryOption helper, consider creating and using a similar helper method like appendUpdateOption.

    if (clientContext != null) {
      options = appendUpdateOption(options, Options.clientContext(clientContext));
    }

@aseering aseering changed the title Secure Parameters support for the Java Client feat: Secure Parameters support for the Java Client Jan 29, 2026
This change adds support for ClientContext in Options and ensures it is
propagated to ExecuteSql, Read, Commit, and BeginTransaction requests.
It aligns with go/spanner-client-scoped-session-state design.

- Added RequestOptions.ClientContext to Options.
- Refactored request option building to Options.toRequestOptionsProto.
- Updated AbstractReadContext, TransactionRunnerImpl, and SessionImpl to use the shared logic.
- Added tests.
@aseering aseering force-pushed the secure-parameters branch 2 times, most recently from 4652157 to 160e1db Compare January 30, 2026 14:04
This change adds support for setting and propagating ClientContext in the
Spanner Connection API. ClientContext allows propagating client-scoped
session state (e.g., secure parameters) to Spanner RPCs.

- Added setClientContext/getClientContext to Connection interface and implementation.
- Implemented state propagation from Connection to UnitOfWork and its implementations (ReadWriteTransaction, SingleUseTransaction).
- Fixed accidental import removal in OptionsTest.java.
- Fixed TransactionRunnerImplTest to correctly verify ClientContext propagation.
- Added ClientContextMockServerTest for end-to-end verification.
@aseering aseering requested a review from a team as a code owner January 30, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant