gemini-code-assist[bot] commented on code in PR #38776:
URL: https://github.com/apache/beam/pull/38776#discussion_r3349960839
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/providers/BigQueryWriteConfiguration.java:
##########
@@ -101,6 +101,12 @@ public void validate() {
Boolean autoSharding = getAutoSharding();
Integer numStreams = getNumStreams();
+ if (numStreams != null) {
+ checkArgument(
+ numStreams >= 0,
+ invalidConfigMessage + "numStreams must be non-negative, but was:
%s",
+ numStreams);
+ }
Review Comment:

If `numStreams` is explicitly set to `0` but `autoSharding` is not enabled
(or is `false`), the configuration is accepted but `numStreams` is silently
ignored in `BigQueryStorageWriteApiSchemaTransformProvider` (since it only
applies `numStreams` if it is `> 0`). To prevent confusing behavior where a
user configures `0` streams expecting that to be applied, we should validate
that `numStreams` can only be `0` if `autoSharding` is enabled.
```java
if (numStreams != null) {
checkArgument(
numStreams >= 0,
invalidConfigMessage + "numStreams must be non-negative, but was:
%s",
numStreams);
if (numStreams == 0) {
checkArgument(
autoSharding != null && autoSharding,
invalidConfigMessage + "numStreams can only be 0 if autoSharding
is enabled.");
}
}
```
--
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]