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


##########
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:
   Addressed in 
https://github.com/apache/gluten/commit/5cf111fb8dfff46a141f980b9db5f7c9697ec27f.
 The test now keeps the `readCursor` return value in one named pair and reads 
`.second`, so no unused structured-binding variable is introduced while the 
cursor remains alive through the assertions. The focused native target builds 
and all 8 values-node conversion tests pass.



##########
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:
   Addressed in 
https://github.com/apache/gluten/commit/5cf111fb8dfff46a141f980b9db5f7c9697ec27f
 with the same single-pair pattern. The test reads results through `.second` 
without creating an unused `cursor` binding. The focused native target builds 
and all 8 values-node conversion tests pass.



##########
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:
   Addressed in 
https://github.com/apache/gluten/commit/5cf111fb8dfff46a141f980b9db5f7c9697ec27f.
 The test now passes a Mockito `TaskContext` test double instead of `null`, 
using the suite’s existing Mockito dependency. The exact final 
`WholeStageNoInputSuite` source compiles and all 5 tests pass.



##########
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:
   Addressed in 
https://github.com/apache/gluten/commit/5cf111fb8dfff46a141f980b9db5f7c9697ec27f.
 The Scaladoc now states that this is exact recognition of Spark 4.1+ 
`OneRowRelationExec`, explains why earlier shims return `false`, and warns 
callers not to infer generic zero-input semantics from `false`.



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