Add Cloud Spanner Directed Reads support to SpannerIO#39241
Conversation
Summary of ChangesHello, 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 support for Cloud Spanner Directed Reads within the Apache Beam SpannerIO connector. By enabling users to configure replica selection, this change allows for more granular control over read traffic routing in Spanner, improving performance and latency for distributed workloads. The implementation includes robust parsing for both JSON and shorthand string configurations, alongside comprehensive unit testing to ensure proper propagation across SpannerIO read and change stream operations. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for Cloud Spanner directed read options (DirectedReadOptions) across SpannerIO's Read, ReadAll, and ReadChangeStream configurations, including support for parsing these options from both a custom string format and JSON. The review feedback highlights a critical issue where calling withDirectedReadOptions on Read, ReadAll, or ReadChangeStream can result in a NullPointerException if getSpannerConfig() returns null. To resolve this, the reviewer suggests safely initializing the SpannerConfig if it is not already present.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
d4baa46 to
f23b092
Compare
|
Assign set of reviewers |
|
Assigning reviewers: R: @chamikaramj for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
This change allows Beam pipeline developers to configure Cloud Spanner DirectedReadOptions on SpannerConfig, as well as on SpannerIO.read(), readAll(), and readChangeStream(). - Adds getDirectedReadOptions() and withDirectedReadOptions(...) overloads (accepting DirectedReadOptions, ValueProvider<DirectedReadOptions>, and String) to SpannerConfig. - Adds an internal parseDirectedReadOptions helper supporting JSON strings via protobuf JsonFormat, matching the official Cloud Spanner Java client library behavior. - Threads DirectedReadOptions into SpannerOptions.Builder in SpannerAccessor so that all DatabaseClient instances and ChangeStreamDao queries automatically inherit the directed read configuration. - Adds delegation methods to SpannerIO.Read, ReadAll, and ReadChangeStream. - Adds comprehensive unit tests in SpannerAccessorTest and SpannerIOReadChangeStreamTest.
f23b092 to
9328cc2
Compare
|
Assign set of reviewers |
|
Reviewers are already assigned to this PR: @chamikaramj @nielm |
Add Cloud Spanner Directed Reads support to SpannerIO
This PR adds support for Cloud Spanner Directed Reads, allowing Apache Beam pipeline developers to route read and Change Stream polling queries to specific replica types or geographic locations (e.g., restricting queries exclusively to
READ_ONLYreplicas for workload isolation).Key Changes
SpannerConfig:getDirectedReadOptions()getter, builder setter, andwithDirectedReadOptions(...)overloads acceptingDirectedReadOptions,ValueProvider<DirectedReadOptions>, andString.parseDirectedReadOptions(String)helper method supporting standard JSON strings (via protobufJsonFormat).SpannerAccessor:spannerConfig.getDirectedReadOptions()intoSpannerOptions.Builder.setDirectedReadOptions(...)during client initialization so allDatabaseClientinstances and Change Stream queries (ChangeStreamDao) automatically inherit the directed read configuration without requiring per-query overrides.SpannerIO:withDirectedReadOptions(...)delegation methods toSpannerIO.Read,SpannerIO.ReadAll, andSpannerIO.ReadChangeStream.