luis4a0 commented on code in PR #12963:
URL: https://github.com/apache/gluten/pull/12963#discussion_r4080688763


##########
gluten-substrait/src/main/java/org/apache/gluten/substrait/rel/VirtualTableRelNode.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.substrait.rel;
+
+import org.apache.gluten.substrait.type.TypeNode;
+import org.apache.gluten.utils.SubstraitUtil;
+
+import io.substrait.proto.Expression;
+import io.substrait.proto.NamedStruct;
+import io.substrait.proto.ReadRel;
+import io.substrait.proto.Rel;
+import io.substrait.proto.RelCommon;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+public class VirtualTableRelNode implements RelNode, Serializable {
+  private final List<TypeNode> types;
+  private final List<String> names;
+  private final List<List<Expression.Literal>> rows;
+
+  VirtualTableRelNode(
+      List<TypeNode> types, List<String> names, List<List<Expression.Literal>> 
rows) {
+    Objects.requireNonNull(types, "types");
+    Objects.requireNonNull(names, "names");
+    Objects.requireNonNull(rows, "rows");
+    if (types.size() != names.size()) {
+      throw new IllegalArgumentException(
+          "Virtual table schema has " + types.size() + " types but " + 
names.size() + " names.");
+    }
+    if (rows.isEmpty()) {
+      throw new IllegalArgumentException("Virtual table must contain at least 
one row.");
+    }
+
+    this.types = new ArrayList<>(types);
+    this.names = new ArrayList<>(names);
+    this.rows = new ArrayList<>(rows.size());
+    for (List<Expression.Literal> row : rows) {
+      Objects.requireNonNull(row, "row");
+      if (row.size() != types.size()) {
+        throw new IllegalArgumentException(
+            "Virtual table row has "
+                + row.size()
+                + " fields but the schema has "
+                + types.size()
+                + ".");
+      }
+      ArrayList<Expression.Literal> rowCopy = new ArrayList<>(row.size());
+      for (Expression.Literal literal : row) {
+        rowCopy.add(Objects.requireNonNull(literal, "literal"));
+      }
+      this.rows.add(rowCopy);
+    }

Review Comment:
   Addressed in 
https://github.com/apache/gluten/commit/d4dde9efb649b394588d079cd28f80d7ec5de9b4.
 `VirtualTableRelNode` now copies `types` and `names` element-by-element with 
indexed `Objects.requireNonNull` checks before relation registration. The 
regression cases place null at index 1, verify the indexed diagnostic, and 
assert that `registeredRelMap` remains empty. The focused suite passes 5/5.



##########
gluten-substrait/src/test/scala/org/apache/gluten/execution/WholeStageNoInputSuite.scala:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.execution
+
+import org.mockito.Mockito.mock
+import org.scalatest.funsuite.AnyFunSuite
+
+class WholeStageNoInputSuite extends AnyFunSuite {
+  test("explicit no-input execution creates one dependency-free partition") {
+    val wrapper = new ColumnarInputRDDsWrapper(Seq.empty, 
supportsNoInputExecution = true)
+
+    assert(wrapper.getPartitionLength == 1)
+    assert(wrapper.getDependencies.isEmpty)
+    assert(wrapper.getPartitions(0).isEmpty)
+    assert(wrapper.getIterators(Seq.empty, null).isEmpty)
+  }
+
+  test("an accidental empty input stage still fails") {
+    val wrapper = new ColumnarInputRDDsWrapper(Seq.empty)
+
+    val error = intercept[IllegalStateException] {
+      wrapper.getPartitionLength
+    }
+    assert(error.getMessage.contains("No non-broadcast input RDD is 
available"))
+  }
+
+  test("an explicitly supported broadcast-only input creates one partition") {
+    val broadcast = mock(classOf[BroadcastBuildSideRDD])
+    val wrapper =
+      new ColumnarInputRDDsWrapper(Seq(broadcast), supportsNoInputExecution = 
true)
+
+    assert(wrapper.getDependencies.isEmpty)
+    assert(wrapper.getPartitions(0).isEmpty)
+    assert(wrapper.getPartitionLength == 1)
+  }
+
+  test("an unsupported broadcast-only input still fails") {
+    val broadcast = mock(classOf[BroadcastBuildSideRDD])
+    val wrapper = new ColumnarInputRDDsWrapper(Seq(broadcast))
+
+    intercept[IllegalStateException] {
+      wrapper.getPartitionLength
+    }
+  }
+
+  test("concurrent partition discovery still produces one partition per 
request") {
+    val wrapper = new ColumnarInputRDDsWrapper(Seq.empty, 
supportsNoInputExecution = true)
+    val partitionLengths = Array.fill(32)(0)
+    val threads = partitionLengths.indices.map {
+      index => new Thread(() => partitionLengths(index) = 
wrapper.getPartitionLength)
+    }
+    threads.foreach(_.start())
+    threads.foreach(_.join())

Review Comment:
   Addressed in 
https://github.com/apache/gluten/commit/d4dde9efb649b394588d079cd28f80d7ec5de9b4.
 The workers are daemon threads and now share one monotonic 10-second deadline; 
each join is bounded by the remaining time, followed by an assertion that no 
worker is still alive. The focused concurrent partition-discovery test passes.



##########
gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenSQLQuerySuite.scala:
##########
@@ -166,27 +168,32 @@ class GlutenSQLQuerySuite extends SQLQuerySuite with 
GlutenSQLTestsTrait {
         === Array(plan.stripMargin)
     )
 
+    val oneRowPlan =
+      if (BackendTestUtils.isVeloxBackendLoaded()) {
+        """== Physical Plan ==
+          |ColumnarToRow
+          |+- ^(1) ProjectExecTransformer [1 AS 1#N]
+          |   +- ^(1) OneRowRelationExecTransformer
+          |
+          |""".stripMargin
+      } else {
+        """== Physical Plan ==
+          |ColumnarToRow
+          |+- ^(1) ProjectExecTransformer [1 AS 1#N]
+          |   +- ^(1) InputIteratorTransformer[]
+          |      +- RowToColumnar
+          |         +- *(1) Scan OneRowRelation[]
+          |
+          |""".stripMargin
+      }

Review Comment:
   Addressed in 
https://github.com/apache/gluten/commit/d4dde9efb649b394588d079cd28f80d7ec5de9b4.
 The test now derives native OneRow support through `SparkShimLoader` and 
`BackendsApiManager`, then checks the presence or absence of the 
`RowToColumnar` and `Scan OneRowRelation` fallback boundaries. It no longer 
keys behavior to Velox or hard-codes the transformer display name. The focused 
Spark 4.1 explain regression passes 1/1.



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