Fix out of range
Fixes https://github.com/apache/beam/issues/30177
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead. - [ ] Update
CHANGES.mdwith noteworthy changes. - [ ] If this contribution is large, please file an Apache Individual Contributor License Agreement.
See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers
Assigning reviewers:
R: @Abacn for label java.
Note: If you would like to opt out of this review, comment assign to next reviewer.
Available commands:
stop reviewer notifications- opt out of the automated review toolingremind me after tests pass- tag the comment author after tests passwaiting on author- shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
Reminder, please take a look at this pr: @Abacn
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:
R: @ahmedabu98 for label java.
Available commands:
stop reviewer notifications- opt out of the automated review toolingremind me after tests pass- tag the comment author after tests passwaiting on author- shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
Reminder, please take a look at this pr: @ahmedabu98
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:
R: @chamikaramj for label java.
Available commands:
stop reviewer notifications- opt out of the automated review toolingremind me after tests pass- tag the comment author after tests passwaiting on author- shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
Reminder, please take a look at this pr: @chamikaramj
https://github.com/apache/beam/pull/35051#discussion_r2112122889 @yirutang I assume there is no potential data loss here.
LGTM, but need to clean up the unused exception.
Also is it possible to add a test for this?
I do not have a good way to test this. I think the current PR wont do any harm at least since for streaming, the bug makes the pipeline stuck.
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:
R: @robertwb for label java.
Available commands:
stop reviewer notifications- opt out of the automated review toolingremind me after tests pass- tag the comment author after tests passwaiting on author- shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
Reminder, please take a look at this pr: @robertwb
Maybe it's too much to add an integration test here. But we can try running it locally with modified code that forces an end of stream error. Can you try adding an increment to the offset in the line below and running a pipeline locally to see if your new code path gets triggered? e.g. return datasetService.flush(streamId, offset + 50);
https://github.com/apache/beam/blob/52e42d72df16dace19674508d448bf6f0f92a4f6/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiFlushAndFinalizeDoFn.java#L157
Maybe it's too much to add an integration test here. But we can try running it locally with modified code that forces an end of stream error. Can you try adding an increment to the offset in the line below and running a pipeline locally to see if your new code path gets triggered? e.g.
return datasetService.flush(streamId, offset + 50);https://github.com/apache/beam/blob/52e42d72df16dace19674508d448bf6f0f92a4f6/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiFlushAndFinalizeDoFn.java#L157
Good idea. Manually changed the offset and ran this:
./gradlew :sdks:java:io:google-cloud-platform:integrationTest --tests "org.apache.beam.sdk.io.gcp.bigquery.BigQueryIOStorageWriteIT.testBigQueryStorageWrite3MProto" -PgcpProject=apache-beam-testing -PgcpTempRoot=gs://temp-storage-for-end-to-end-tests -i > test_output.log
testBigQueryStorageWrite3MProto failed as expected and also I added the log to test isOffsetBeyondEndOfStreamError is called with
private boolean isOffsetBeyondEndOfStreamError(Throwable t) {
LOG.info("Checking for offset beyond end of stream error.");
if (t == null) {
return false;
}
Jul 19, 2025 2:51:21 PM org.apache.beam.sdk.io.gcp.bigquery.StorageApiFlushAndFinalizeDoFn isOffsetBeyondEndOfStreamError
INFO: Checking for offset beyond end of stream error.
Jul 19, 2025 2:51:21 PM org.apache.beam.sdk.io.gcp.bigquery.StorageApiFlushAndFinalizeDoFn lambda$process$1
WARNING: Flush of stream projects/apache-beam-testing/datasets/big_query_storage_write_it_1752951070961_24/tables/storage_write_1752951073468/streams/Cic2YmJiYjNlNS0wMDAwLTIwMmQtYWI0NS1kNGY1NDdmZDExZDQ6czQ to offset 1499 failed because the offset is beyond the end of the stream. This typically means the stream was finalized or truncated by BQ. The operation will not be retried on this stream. Error: com.google.api.gax.rpc.OutOfRangeException: io.grpc.StatusRuntimeException: OUT_OF_RANGE: Offset 1549 is beyond the end of the stream Entity: projects/apache-beam-testing/datasets/big_query_storage_write_it_1752951070961_24/tables/storage_write_1752951073468/streams/Cic2YmJiYjNlNS0wMDAwLTIwMmQtYWI0NS1kNGY1NDdmZDExZDQ6czQ
LOG.warn(
"Flush of stream {} to offset {} failed because the offset is beyond the end of the stream. "`
`` `
is also shown correctly.