Copilot commented on code in PR #12327:
URL: https://github.com/apache/gluten/pull/12327#discussion_r3510306082


##########
gluten-flink/runtime/src/main/java/org/apache/gluten/table/runtime/operators/GlutenTwoInputOperator.java:
##########
@@ -234,28 +262,49 @@ public void processWatermark2(Watermark mark) throws 
Exception {
     processElementInternal();
   }
 
+  @Override
+  public void endInput(int inputId) throws Exception {
+    switch (inputId) {
+      case 1:
+        leftInputEnded = true;
+        if (leftInputQueue != null) {
+          leftInputQueue.noMoreInput();
+        }
+        break;
+      case 2:
+        rightInputEnded = true;
+        if (rightInputQueue != null) {
+          rightInputQueue.noMoreInput();
+        }
+        break;
+      default:
+        throw new IllegalArgumentException("Unknown input id: " + inputId);
+    }
+  }

Review Comment:
   `endInput(int)` records `leftInputEnded/rightInputEnded` and calls 
`noMoreInput()`, but never acts on both inputs having ended. This leaves 
`finishTask()` unused and risks not draining final outputs for bounded inputs. 
Consider finishing the Velox task once both inputs have ended.



##########
gluten-flink/runtime/src/main/java/org/apache/gluten/table/runtime/operators/GlutenOneInputOperator.java:
##########
@@ -259,10 +285,18 @@ public void processWatermark2(Watermark mark) throws 
Exception {
     throw new UnsupportedOperationException("Not implemented for 
GlutenOneInputOperator");
   }
 
+  @Override
+  public void endInput() throws Exception {
+    if (inputQueue != null) {
+      inputQueue.noMoreInput();
+    }
+  }

Review Comment:
   `endInput()` currently only signals `inputQueue.noMoreInput()` but never 
drains/finishes the Velox task, so bounded jobs may not flush final output 
before completion. Since a `finishTask()` helper exists, it should be invoked 
here after signaling end-of-input.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/NexmarkTest.java:
##########
@@ -71,7 +72,7 @@ public class NexmarkTest {
         }
       };
 
-  private static final int KAFKA_PORT = 19092;
+  private static final int KAFKA_PORT = 
Integer.getInteger("gluten.flink.ut.kafka.port", 9092);

Review Comment:
   Changing the embedded Kafka listener default port from 19092 to 9092 makes 
tests more likely to conflict with a developer’s local Kafka (9092 is the 
common default). Keeping 19092 as the default while still allowing override via 
system property should be more reliable.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/NexmarkTest.java:
##########
@@ -242,11 +245,45 @@ private void executeQuery(StreamTableEnvironment tEnv, 
String queryFileName, boo
         assertThat(checkJobRunningStatus(insertResult, 30000) == true);
       } else {
         waitForJobCompletion(insertResult, 30000);
+        if ("q10_orc.sql".equals(queryFileName)) {
+          verifyQ10OrcOutput(queryStartMillis);
+        }

Review Comment:
   `verifyQ10OrcOutput` filters output files by `lastModifiedTime >= 
queryStartMillis`. On filesystems with coarse timestamp granularity (e.g., 1s), 
files created in the same second can end up with `lastModifiedTime` slightly 
before `queryStartMillis`, making this check flaky. Adding a small negative 
skew to the start time reduces this risk.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/operators/GlutenTwoInputOperatorCloseTest.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.gluten.table.runtime.operators;
+
+import io.github.zhztheplayer.velox4j.connector.ExternalStreams;
+import io.github.zhztheplayer.velox4j.data.RowVector;
+import io.github.zhztheplayer.velox4j.iterator.UpIterator;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.query.SerialTask;
+import io.github.zhztheplayer.velox4j.stateful.StatefulElement;
+import io.github.zhztheplayer.velox4j.type.BigIntType;
+import io.github.zhztheplayer.velox4j.type.RowType;
+
+import org.apache.flink.table.data.RowData;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class GlutenTwoInputOperatorCloseTest {
+  private static final RowType ROW_TYPE = new RowType(List.of("c0"), 
List.of(new BigIntType()));
+
+  @Test
+  public void testEndInputFinishesAfterBothInputsEnd() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenTwoInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue leftQueue = new FakeBlockingQueue(1, "left", calls);
+    FakeBlockingQueue rightQueue = new FakeBlockingQueue(2, "right", calls);
+    FakeSerialTask task = new FakeSerialTask(calls, false);
+    setField(operator, "leftInputQueue", leftQueue);
+    setField(operator, "rightInputQueue", rightQueue);
+    setField(operator, "task", task);
+
+    operator.endInput(1);
+
+    assertThat(calls).containsExactly("left.noMoreInput");
+
+    operator.endInput(2);
+
+    assertThat(calls).containsExactly("left.noMoreInput", "right.noMoreInput");
+  }
+
+  @Test
+  public void testCloseOnlyCleansResources() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenTwoInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue leftQueue = new FakeBlockingQueue(1, "left", calls);
+    FakeBlockingQueue rightQueue = new FakeBlockingQueue(2, "right", calls);
+    FakeSerialTask task = new FakeSerialTask(calls, false);
+    setField(operator, "leftInputQueue", leftQueue);
+    setField(operator, "rightInputQueue", rightQueue);
+    setField(operator, "task", task);
+
+    operator.close();
+
+    assertThat(calls)
+        .containsExactly("task.advance", "task.unbind", "task.close", 
"left.close", "right.close");
+  }
+
+  @Test
+  public void testCloseCleansResourcesWhenCloseFails() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenTwoInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue leftQueue = new FakeBlockingQueue(1, "left", calls, 
true);
+    FakeBlockingQueue rightQueue = new FakeBlockingQueue(2, "right", calls);
+    FakeSerialTask task = new FakeSerialTask(calls, false);
+    setField(operator, "leftInputQueue", leftQueue);
+    setField(operator, "rightInputQueue", rightQueue);
+    setField(operator, "task", task);
+
+    assertThatThrownBy(operator::close)
+        .isInstanceOf(RuntimeException.class)
+        .hasMessage("left.close");
+
+    assertThat(calls)
+        .containsExactly("task.advance", "task.unbind", "task.close", 
"left.close", "right.close");
+  }

Review Comment:
   Same as above: `close()` doesn’t invoke `task.advance()`, so the expected 
call sequence should not include it when validating cleanup behavior after a 
close failure.



##########
gluten-flink/ut/pom.xml:
##########
@@ -195,6 +195,24 @@
       <version>${flink.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.flink</groupId>
+      <artifactId>flink-orc</artifactId>
+      <version>${flink.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>3.25.5</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-client</artifactId>
+      <version>2.7.4</version>
+      <scope>test</scope>
+    </dependency>

Review Comment:
   This module hard-codes `hadoop-client` version `2.7.4`, but the repo already 
centralizes Hadoop via the `${hadoop.version}` property (pom.xml:85) and 
overrides it in profiles. Using the shared property keeps Flink UTs compatible 
with those profiles.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/operators/GlutenTwoInputOperatorCloseTest.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.gluten.table.runtime.operators;
+
+import io.github.zhztheplayer.velox4j.connector.ExternalStreams;
+import io.github.zhztheplayer.velox4j.data.RowVector;
+import io.github.zhztheplayer.velox4j.iterator.UpIterator;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.query.SerialTask;
+import io.github.zhztheplayer.velox4j.stateful.StatefulElement;
+import io.github.zhztheplayer.velox4j.type.BigIntType;
+import io.github.zhztheplayer.velox4j.type.RowType;
+
+import org.apache.flink.table.data.RowData;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class GlutenTwoInputOperatorCloseTest {
+  private static final RowType ROW_TYPE = new RowType(List.of("c0"), 
List.of(new BigIntType()));
+
+  @Test
+  public void testEndInputFinishesAfterBothInputsEnd() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenTwoInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue leftQueue = new FakeBlockingQueue(1, "left", calls);
+    FakeBlockingQueue rightQueue = new FakeBlockingQueue(2, "right", calls);
+    FakeSerialTask task = new FakeSerialTask(calls, false);
+    setField(operator, "leftInputQueue", leftQueue);
+    setField(operator, "rightInputQueue", rightQueue);
+    setField(operator, "task", task);
+
+    operator.endInput(1);
+
+    assertThat(calls).containsExactly("left.noMoreInput");
+
+    operator.endInput(2);
+
+    assertThat(calls).containsExactly("left.noMoreInput", "right.noMoreInput");
+  }

Review Comment:
   If `endInput(int)` finishes the task when both inputs end, the second 
`endInput(2)` call should also trigger `task.advance()`. Updating the assertion 
makes the test validate the intended bounded-input completion behavior.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/operators/GlutenOneInputOperatorCloseTest.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.gluten.table.runtime.operators;
+
+import io.github.zhztheplayer.velox4j.connector.ExternalStreams;
+import io.github.zhztheplayer.velox4j.data.RowVector;
+import io.github.zhztheplayer.velox4j.iterator.UpIterator;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.query.SerialTask;
+import io.github.zhztheplayer.velox4j.stateful.StatefulElement;
+import io.github.zhztheplayer.velox4j.type.BigIntType;
+import io.github.zhztheplayer.velox4j.type.RowType;
+
+import org.apache.flink.table.data.RowData;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GlutenOneInputOperatorCloseTest {
+  private static final RowType ROW_TYPE = new RowType(List.of("c0"), 
List.of(new BigIntType()));
+
+  @Test
+  public void testEndInputFinishesTask() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenOneInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue inputQueue = new FakeBlockingQueue(1, calls);
+    FakeSerialTask task = new FakeSerialTask(calls);
+    setField(operator, "inputQueue", inputQueue);
+    setField(operator, "task", task);
+
+    operator.endInput();
+
+    assertThat(calls).containsExactly("input.noMoreInput");
+  }

Review Comment:
   After `GlutenOneInputOperator.endInput()` is called, the operator is 
expected to finish the native task; with the proposed runtime change, 
`SerialTask.advance()` will be invoked. The assertion should include the 
expected `task.advance` call so the test actually validates end-of-input 
completion behavior.



##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/operators/GlutenTwoInputOperatorCloseTest.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.gluten.table.runtime.operators;
+
+import io.github.zhztheplayer.velox4j.connector.ExternalStreams;
+import io.github.zhztheplayer.velox4j.data.RowVector;
+import io.github.zhztheplayer.velox4j.iterator.UpIterator;
+import io.github.zhztheplayer.velox4j.plan.StatefulPlanNode;
+import io.github.zhztheplayer.velox4j.query.SerialTask;
+import io.github.zhztheplayer.velox4j.stateful.StatefulElement;
+import io.github.zhztheplayer.velox4j.type.BigIntType;
+import io.github.zhztheplayer.velox4j.type.RowType;
+
+import org.apache.flink.table.data.RowData;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class GlutenTwoInputOperatorCloseTest {
+  private static final RowType ROW_TYPE = new RowType(List.of("c0"), 
List.of(new BigIntType()));
+
+  @Test
+  public void testEndInputFinishesAfterBothInputsEnd() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenTwoInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue leftQueue = new FakeBlockingQueue(1, "left", calls);
+    FakeBlockingQueue rightQueue = new FakeBlockingQueue(2, "right", calls);
+    FakeSerialTask task = new FakeSerialTask(calls, false);
+    setField(operator, "leftInputQueue", leftQueue);
+    setField(operator, "rightInputQueue", rightQueue);
+    setField(operator, "task", task);
+
+    operator.endInput(1);
+
+    assertThat(calls).containsExactly("left.noMoreInput");
+
+    operator.endInput(2);
+
+    assertThat(calls).containsExactly("left.noMoreInput", "right.noMoreInput");
+  }
+
+  @Test
+  public void testCloseOnlyCleansResources() throws Exception {
+    List<String> calls = new ArrayList<>();
+    GlutenTwoInputOperator<RowData, RowData> operator = newOperator();
+    FakeBlockingQueue leftQueue = new FakeBlockingQueue(1, "left", calls);
+    FakeBlockingQueue rightQueue = new FakeBlockingQueue(2, "right", calls);
+    FakeSerialTask task = new FakeSerialTask(calls, false);
+    setField(operator, "leftInputQueue", leftQueue);
+    setField(operator, "rightInputQueue", rightQueue);
+    setField(operator, "task", task);
+
+    operator.close();
+
+    assertThat(calls)
+        .containsExactly("task.advance", "task.unbind", "task.close", 
"left.close", "right.close");
+  }

Review Comment:
   `GlutenTwoInputOperator.close()` does not call `SerialTask.advance()`, so 
the close-related assertions expecting `task.advance` will fail. Either make 
`close()` advance/finish the task, or (more consistent with the test name) 
update the expectations to only cover resource cleanup calls.



##########
gluten-flink/ut/pom.xml:
##########
@@ -195,6 +195,24 @@
       <version>${flink.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.flink</groupId>
+      <artifactId>flink-orc</artifactId>
+      <version>${flink.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>3.25.5</version>
+      <scope>test</scope>
+    </dependency>

Review Comment:
   This module hard-codes `protobuf-java` version `3.25.5`, but the repo 
already centralizes Protobuf via the `${protobuf.version}` property 
(pom.xml:112). Using the shared property avoids accidental version skew across 
modules.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to