Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the empty-struct literal conversion change.
No open issues 🎉
What changed in this PR
Fixes a Velox backend crash when converting empty struct literals such as struct() by representing the value as one non-null row with zero fields.
Changes:
- Preserves one row when constructing an empty struct’s row vector.
- Adds a native regression test checking the converted constant’s type, row count, and nullness.
| File | Description |
|---|---|
cpp/velox/tests/SubstraitVeloxExprConverterTest.cc |
Adds regression coverage for empty struct literal conversion. |
cpp/velox/substrait/SubstraitToVeloxExpr.cc |
Changes empty struct row-vector size from zero to one. |
Review effort: Balanced
| ASSERT_NE(result, nullptr); | ||
| EXPECT_TRUE(result->type()->equivalent(*ROW({}, {}))); | ||
| ASSERT_TRUE(result->hasValueVector()); | ||
| ASSERT_EQ(result->valueVector()->size(), 1); |
There was a problem hiding this 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.
What changes are proposed in this pull request?
Fix a crash in the Velox backend when converting an empty struct literal such as struct(). The converter created a RowVector with zero rows, then tried to wrap row 0 as a constant. It now creates one row with zero fields to represent the non-null empty struct value.
How was this patch tested?
Added and ran SubstraitVeloxExprConverterTest.emptyStructLiteral. The test reproduced the crash before the fix and passed after rebuilding the native library. It verifies that the converted constant has a zero-field ROW type and contains exactly one non-null row.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-6.2 Astra)