diff --git a/cpp/src/arrow/compute/kernels/aggregate_basic.cc b/cpp/src/arrow/compute/kernels/aggregate_basic.cc index 0512e17e21d29..31343a9c8f5fb 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_basic.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_basic.cc @@ -482,8 +482,8 @@ void AddFirstOrLastAggKernel(ScalarAggregateFunction* func, // ---------------------------------------------------------------------- // MinMax implementation -using arrow::compute::match::SameTypeId; using arrow::compute::match::Not; +using arrow::compute::match::SameTypeId; Result> MinMaxInit(KernelContext* ctx, const KernelInitArgs& args) { diff --git a/cpp/src/arrow/compute/kernels/aggregate_test.cc b/cpp/src/arrow/compute/kernels/aggregate_test.cc index dc1824031a927..1c52809d1d75d 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_test.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_test.cc @@ -2047,16 +2047,16 @@ TEST(TestDecimalMinMaxKernel, Decimals) { } } -TEST(TestDictionaryMinMaxKernel, DictionaryArray) { +TEST(TestDictionaryMinMaxKernel, DecimalValue) { ScalarAggregateOptions options; std::shared_ptr dict_ty; std::shared_ptr ty; for (const auto& index_type : all_dictionary_index_types()) { ARROW_SCOPED_TRACE("index_type = ", index_type->ToString()); - for (const auto& item_ty_ : {decimal128(5, 2), decimal256(5, 2)}) { - dict_ty = dictionary(index_type, item_ty_); - ty = struct_({field("min", item_ty_), field("max", item_ty_)}); + for (const auto& value_ty_ : {decimal128(5, 2), decimal256(5, 2)}) { + dict_ty = dictionary(index_type, value_ty_); + ty = struct_({field("min", value_ty_), field("max", value_ty_)}); options = ScalarAggregateOptions(/*skip_nulls=*/true); EXPECT_THAT( @@ -2133,19 +2133,19 @@ TEST(TestDictionaryMinMaxKernel, DictionaryArray) { options), ResultWith(ScalarFromJSON(ty, R"({"min": "-1.23", "max": "9.20"})"))); } + } +} - std::shared_ptr item_ty = null(); - dict_ty = dictionary(index_type, item_ty); - ty = struct_({field("min", item_ty), field("max", item_ty)}); - Datum result = ScalarFromJSON(ty, "[null, null]"); - EXPECT_THAT(MinMax(DictArrayFromJSON(dict_ty, R"([null, null])", R"([])"), options), - ResultWith(result)); - EXPECT_THAT(MinMax(DictArrayFromJSON(dict_ty, R"([])", R"([])"), options), - ResultWith(result)); +TEST(TestDictionaryMinMaxKernel, BooleanValue) { + ScalarAggregateOptions options; + std::shared_ptr value_ty = boolean(); + std::shared_ptr ty = + struct_({field("min", value_ty), field("max", value_ty)}); + std::shared_ptr dict_ty; + + for (const auto& index_type : all_dictionary_index_types()) { + ARROW_SCOPED_TRACE("index_type = ", index_type->ToString()); - item_ty = boolean(); - dict_ty = dictionary(index_type, item_ty); - ty = struct_({field("min", item_ty), field("max", item_ty)}); EXPECT_THAT( MinMax(DictArrayFromJSON(dict_ty, R"([0, 0, 1])", R"([false, true])"), options), ResultWith(ScalarFromJSON(ty, "[false, true]"))); @@ -2158,6 +2158,25 @@ TEST(TestDictionaryMinMaxKernel, DictionaryArray) { } } +TEST(TestDictionaryMinMaxKernel, NullValue) { + ScalarAggregateOptions options; + std::shared_ptr value_ty = null(); + std::shared_ptr ty = + struct_({field("min", value_ty), field("max", value_ty)}); + std::shared_ptr dict_ty; + + for (const auto& index_type : all_dictionary_index_types()) { + ARROW_SCOPED_TRACE("index_type = ", index_type->ToString()); + // null + dict_ty = dictionary(index_type, value_ty); + Datum result = ScalarFromJSON(ty, "[null, null]"); + EXPECT_THAT(MinMax(DictArrayFromJSON(dict_ty, R"([null, null])", R"([])"), options), + ResultWith(result)); + EXPECT_THAT(MinMax(DictArrayFromJSON(dict_ty, R"([])", R"([])"), options), + ResultWith(result)); + } +} + TEST(TestNullMinMaxKernel, Basics) { auto item_ty = null(); auto ty = struct_({field("min", item_ty), field("max", item_ty)});