Skip to content

Commit

Permalink
GH-45564: [C++][Acero] Add size validation for names and expressions …
Browse files Browse the repository at this point in the history
…vectors in ProjectNode (#45565)

### What changes are included in this PR?
Added a check to validate that the sizes of the names and expressions vectors match in the ProjectNode class

### Are these changes tested?
Yes

### Are there any user-facing changes?
No

* GitHub Issue: #45564

Lead-authored-by: kamilt <[email protected]>
Co-authored-by: mroz45 <[email protected]>
Co-authored-by: Rossi Sun <[email protected]>
Signed-off-by: Rossi Sun <[email protected]>
  • Loading branch information
mroz45 and zanmato1984 authored Mar 11, 2025
1 parent 5ff10fd commit 56436e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cpp/src/arrow/acero/plan_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,23 @@ TEST(ExecPlanExecution, SourceFilterProjectGroupedSumFilter) {
}
}

TEST(ExecPlanExecution, ProjectNamesSizeMismatch) {
auto input = MakeGroupableBatches();

Declaration plan = Declaration::Sequence(
{{"source", SourceNodeOptions{input.schema, input.gen(true, /*slow=*/false)}},
{"project", ProjectNodeOptions{
/*expressions=*/{field_ref("str"),
call("multiply", {field_ref("i32"), literal(2)})},
/*names=*/{"a"}}}}); // expected 2 names but only 1 provided

EXPECT_RAISES_WITH_MESSAGE_THAT(
Invalid,
::testing::HasSubstr(
"Project node's size of names 1 doesn't match size of expressions 2"),
DeclarationToTable(std::move(plan)));
}

TEST(ExecPlanExecution, SourceFilterProjectGroupedSumOrderBy) {
for (bool parallel : {false, true}) {
SCOPED_TRACE(parallel ? "parallel/merged" : "serial");
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/arrow/acero/project_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ class ProjectNode : public MapNode {
for (size_t i = 0; i < exprs.size(); ++i) {
names[i] = exprs[i].ToString();
}
} else {
ARROW_RETURN_IF(
names.size() != exprs.size(),
Status::Invalid("Project node's size of names " + std::to_string(names.size()) +
" doesn't match size of expressions " +
std::to_string(exprs.size())));
}

FieldVector fields(exprs.size());
int i = 0;
for (auto& expr : exprs) {
Expand Down

0 comments on commit 56436e8

Please sign in to comment.