diff --git a/cpp/src/arrow/acero/aggregate_node_test.cc b/cpp/src/arrow/acero/aggregate_node_test.cc index bb19f0fafed99..50a8c40f3f8e2 100644 --- a/cpp/src/arrow/acero/aggregate_node_test.cc +++ b/cpp/src/arrow/acero/aggregate_node_test.cc @@ -215,29 +215,43 @@ TEST(ScalarAggregateNode, AnyAll) { // when min_count != 0. std::shared_ptr in_schema = schema({field("not_used", int32())}); std::shared_ptr out_schema = schema({field("agg_out", boolean())}); - std::vector batches{ - ExecBatchFromJSON({int32()}, "[[42], [42], [42], [42]]")}; - for (auto& func_name : {"any", "all"}) { - SCOPED_TRACE(func_name); - std::vector aggregates = { - Aggregate(func_name, - std::make_shared(/*skip_nulls=*/false, - /*min_count=*/2), - FieldRef("literal_true"))}; - - // And a projection to make the input including a Scalar Boolean - Declaration plan = Declaration::Sequence( - {{"exec_batch_source", ExecBatchSourceNodeOptions(in_schema, batches)}, - {"project", ProjectNodeOptions({literal(true)}, {"literal_true"})}, - {"aggregate", AggregateNodeOptions(aggregates)}}); - - ASSERT_OK_AND_ASSIGN(BatchesWithCommonSchema out_batches, - DeclarationToExecBatches(plan)); - - ExecBatch expected_batch = ExecBatchFromJSON({boolean()}, "[[true]]"); - - AssertExecBatchesEqualIgnoringOrder(out_schema, {expected_batch}, - out_batches.batches); + struct AnyAllCase { + std::string batches_json; + Expression literal; + std::string expected_json; + }; + std::vector cases{ + {"[[42], [42], [42], [42]]", literal(true), "[[true]]"}, + {"[[42], [42], [42], [42]]", literal(false), "[[false]]"}, + {"[[42], [42], [42], [42]]", literal(BooleanScalar{}), "[[null]]"}, + {"[[42]]", literal(true), "[[null]]"}, + {"[[42], [42], [42]]", literal(true), "[[true]]"}, + }; + for (const AnyAllCase& any_all_case : cases) { + for (const std::string& func_name : {"any", "all"}) { + std::vector batches{ + ExecBatchFromJSON({int32()}, any_all_case.batches_json)}; + std::vector aggregates = {Aggregate( + "any", + std::make_shared(/*skip_nulls=*/false, + /*min_count=*/2), + FieldRef("literal"))}; + + // And a projection to make the input including a Scalar Boolean + Declaration plan = Declaration::Sequence( + {{"exec_batch_source", ExecBatchSourceNodeOptions(in_schema, batches)}, + {"project", ProjectNodeOptions({any_all_case.literal}, {"literal"})}, + {"aggregate", AggregateNodeOptions(aggregates)}}); + + ASSERT_OK_AND_ASSIGN(BatchesWithCommonSchema out_batches, + DeclarationToExecBatches(plan)); + + ExecBatch expected_batch = + ExecBatchFromJSON({boolean()}, any_all_case.expected_json); + + AssertExecBatchesEqualIgnoringOrder(out_schema, {expected_batch}, + out_batches.batches); + } } }