Copilot commented on code in PR #12963: URL: https://github.com/apache/gluten/pull/12963#discussion_r4072939818
########## 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: The constructor validates null `rows`/`row`/`literal`, but does not validate that individual `types` and `names` elements are non-null. If a caller passes a list containing null elements, the object can be constructed and registered, but later `toProtobuf()` may fail with a less actionable NPE (and after registration has occurred). Consider validating each `TypeNode` and each `String` name with `Objects.requireNonNull` (optionally including the index in the message) before copying. ########## 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: The test uses `Thread.join()` without a timeout. If `getPartitionLength` ever regresses into a deadlock or infinite wait, the suite can hang indefinitely. Consider joining with a bounded timeout and asserting all threads completed (e.g., `threads.foreach(_.join(…))` plus an `assert(!thread.isAlive)`), so failures are reported as test failures rather than stalled runs. ########## 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: This regression expectation is keyed specifically to `isVeloxBackendLoaded()`. If another backend later adds native `OneRowRelationExec` support (or Velox changes the printed node name), this test will fail despite correct behavior. A more robust approach is to assert on the presence/absence of the specific fallback boundary lines (e.g., `RowToColumnar` + `Scan OneRowRelation`) rather than hard-coding an entire backend-specific plan string, or to key the expectation off a capability signal (e.g., whether `genOneRowRelationExecTransformer` is overridden/active) instead of the backend name. -- 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]
