yaooqinn commented on code in PR #13825:
URL: https://github.com/apache/gluten/pull/13825#discussion_r4725607720


##########
cpp/velox/tests/SubstraitVeloxExprConverterTest.cc:
##########
@@ -31,6 +31,23 @@ namespace gluten {
 
 class SubstraitVeloxExprConverterExecutionTest : public 
exec::test::OperatorTestBase {};
 
+TEST(SubstraitVeloxExprConverterTest, emptyStructLiteral) {
+  memory::MemoryManager::testingSetInstance({});
+  auto pool = memory::memoryManager()->addLeafPool();
+  const std::unordered_map<uint64_t, std::string> functionMap;
+  SubstraitVeloxExprConverter converter(pool.get(), functionMap);
+  ::substrait::Expression expression;
+  expression.mutable_literal()->mutable_struct_();
+
+  auto result =
+      std::dynamic_pointer_cast<const 
core::ConstantTypedExpr>(converter.toVeloxExpr(expression, ROW({}, {})));
+  ASSERT_NE(result, nullptr);
+  EXPECT_TRUE(result->type()->equivalent(*ROW({}, {})));
+  ASSERT_TRUE(result->hasValueVector());
+  ASSERT_EQ(result->valueVector()->size(), 1);

Review Comment:
   This checks the constant wrapper, which `wrapInConstant(1, 0, …)` always 
makes one row, so it would pass even if the base row vector still had zero 
rows; the test only catches the bug because the old code crashes the binary 
(SIGFPE in the `ConstantVector` constructor, which divides `representedBytes` 
by the base size). Could it assert 
`result->valueVector()->wrappedVector()->size() == 1` instead?
   
   The same `makeEmptyRowVector` also feeds array, map and struct literals 
(`literalsToVector`, `literalsToRowVector`), and `makeArrayVector` takes the 
array size from the element vector, so with zero-row elements `array(struct(), 
struct())` would come out empty rather than with two elements. A case for that 
path, natively or as a `runQueryAndCompare` of something like `SELECT 
size(if(id < 0, null, array(struct(), struct()))) FROM range(2)` (vanilla gives 
2 for each row; the `if` keeps it from being constant-folded, and `size` keeps 
`array<struct<>>` out of the output schema, which `VeloxValidatorApi` would 
reject), would cover the wrong-result side of this fix.
   



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