gemini-code-assist[bot] commented on code in PR #38777:
URL: https://github.com/apache/beam/pull/38777#discussion_r3343054979
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/providers/BigQueryStorageWriteApiSchemaTransformProvider.java:
##########
@@ -179,11 +179,15 @@ public PCollectionRowTuple expand(PCollectionRowTuple
input) {
PCollection<Row> inputRows = input.getSinglePCollection();
BigQueryIO.Write<Row> write =
createStorageWriteApiTransform(inputRows.getSchema());
+ int numStreams = configuration.getNumStreams() == null ? 0 :
configuration.getNumStreams();
+
+ if (numStreams > 0) {
+ write = write.withNumStorageWriteApiStreams(numStreams);
+ }
Review Comment:

There are two issues with the current handling of `numStreams`:
1. **Validation**: If `configuration.getNumStreams()` is negative, it is
silently ignored instead of throwing an error. We should validate that it is
non-negative.
2. **Explicit Override**: If `configuration.getNumStreams()` is explicitly
set to `0`, the current code does not call
`write.withNumStorageWriteApiStreams(0)` because of the `numStreams > 0` check.
This means if a user has a pipeline option `--numStorageWriteApiStreams` set to
a non-zero value, the explicit `0` configuration in the SchemaTransform will be
ignored, and the pipeline option's value will be used instead. To allow
explicitly overriding pipeline options with `0` (which is a valid configuration
to keep pipeline parallelism as is), we should call
`write.withNumStorageWriteApiStreams(numStreams)` whenever
`configuration.getNumStreams() != null`.
```java
Integer configuredStreams = configuration.getNumStreams();
if (configuredStreams != null) {
if (configuredStreams < 0) {
throw new IllegalArgumentException("numStreams must be
non-negative.");
}
write = write.withNumStorageWriteApiStreams(configuredStreams);
}
int numStreams = configuredStreams == null ? 0 : configuredStreams;
```
--
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]