Repository navigation
[SpannerIO] Add timestamp bound and host options to the Spanner read SchemaTransform - #41953
Open
jonathansudhakar1 wants to merge 1 commit into
Open
jonathansudhakar1 wants to merge 1 commit into
jonathansudhakar1 wants to merge 1 commit into
Conversation
Contributor
|
Assigning reviewers: R: @tvalentyn added as fallback since no labels match configuration 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). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #41953 +/- ##
============================================
- Coverage 59.79% 59.68% -0.11%
Complexity 5238 5238
============================================
Files 1472 1472
Lines 188774 188774
Branches 3928 3928
============================================
- Hits 112877 112675 -202
- Misses 72466 72668 +202
Partials 3431 3431
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…SchemaTransform The Spanner read SchemaTransform (spanner_read:v1, YAML ReadFromSpanner) is the recommended way to read from Spanner in Python and YAML, but it only does strong reads, and it can't use another Spanner host or an emulator. The legacy Python ReadFromSpanner, which goes through SpannerTransformRegistrar, supports all of these. Add the legacy wrapper's options, with the same names and meaning: timestamp_bound_mode, with read_timestamp or with staleness and time_unit, plus host and emulator_host. Mode and time unit names are case-insensitive. SpannerIO reads in a batch read-only transaction, and the Spanner client rejects MAX_STALENESS and MIN_READ_TIMESTAMP for those, so validate() rejects these two modes with a clear message instead of letting the read fail on the workers. validate() also rejects options that don't belong to the chosen mode. Also map the new fields in standard_io.yaml for YAML ReadFromSpanner and show a stale read in the transform's description.
jonathansudhakar1
force-pushed
the
spanner-read-options-22480
branch
from
December 5, 2026 14:04
12f5815 to
c8b964d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #22480.
A follow-up to #41769, as discussed there: @stankiewicz suggested exposing the same knobs on the SchemaTransforms as the legacy Python wrappers have, so the legacy wrappers could later be removed or delegate to the SchemaTransforms. This PR does the read side. #41769 has since been merged, and the write-side knobs will come in a separate PR.
The Spanner read SchemaTransform (
spanner_read:v1, YAMLReadFromSpanner) only does strong reads and can't point at another Spanner host or an emulator. The legacy PythonReadFromSpanner(SpannerTransformRegistrar.ReadBuilder) supports all of these, so users moving to the SchemaTransform lose point-in-time and stale reads.Changes
SpannerReadSchemaTransformProvider, with the legacy wrapper's names and meaning:timestamp_bound_mode:STRONG(the default, unchanged),READ_TIMESTAMP(withread_timestamp, RFC 3339) orEXACT_STALENESS(withstalenessandtime_unit). Mode and unit names are case-insensitive.hostandemulator_host, passed toSpannerIO.Read#withHost/#withEmulatorHost.validate(), which the transform already calls when it's built): each mode needs its own fields and rejects the others,stalenesscan't be negative, andread_timestamp/time_unitmust parse.MAX_STALENESSandMIN_READ_TIMESTAMPare rejected with an explanation: SpannerIO reads in a batch read-only transaction (CreateTransactionFn→BatchClient#batchReadOnlyTransaction), and the Spanner client'sMultiUseReadOnlyTransactiononly allows those two modes for single-use reads.buildRead()(package-private) builds theSpannerIO.Read, and a package-privatesetServiceFactorylets tests useFakeServiceFactory, as [SpannerIO] Add write results and write options to the Spanner write SchemaTransform #41769 does for the write side.description()gets a short stale-read example.Also:
standard_io.yamlmaps the six new fields for YAMLReadFromSpanner.With none of the new fields set, the transform builds the same
SpannerIO.Readas before.Testing
All with JDK 21. Checker Framework was on, as in CI.
./gradlew :sdks:java:io:google-cloud-platform:spotlessCheck :sdks:java:io:google-cloud-platform:compileJava :sdks:java:io:google-cloud-platform:compileTestJava :sdks:java:io:google-cloud-platform:checkstyleMain :sdks:java:io:google-cloud-platform:checkstyleTest :sdks:java:io:google-cloud-platform:javadoc: passed../gradlew :sdks:java:io:google-cloud-platform:test --rerun --tests '…SpannerReadSchemaTransformProviderTest' --tests '…SpannerSchemaTransformProviderTest' --tests '…SpannerIOReadTest' --tests '…SpannerTransformRegistrarTest': 8/8, 7/7, 33/33 and 22/22 passed.SpannerReadSchemaTransformProviderTestchecks the bound, host and emulator host on the builtSpannerIO.Read, the unchanged defaults, and every validation error. One test runs the transform in a pipeline againstFakeServiceFactory, where the fake batch client only returns a transaction for the expected read timestamp, so the read fails if the bound doesn't reach the transaction.SpannerSchemaTransformProviderTest. That file only gets the six new names intestReadFindTransformAndMakeItWork.spotlessCheck, compile and checkstyle tasks (passed) and the same four test classes with--rerun: 8/8, 13/13, 33/33 and 22/22 passed.withTimestampBoundremoved and the emulator host replaced, 4 of the 8 new tests failed, including the pipeline test.:sdks:java:io:google-cloud-platform:expansion-service:shadowJar(no Spanner connection):ReadFromSpannerconfig schema lists the six fields (strings, and anINT64staleness, all nullable).timestamp_bound_mode: MAX_STALENESSfails at expansion with the new message.EXACT_STALENESS,staleness: 15,time_unit: SECONDSandemulator_host: 'localhost:59999', expansion reaches schema inference, which fails withThe Spanner emulator host has been set to localhost:59999, but no running emulator could be found at that address.So the options pass validation and the emulator host reachesSpannerIO.pytest apache_beam/yaml/yaml_provider_unit_test.py apache_beam/yaml/yaml_io_test.py: 49 passed, 23 skipped.pre-commiton the changed files passed.SpannerReadITand the YAML Spanner extended tests, which need GCP or the Docker emulator.Open questions
timestamp_bound_mode/read_timestamp/staleness/time_unitso the legacyReadFromSpannercould pass its arguments straight through later. Happy to rename (for example toread_timestampplusexact_staleness_seconds) if you'd prefer a smaller YAML surface.MAX_STALENESSandMIN_READ_TIMESTAMP, and its docstring example usesMAX_STALENESS. From reading the code (not run against Spanner), those would fail on the workers when the transaction is created. I left the legacy wrapper alone, since it's out of scope here, but can send a small docs fix if that's useful.CHANGES.md: this and [SpannerIO] Add write results and write options to the Spanner write SchemaTransform #41769 both add an I/Os bullet, so whichever merges second needs a rebase.Resolved: rebased after [SpannerIO] Add write results and write options to the Spanner write SchemaTransform #41769 was merged, keeping both bullets.