apache / apache/beam

BigQueryServicesImpl.insertAll evaluates maxRowBatchSize after a row is added to the batch

Open
#20,618 0 comments 0 reactions 0 assignees View on GitHub
bug gcp io java P3
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
1d 20h
Merged PRs (30d)
196

Description

When using the `BigQueryIO.Write` transformation, a set of pipeline options defined in `BigQueryOptions` become available to the pipeline.

Two of these options being:
* `maxStreamingRowsToBatch` - "The maximum number of rows to batch in a single streaming insert to BigQuery."
* `maxStreamingBatchSize` - "The maximum byte size of a single streaming insert to BigQuery"

Reading the description of the `maxStreamingBatchSize`, I am given the impression that the BigQuery sink will ensure that each batch is either on, or under, the max byte size configured.

But after [reviewing the code of the internal sink transformation](https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryServicesImpl.java#L826), I can see that the batching code will first add a row to the batch and then compares the new batch size against the maximum configured.

The description of the option, `maxStreamingBatchSize`, gives the end user an impression that this will protect them from batches that will exceed the size limit of the BigQuery streaming inserts API.

When in reality it can lead to a situation where a batch is produced that massively exceeds the limit and the transformation will get stuck into a loop of constantly retrying the request.

Imported from Jira [BEAM-11330](https://issues.apache.org/jira/browse/BEAM-11330). Original Jira may contain additional context.
Reported by: liamhaworth01.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.