Skip to content

[VL] Preserve one row for empty struct literals - #13825

Open
boneanxs wants to merge 1 commit into
apache:mainfrom
boneanxs:test_empty_complex_vector
Open

boneanxs wants to merge 1 commit into
apache:mainfrom
boneanxs:test_empty_complex_vector

Conversation

@boneanxs

Copy link
Copy Markdown
Contributor

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)

Copilot AI balanced review requested due to automatic review settings November 27, 2026 07:50
@github-actions github-actions Bot added the VELOX label Nov 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants