Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
R-JunmingChen committed Oct 15, 2023
1 parent 7c2ebe0 commit bc5a647
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/aggregate_basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<KernelState>> MinMaxInit(KernelContext* ctx,
const KernelInitArgs& args) {
Expand Down
49 changes: 34 additions & 15 deletions cpp/src/arrow/compute/kernels/aggregate_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2047,16 +2047,16 @@ TEST(TestDecimalMinMaxKernel, Decimals) {
}
}

TEST(TestDictionaryMinMaxKernel, DictionaryArray) {
TEST(TestDictionaryMinMaxKernel, DecimalValue) {
ScalarAggregateOptions options;
std::shared_ptr<arrow::DataType> dict_ty;
std::shared_ptr<arrow::DataType> 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(
Expand Down Expand Up @@ -2133,19 +2133,19 @@ TEST(TestDictionaryMinMaxKernel, DictionaryArray) {
options),
ResultWith(ScalarFromJSON(ty, R"({"min": "-1.23", "max": "9.20"})")));
}
}
}

std::shared_ptr<arrow::DataType> 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<arrow::DataType> value_ty = boolean();
std::shared_ptr<arrow::DataType> ty =
struct_({field("min", value_ty), field("max", value_ty)});
std::shared_ptr<arrow::DataType> 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]")));
Expand All @@ -2158,6 +2158,25 @@ TEST(TestDictionaryMinMaxKernel, DictionaryArray) {
}
}

TEST(TestDictionaryMinMaxKernel, NullValue) {
ScalarAggregateOptions options;
std::shared_ptr<arrow::DataType> value_ty = null();
std::shared_ptr<arrow::DataType> ty =
struct_({field("min", value_ty), field("max", value_ty)});
std::shared_ptr<arrow::DataType> 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)});
Expand Down

0 comments on commit bc5a647

Please sign in to comment.