jonathansudhakar1 opened a new pull request, #41769:
URL: https://github.com/apache/beam/pull/41769

   Addresses #22480.
   
   This follows the plan @stankiewicz laid out on the issue: expose 
`SpannerIO.Write#withWriteResults()` and the missing write options on the 
Spanner write SchemaTransform (`spanner_write:v1`, YAML `WriteToSpanner`), 
since Abacn noted it's the recommended Spanner write path for Python. The 
legacy `SpannerTransformRegistrar` transforms in `apache_beam.io.gcp.spanner` 
don't change.
   
   ## Changes
   
   `SpannerWriteSchemaTransformProvider`:
   - **`emit_write_results`** (optional, default `false`) adds a 
**`write_results`** output with one row per batch committed to Spanner:
     - `mutation_count` (`INT64`)
     - `commit_timestamp` and `snapshot_timestamp` (nullable `MicrosInstant`)
   
     `post-write` and the `error_handling` output don't change. With the flag 
off, the transform expands the same way as before.
   - **Works together with `error_handling` (#41764).** The provider turns on 
commit stats on `SpannerIO.Write` itself (it's in the same package) instead of 
going through `withWriteResults()`, which returns only the `WriteResults`. So 
the same `SpannerWriteResult` still has the failed mutations, and #41765's new 
check, which only guards `WriteWithResults`/`WriteGroupedWithResults`, doesn't 
apply.
   - **New optional options:** `priority` (`LOW`/`MEDIUM`/`HIGH`, any case; the 
default stays `MEDIUM`), `max_commit_delay_millis`, `transaction_tag` and 
`exclude_txn_from_change_streams`. Each maps to the matching 
`SpannerIO.Write`/`SpannerConfig` setting and is left alone when unset.
   - **Validation at construction:** the transform now calls 
`configuration.validate()` when it's built, as 
`SpannerReadSchemaTransformProvider` already does. `validate()` also rejects an 
unknown `priority` and a negative `max_commit_delay_millis`.
   - **Docs:** the field descriptions and `description()` explain the new 
output, and `outputCollectionNames()` lists `write_results`.
   
   Also:
   - `standard_io.yaml` maps the five new fields for YAML `WriteToSpanner`.
   - CHANGES.md has a bullet under I/Os.
   
   ## 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 --tests 
'…SpannerSchemaTransformProviderTest' --tests '…SpannerIOWriteTest' --tests 
'…SpannerTransformRegistrarTest'`: 12/12, 46/46 and 22/22 passed.
     - The new provider tests use `FakeServiceFactory`. They cover the 
write-results rows (microsecond timestamps round-trip exactly), write results 
and `error_handling` together (one key fails, one commits), the options 
reaching `SpannerIO.Write`, the unchanged defaults (only `post-write`, no 
commit stats), and validation.
     - As a mutation check, I swapped the snapshot and commit timestamps in the 
row conversion and dropped the transaction tag. Three of the new tests failed, 
as expected.
   - YAML end to end, construction only (no Spanner connection):
     - I built 
`:sdks:java:io:google-cloud-platform:expansion-service:shadowJar` and expanded 
a YAML `WriteToSpanner` through it, with all five new fields plus 
`error_handling`.
     - The outputs were `post-write`, `write_results` and the error output, and 
Python sees the timestamps as `Optional[Timestamp]`.
     - `priority: urgent` fails at expansion with `priority must be one of LOW, 
MEDIUM or HIGH, but was 'urgent'.`
   - `pytest apache_beam/yaml/yaml_provider_unit_test.py 
apache_beam/yaml/yaml_io_test.py`: 49 passed, 23 skipped. `pre-commit` on the 
changed files passed.
   - **Not run:** `SpannerWriteIT` and the YAML Spanner extended tests. They 
need GCP or the Docker emulator.
   
   ## Open questions
   
   - **Naming:** I used `max_commit_delay_millis` rather than the 
`max_commit_delay` I wrote on the issue, to match other SchemaTransform configs 
that put the unit in the name (`poll_interval_millis`, 
`triggering_frequency_seconds`). Happy to rename.
   - **Snapshot timestamp precision:** Spanner documents commit timestamps as 
microsecond-granular, so `MicrosInstant` keeps `commit_timestamp` exactly. I 
didn't find the same statement for snapshot timestamps. Any sub-microsecond 
part of `snapshot_timestamp` would be truncated.
   - **Possible follow-ups:** the batching knobs the legacy Python wrappers 
expose (`max_batch_size_bytes`, `max_number_mutations`, `max_number_rows`, 
`commit_deadline`), and a write operation other than insert-or-update. Both 
would be separate PRs, if they're wanted.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] [SpannerIO] Add write res... jonathansudhakar1 (via GitHub) via github

Reply via email to