gemini-code-assist[bot] commented on code in PR #37851:
URL: https://github.com/apache/beam/pull/37851#discussion_r2933568731
##########
runners/core-java/src/main/java/org/apache/beam/runners/core/SimpleDoFnRunner.java:
##########
@@ -1027,6 +1039,16 @@ public <T> void outputWindowedValue(
.output();
}
+ @Override
+ public void outputWindowedValue(WindowedValue<OutputT> windowedValue) {
+ SimpleDoFnRunner.this.outputWindowedValue(mainOutputTag, windowedValue);
+ }
+
+ @Override
+ public <T> void outputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
+ SimpleDoFnRunner.this.outputWindowedValue(tag, windowedValue);
+ }
Review Comment:

The new `outputWindowedValue` methods in `OnTimerArgumentProvider` seem to
be missing a call to `checkTimestamp`. Other output methods in this class, like
`outputWithTimestamp`, include this check. This could lead to incorrect
timestamps on output elements. Please add the timestamp check for consistency
and correctness.
```suggestion
public void outputWindowedValue(WindowedValue<OutputT> windowedValue) {
checkTimestamp(timestamp(), windowedValue.getTimestamp());
SimpleDoFnRunner.this.outputWindowedValue(mainOutputTag,
windowedValue);
}
@Override
public <T> void outputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
checkTimestamp(timestamp(), windowedValue.getTimestamp());
SimpleDoFnRunner.this.outputWindowedValue(tag, windowedValue);
}
```
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/MetadataPropagationTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.transforms;
+
+import org.apache.beam.sdk.testing.NeedsRunner;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.values.CausedByDrain;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+public class MetadataPropagationTest {
+ private static final Integer[] EMPTY = new Integer[] {};
+ private static final Integer[] DATA = new Integer[] {1, 2, 3, 4, 5};
+ private static final Integer[] REPEATED_DATA = new Integer[] {1, 1, 2, 2, 3,
3, 4, 4, 5, 5};
+
+ @RunWith(JUnit4.class)
+ public static class MiscTest {
Review Comment:

The tests in this class modify a global static flag
`WindowedValues.WindowedValueCoder.metadataSupported`. This can lead to test
flakiness and interference, as the order of test execution is not guaranteed.
For example, if `testMetadataPropagationAcrossShuffleParameter` runs before
`testDefaultMetadataPropagationAcrossShuffleParameter`, the latter will fail
because it asserts `isMetadataSupported()` is false.
To ensure test isolation, you should manage this static state. A good
approach would be to add a method to `WindowedValueCoder` to reset this flag
(e.g., `setMetadataNotSupported()`) and call it in an `@After` method in your
test class. This will make your tests more robust and reliable.
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java:
##########
@@ -644,6 +644,38 @@ public <T> void outputWithTimestamp(TupleTag<T> tag, T
output, Instant timestamp
CausedByDrain.NORMAL));
}
+ @Override
+ public void outputWindowedValue(WindowedValue<OutputT> windowedValue) {
+ for (BoundedWindow w : windowedValue.getWindows()) {
+ getMutableOutput(mainOutputTag)
+ .add(
+ ValueInSingleWindow.of(
+ windowedValue.getValue(),
+ windowedValue.getTimestamp(),
+ w,
+ windowedValue.getPaneInfo(),
+ windowedValue.getRecordId(),
+ windowedValue.getRecordOffset(),
+ windowedValue.causedByDrain()));
+ }
+ }
+
+ @Override
+ public <T> void outputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
+ for (BoundedWindow w : windowedValue.getWindows()) {
+ getMutableOutput(tag)
+ .add(
+ ValueInSingleWindow.of(
+ windowedValue.getValue(),
+ windowedValue.getTimestamp(),
+ w,
+ windowedValue.getPaneInfo(),
+ windowedValue.getRecordId(),
+ windowedValue.getRecordOffset(),
+ windowedValue.causedByDrain()));
+ }
+ }
Review Comment:

There's some code duplication between the two new `outputWindowedValue`
methods. The logic for iterating through windows and creating
`ValueInSingleWindow` instances is identical. To improve maintainability and
reduce redundancy, you could extract this common logic into a private helper
method.
```java
private <T> void doOutputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
for (BoundedWindow w : windowedValue.getWindows()) {
getMutableOutput(tag)
.add(
ValueInSingleWindow.of(
windowedValue.getValue(),
windowedValue.getTimestamp(),
w,
windowedValue.getPaneInfo(),
windowedValue.getRecordId(),
windowedValue.getRecordOffset(),
windowedValue.causedByDrain()));
}
}
@Override
public void outputWindowedValue(WindowedValue<OutputT> windowedValue) {
doOutputWindowedValue(mainOutputTag, windowedValue);
}
@Override
public <T> void outputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
doOutputWindowedValue(tag, windowedValue);
}
```
##########
runners/core-java/src/main/java/org/apache/beam/runners/core/OutputAndTimeBoundedSplittableProcessElementInvoker.java:
##########
@@ -472,6 +472,26 @@ public <T> void outputWindowedValue(
element.causedByDrain()));
}
+ @Override
+ public void outputWindowedValue(WindowedValue<OutputT> windowedValue) {
+ noteOutput();
+ if (watermarkEstimator instanceof TimestampObservingWatermarkEstimator) {
+ ((TimestampObservingWatermarkEstimator) watermarkEstimator)
+ .observeTimestamp(windowedValue.getTimestamp());
+ }
+ outputReceiver.output(mainOutputTag, windowedValue);
+ }
+
+ @Override
+ public <T> void outputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
+ noteOutput();
+ if (watermarkEstimator instanceof TimestampObservingWatermarkEstimator) {
+ ((TimestampObservingWatermarkEstimator) watermarkEstimator)
+ .observeTimestamp(windowedValue.getTimestamp());
+ }
+ outputReceiver.output(tag, windowedValue);
+ }
Review Comment:

There's some code duplication between the two new `outputWindowedValue`
methods. The logic for `noteOutput()` and observing the timestamp is identical.
To improve maintainability, you could extract this common logic into a private
helper method.
```suggestion
private void noteOutputAndObserveTimestamp(Instant timestamp) {
noteOutput();
if (watermarkEstimator instanceof
TimestampObservingWatermarkEstimator) {
((TimestampObservingWatermarkEstimator) watermarkEstimator)
.observeTimestamp(timestamp);
}
}
@Override
public void outputWindowedValue(WindowedValue<OutputT> windowedValue) {
noteOutputAndObserveTimestamp(windowedValue.getTimestamp());
outputReceiver.output(mainOutputTag, windowedValue);
}
@Override
public <T> void outputWindowedValue(TupleTag<T> tag, WindowedValue<T>
windowedValue) {
noteOutputAndObserveTimestamp(windowedValue.getTimestamp());
outputReceiver.output(tag, windowedValue);
}
```
--
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]