arashandishgar commented on code in PR #46031: URL: https://github.com/apache/arrow/pull/46031#discussion_r2030859974
########## cpp/src/arrow/record_batch_test.cc: ########## @@ -1424,33 +1471,86 @@ TEST_F(TestRecordBatch, MakeStatisticsArrayMaxApproximate) { } TEST_F(TestRecordBatch, MakeStatisticsArrayString) { - auto schema = - ::arrow::schema({field("no-statistics", boolean()), field("string", utf8())}); - auto no_statistics_array = ArrayFromJSON(boolean(), "[true, false, true]"); - auto string_array_data = ArrayFromJSON(utf8(), "[\"a\", null, \"c\"]")->data()->Copy(); - string_array_data->statistics = std::make_shared<ArrayStatistics>(); - string_array_data->statistics->is_max_exact = true; - string_array_data->statistics->max = "c"; - auto string_array = MakeArray(std::move(string_array_data)); - auto batch = RecordBatch::Make(schema, string_array->length(), - {no_statistics_array, string_array}); + auto CheckString = [](const std::shared_ptr<DataType>& type) { + auto schema = + ::arrow::schema({field("no-statistics", boolean()), field("string", type)}); + auto no_statistics_array = ArrayFromJSON(boolean(), "[true, false, true]"); + auto string_array_data = ArrayFromJSON(type, "[\"a\", null, \"c\"]")->data()->Copy(); + string_array_data->statistics = std::make_shared<ArrayStatistics>(); + string_array_data->statistics->is_max_exact = true; + string_array_data->statistics->max = "c"; + auto string_array = MakeArray(std::move(string_array_data)); + auto batch = RecordBatch::Make(schema, string_array->length(), + {no_statistics_array, string_array}); + + ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray()); + + ASSERT_OK_AND_ASSIGN(auto expected_statistics_array, + MakeStatisticsArray("[null, 1]", + {{ + ARROW_STATISTICS_KEY_ROW_COUNT_EXACT, + }, + { + ARROW_STATISTICS_KEY_MAX_VALUE_EXACT, + }}, + {{ + ArrayStatistics::ValueType{int64_t{3}}, + }, + { + ArrayStatistics::ValueType{"c"}, + }}, + {nullptr, type})); + AssertArraysEqual(*expected_statistics_array, *statistics_array, true); + }; + // Check each type + CheckString(binary()); + CheckString(utf8()); + CheckString(large_binary()); + CheckString(large_utf8()); + CheckString(binary_view()); + CheckString(utf8_view()); + CheckString(fixed_size_binary(1)); + + // Check the combination of various string types Review Comment: I think the above test is important for cases involving different types of fixed_size_binary. However, I forgot to handle this scenario, as shown in the following code ``` auto f0 = ArrayFromJSON(fixed_size_binary(1), R"(["a", "b", "c"])"); f0->data()->statistics = std::make_shared<ArrayStatistics>(); f0->data()->statistics->max = "c"; auto f1 = ArrayFromJSON(int64(), R"([1, 2, 3])"); auto f2 = ArrayFromJSON(fixed_size_binary(2), R"(["aa", "bb", "cc"])"); f2->data()->statistics = std::make_shared<ArrayStatistics>(); f2->data()->statistics->max = "cc"; auto schema = ::arrow::schema({field("f0", fixed_size_binary(1)), field("f1", int64()), field("f2", fixed_size_binary(2))}); auto batch = RecordBatch::Make(schema, f0->length(), {f0, f1, f2}); ASSERT_OK_AND_ASSIGN(auto statistics_array, batch->MakeStatisticsArray()); ``` print a message like ``` /home/arashandishgar/Desktop/arrow/cpp/src/arrow/array/builder_binary.cc:113: Check failed: (size) == (byte_width_) Appending wrong size to FixedSizeBinaryBuilder Process finished with exit code 134 (interrupted by signal 6:SIGABRT) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org