Skip to content

Commit 56436e8

Browse files
mroz45zanmato1984
andauthored
GH-45564: [C++][Acero] Add size validation for names and expressions 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]>
1 parent 5ff10fd commit 56436e8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cpp/src/arrow/acero/plan_test.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,23 @@ TEST(ExecPlanExecution, SourceFilterProjectGroupedSumFilter) {
12661266
}
12671267
}
12681268

1269+
TEST(ExecPlanExecution, ProjectNamesSizeMismatch) {
1270+
auto input = MakeGroupableBatches();
1271+
1272+
Declaration plan = Declaration::Sequence(
1273+
{{"source", SourceNodeOptions{input.schema, input.gen(true, /*slow=*/false)}},
1274+
{"project", ProjectNodeOptions{
1275+
/*expressions=*/{field_ref("str"),
1276+
call("multiply", {field_ref("i32"), literal(2)})},
1277+
/*names=*/{"a"}}}}); // expected 2 names but only 1 provided
1278+
1279+
EXPECT_RAISES_WITH_MESSAGE_THAT(
1280+
Invalid,
1281+
::testing::HasSubstr(
1282+
"Project node's size of names 1 doesn't match size of expressions 2"),
1283+
DeclarationToTable(std::move(plan)));
1284+
}
1285+
12691286
TEST(ExecPlanExecution, SourceFilterProjectGroupedSumOrderBy) {
12701287
for (bool parallel : {false, true}) {
12711288
SCOPED_TRACE(parallel ? "parallel/merged" : "serial");

cpp/src/arrow/acero/project_node.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ class ProjectNode : public MapNode {
5959
for (size_t i = 0; i < exprs.size(); ++i) {
6060
names[i] = exprs[i].ToString();
6161
}
62+
} else {
63+
ARROW_RETURN_IF(
64+
names.size() != exprs.size(),
65+
Status::Invalid("Project node's size of names " + std::to_string(names.size()) +
66+
" doesn't match size of expressions " +
67+
std::to_string(exprs.size())));
6268
}
63-
6469
FieldVector fields(exprs.size());
6570
int i = 0;
6671
for (auto& expr : exprs) {

0 commit comments

Comments
 (0)