github-actions[bot] commented on code in PR #41807:
URL: https://github.com/apache/beam/pull/41807#discussion_r4744844883


##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnApiDoFnRunner.java:
##########
@@ -1705,15 +1740,7 @@ private class WindowObservingProcessBundleContext
 
     @Override
     public OutputBuilder<OutputT> builder(OutputT value) {
-      return WindowedValues.<OutputT>builder()
-          .setValue(value)
-          .setTimestamp(currentElement.getTimestamp())
-          .setPaneInfo(currentElement.getPaneInfo())
-          .setWindows(currentElement.getWindows())
-          .setRecordOffset(currentElement.getRecordOffset())
-          .setRecordId(currentElement.getRecordId())
-          .setCausedByDrain(currentElement.causedByDrain())
-          .setValueKind(currentElement.getValueKind())
+      return WindowedValues.builder(currentElement, value)

Review Comment:
   **🔴 Critical**: `WindowedValues.builder(currentElement, value)` copies all 
windows from `currentElement` (`currentElement.getWindows()`). In 
`WindowObservingProcessBundleContext`, `processElement` is invoked once per 
window (`currentWindow`) when `currentElement` belongs to multiple windows. 
Using `currentElement`'s windows instead of `.setWindow(currentWindow)` causes 
any output built via `builder(...)` (as well as `mainRowOutputReceiver` and 
`taggedOutputReceiver` which also use `currentElement`) to be emitted into all 
of `currentElement`'s windows on every per-window invocation, duplicating 
outputs across windows. It should set `.setWindow(currentWindow)`.
   
   ```suggestion
         return WindowedValues.builder(currentElement, 
value).setWindow(currentWindow)
   ```



##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnApiDoFnRunner.java:
##########
@@ -2132,21 +2232,65 @@ public OutputReceiver<Row> 
outputRowReceiver(DoFn<InputT, OutputT> doFn) {
           private final Map<TupleTag<?>, OutputReceiver<?>> 
taggedOutputReceivers = new HashMap<>();
           private final Map<TupleTag<?>, OutputReceiver<Row>> 
taggedRowReceivers = new HashMap<>();
 
+          private <T> FnDataReceiver<WindowedValue<T>> 
resolveConsumer(TupleTag<T> tag) {
+            return (FnDataReceiver) localNameToConsumer.get(tag.getId());
+          }
+
           private <T> OutputReceiver<T> createTaggedOutputReceiver(TupleTag<T> 
tag) {
             // Note that it is important that we use the non-tag versions here 
when using the main
             // output tag for performance reasons and we also rely on it for 
the splittable DoFn
             // context objects as well.
             if (tag == null || mainOutputTag.equals(tag)) {
               return (OutputReceiver<T>) ProcessBundleContextBase.this;
             }
+            // localNameToConsumer is immutable after construction; resolve 
once per tag.
+            final @Nullable FnDataReceiver<WindowedValue<T>> consumer = 
resolveConsumer(tag);
             return new OutputReceiver<T>() {
+              @Override
+              public void output(T value) {

Review Comment:
   **🔴 Critical**: Similar to `mainRowOutputReceiver`, 
`createTaggedOutputReceiver` and `createTaggedRowReceiver` in 
`ProcessBundleContextBase` bypass the context's windowing and timestamp 
validation:
   1. For `WindowObservingProcessBundleContext`, `output`, 
`outputWithTimestamp`, and `builder` use `currentElement`'s windows instead of 
`currentWindow`, emitting duplicate elements across all windows when an input 
is in multiple windows.
   2. For `NonWindowObservingProcessBundleContext`, `outputWithTimestamp` and 
`outputWindowedValue` no longer validate `timestamp` via 
`checkTimestamp(timestamp)` (though note `builder` previously also delegated to 
`outputWindowedValue(tag, WindowedValue)` which didn't check timestamps).



##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnApiDoFnRunner.java:
##########
@@ -2105,13 +2155,63 @@ public void output(OutputT output) {
               private final SerializableFunction<Row, OutputT> fromRowFunction 
=
                   mainOutputSchemaCoder.getFromRowFunction();
 
+              @Override
+              public void output(Row value) {

Review Comment:
   **🔴 Critical**: In `ProcessBundleContextBase.mainRowOutputReceiver`, 
`output`, `outputWithTimestamp`, `outputWindowedValue`, and `builder` now 
bypass `ProcessBundleContextBase.this` and construct `WindowedValue` directly 
from `currentElement` and send it straight to `mainOutputConsumer`. This causes 
two regressions:
   1. In `NonWindowObservingProcessBundleContext`, `outputWithTimestamp`, 
`outputWindowedValue`, and `builder` no longer call `checkTimestamp(...)`, 
allowing invalid timestamps outside `getAllowedTimestampSkew()` to be emitted 
without throwing `IllegalArgumentException`.
   2. In `WindowObservingProcessBundleContext`, `output`, 
`outputWithTimestamp`, and `builder` copy `currentElement.getWindows()` instead 
of using `currentWindow`, duplicating outputs into all windows when an input 
element belongs to multiple windows.



-- 
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]

Reply via email to