Copilot commented on code in PR #12963:
URL: https://github.com/apache/gluten/pull/12963#discussion_r4081958035
##########
cpp/velox/tests/Substrait2VeloxValuesNodeConversionTest.cc:
##########
@@ -62,7 +56,250 @@ TEST_F(Substrait2VeloxValuesNodeConversionTest, valuesNode)
{
});
createDuckDbTable({expectedData});
- assertQuery(veloxPlan, "SELECT * FROM tmp");
+ for (const bool validationMode : {false, true}) {
+ auto veloxCfg =
+
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ VeloxConnectorIds{},
+ std::nullopt,
+ std::nullopt,
+ validationMode);
+ assertQuery(planConverter->toVeloxPlan(substraitPlan), "SELECT * FROM
tmp");
+ }
+}
+
+TEST_F(Substrait2VeloxValuesNodeConversionTest, zeroColumnOneRowValuesNode) {
+ auto planPath =
FilePathGenerator::getDataFilePath("substrait_virtualTable_emptySchema.json");
+
+ ::substrait::Plan substraitPlan;
+ JsonToProtoConverter::readFromFile(planPath, substraitPlan);
+ auto veloxCfg =
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ VeloxConnectorIds{},
+ std::nullopt,
+ std::nullopt,
+ false);
+ auto veloxPlan = planConverter->toVeloxPlan(substraitPlan);
+
+ auto valuesNode = std::dynamic_pointer_cast<const
core::ValuesNode>(veloxPlan);
+ ASSERT_NE(valuesNode, nullptr);
+ ASSERT_TRUE(valuesNode->outputType()->equivalent(*ROW({})));
+ ASSERT_EQ(valuesNode->values().size(), 1);
+ ASSERT_EQ(valuesNode->values().front()->childrenSize(), 0);
+ ASSERT_EQ(valuesNode->values().front()->size(), 1);
+ const auto& splitInfos = planConverter->splitInfos();
+ const auto splitInfo = splitInfos.find(valuesNode->id());
+ ASSERT_NE(splitInfo, splitInfos.end());
+ ASSERT_NE(splitInfo->second, nullptr);
+ ASSERT_EQ(splitInfo->second->leafType, SplitInfo::LeafType::TRIVIAL_LEAF);
+
+ CursorParameters params;
+ params.planNode = veloxPlan;
+ auto [cursor, results] = readCursor(params);
+ ASSERT_EQ(results.size(), 1);
+ ASSERT_EQ(results.front()->childrenSize(), 0);
+ ASSERT_EQ(results.front()->size(), 1);
+}
+
+TEST_F(Substrait2VeloxValuesNodeConversionTest,
virtualTableDoesNotConsumeTableScanSplit) {
+ auto planPath =
FilePathGenerator::getDataFilePath("substrait_virtualTable.json");
+
+ ::substrait::Plan substraitPlan;
+ JsonToProtoConverter::readFromFile(planPath, substraitPlan);
+ const auto virtualRead = substraitPlan.relations(0).root().input().read();
+
+ auto* setRel =
substraitPlan.mutable_relations(0)->mutable_root()->mutable_input()->mutable_set();
+ setRel->set_op(::substrait::SetRel_SetOp::SetRel_SetOp_SET_OP_UNION_ALL);
+ setRel->add_inputs()->mutable_read()->CopyFrom(virtualRead);
+ auto* tableScanRead = setRel->add_inputs()->mutable_read();
+ tableScanRead->CopyFrom(virtualRead);
+ tableScanRead->clear_virtual_table();
+
+ auto veloxCfg =
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ VeloxConnectorIds connectorIds;
+ connectorIds.hive = "test-hive";
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ std::move(connectorIds),
+ std::nullopt,
+ std::nullopt,
+ false);
+ auto tableScanSplit = std::make_shared<SplitInfo>();
+ tableScanSplit->leafType = SplitInfo::LeafType::TABLE_SCAN;
+ planConverter->setSplitInfos({tableScanSplit});
+
+ auto veloxPlan = planConverter->toVeloxPlan(substraitPlan);
+ ASSERT_NE(std::dynamic_pointer_cast<const
core::LocalPartitionNode>(veloxPlan), nullptr);
+
+ const auto& splitInfos = planConverter->splitInfos();
+ ASSERT_EQ(splitInfos.size(), 2);
+ ASSERT_EQ(
+ std::count_if(
+ splitInfos.begin(),
+ splitInfos.end(),
+ [](const auto& entry) { return entry.second->leafType ==
SplitInfo::LeafType::TRIVIAL_LEAF; }),
+ 1);
+ ASSERT_EQ(
+ std::count_if(
+ splitInfos.begin(), splitInfos.end(), [&](const auto& entry) {
return entry.second == tableScanSplit; }),
+ 1);
+}
+
+TEST_F(Substrait2VeloxValuesNodeConversionTest,
rejectsEmptyVirtualTableInAllModes) {
+ auto planPath =
FilePathGenerator::getDataFilePath("substrait_virtualTable_emptySchema.json");
+ for (const bool validationMode : {false, true}) {
+ ::substrait::Plan substraitPlan;
+ JsonToProtoConverter::readFromFile(planPath, substraitPlan);
+ substraitPlan.mutable_relations(0)
+ ->mutable_root()
+ ->mutable_input()
+ ->mutable_read()
+ ->mutable_virtual_table()
+ ->clear_expressions();
+
+ auto veloxCfg =
+
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ VeloxConnectorIds{},
+ std::nullopt,
+ std::nullopt,
+ validationMode);
+
+ VELOX_ASSERT_THROW(planConverter->toVeloxPlan(substraitPlan), "Virtual
table must contain at least one row group.");
+ }
+}
+
+TEST_F(Substrait2VeloxValuesNodeConversionTest,
supportsZeroRowVirtualTableInAllModes) {
+ auto planPath =
FilePathGenerator::getDataFilePath("substrait_virtualTable.json");
+ for (const bool validationMode : {false, true}) {
+ ::substrait::Plan substraitPlan;
+ JsonToProtoConverter::readFromFile(planPath, substraitPlan);
+ substraitPlan.mutable_relations(0)
+ ->mutable_root()
+ ->mutable_input()
+ ->mutable_read()
+ ->mutable_virtual_table()
+ ->mutable_expressions(0)
+ ->clear_fields();
+
+ auto veloxCfg =
+
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ VeloxConnectorIds{},
+ std::nullopt,
+ std::nullopt,
+ validationMode);
+
+ auto values =
+ std::dynamic_pointer_cast<const
facebook::velox::core::ValuesNode>(planConverter->toVeloxPlan(substraitPlan));
+ ASSERT_NE(values, nullptr);
+ ASSERT_EQ(values->values().size(), 1);
+ ASSERT_EQ(values->values().front()->size(), 0);
+ if (!validationMode) {
+ CursorParameters params;
+ params.planNode = values;
+ auto [cursor, results] = readCursor(params);
Review Comment:
Same issue as above: `cursor` is bound but unused. This is prone to
`-Wunused-variable` failures in stricter toolchains. Avoid binding `cursor` if
you don't need it.
##########
cpp/velox/tests/Substrait2VeloxValuesNodeConversionTest.cc:
##########
@@ -62,7 +56,250 @@ TEST_F(Substrait2VeloxValuesNodeConversionTest, valuesNode)
{
});
createDuckDbTable({expectedData});
- assertQuery(veloxPlan, "SELECT * FROM tmp");
+ for (const bool validationMode : {false, true}) {
+ auto veloxCfg =
+
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ VeloxConnectorIds{},
+ std::nullopt,
+ std::nullopt,
+ validationMode);
+ assertQuery(planConverter->toVeloxPlan(substraitPlan), "SELECT * FROM
tmp");
+ }
+}
+
+TEST_F(Substrait2VeloxValuesNodeConversionTest, zeroColumnOneRowValuesNode) {
+ auto planPath =
FilePathGenerator::getDataFilePath("substrait_virtualTable_emptySchema.json");
+
+ ::substrait::Plan substraitPlan;
+ JsonToProtoConverter::readFromFile(planPath, substraitPlan);
+ auto veloxCfg =
std::make_shared<facebook::velox::config::ConfigBase>(std::unordered_map<std::string,
std::string>());
+ auto planConverter = std::make_shared<SubstraitToVeloxPlanConverter>(
+ pool_.get(),
+ veloxCfg.get(),
+ std::vector<std::shared_ptr<ResultIterator>>{},
+ VeloxConnectorIds{},
+ std::nullopt,
+ std::nullopt,
+ false);
+ auto veloxPlan = planConverter->toVeloxPlan(substraitPlan);
+
+ auto valuesNode = std::dynamic_pointer_cast<const
core::ValuesNode>(veloxPlan);
+ ASSERT_NE(valuesNode, nullptr);
+ ASSERT_TRUE(valuesNode->outputType()->equivalent(*ROW({})));
+ ASSERT_EQ(valuesNode->values().size(), 1);
+ ASSERT_EQ(valuesNode->values().front()->childrenSize(), 0);
+ ASSERT_EQ(valuesNode->values().front()->size(), 1);
+ const auto& splitInfos = planConverter->splitInfos();
+ const auto splitInfo = splitInfos.find(valuesNode->id());
+ ASSERT_NE(splitInfo, splitInfos.end());
+ ASSERT_NE(splitInfo->second, nullptr);
+ ASSERT_EQ(splitInfo->second->leafType, SplitInfo::LeafType::TRIVIAL_LEAF);
+
+ CursorParameters params;
+ params.planNode = veloxPlan;
+ auto [cursor, results] = readCursor(params);
Review Comment:
The structured binding assigns `cursor` but it is never used in this test.
If the build enables `-Wunused-variable` (often with `-Werror`), this can fail
compilation. Consider restructuring to avoid binding an unused variable (e.g.,
bind to a single variable and access `.second`, or otherwise explicitly ignore
the cursor).
##########
gluten-substrait/src/test/scala/org/apache/gluten/execution/WholeStageNoInputSuite.scala:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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
+
+import java.util.concurrent.TimeUnit
+
+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)
Review Comment:
Passing `null` for the TaskContext parameter makes this test fragile and can
mask real regressions if `getIterators` later starts using the context
unconditionally. Prefer using a real `TaskContext` (e.g., the Spark-provided
empty context if available) or a mock/stub to keep the test robust.
##########
shims/common/src/main/scala/org/apache/gluten/sql/shims/SparkShims.scala:
##########
@@ -173,6 +173,8 @@ trait SparkShims {
*/
def getLocalTableScanStream(plan: LocalTableScanExec):
Option[SparkDataStream] = None
Review Comment:
`isOneRowRelationExec` is a new cross-version shim hook, but it has no
Scaladoc explaining the Spark-version semantics (e.g., Spark 4.1+) and the
intended usage/contract (what callers should assume when it returns false).
Adding a brief comment here would make the API clearer for new shim
implementers.
--
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]