From e97c952012d9355b87bbdaf451f26400c8eddb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Wed, 16 Apr 2025 12:49:24 +0200 Subject: [PATCH 1/5] GH-46157: [C++] Move test utility RunEndEncodeTableColumns that uses REE to test_util on compute instead of common gtest_util --- cpp/src/arrow/CMakeLists.txt | 2 + cpp/src/arrow/acero/hash_aggregate_test.cc | 6 ++- cpp/src/arrow/compute/kernels/CMakeLists.txt | 2 + cpp/src/arrow/compute/kernels/test_util.cc | 51 +++++++++++++++++++ cpp/src/arrow/compute/kernels/test_util.h | 30 +++++++++++ .../arrow/compute/kernels/test_util_test.cc | 38 ++++++++++++++ cpp/src/arrow/testing/gtest_util.cc | 26 ---------- cpp/src/arrow/testing/gtest_util.h | 4 -- cpp/src/arrow/testing/gtest_util_test.cc | 13 ----- 9 files changed, 127 insertions(+), 45 deletions(-) create mode 100644 cpp/src/arrow/compute/kernels/test_util.cc create mode 100644 cpp/src/arrow/compute/kernels/test_util.h create mode 100644 cpp/src/arrow/compute/kernels/test_util_test.cc diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index 7bfdc332f14c..79991da30ad1 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -801,6 +801,8 @@ if(ARROW_COMPUTE) append_runtime_avx2_src(ARROW_COMPUTE_SRCS compute/row/compare_internal_avx2.cc) append_runtime_avx2_src(ARROW_COMPUTE_SRCS compute/row/encode_internal_avx2.cc) append_runtime_avx2_bmi2_src(ARROW_COMPUTE_SRCS compute/util_avx2.cc) + + list(APPEND ARROW_TESTING_SRCS compute/kernels/test_util.cc) endif() arrow_add_object_library(ARROW_COMPUTE ${ARROW_COMPUTE_SRCS}) diff --git a/cpp/src/arrow/acero/hash_aggregate_test.cc b/cpp/src/arrow/acero/hash_aggregate_test.cc index dce0e44eb135..f02431271978 100644 --- a/cpp/src/arrow/acero/hash_aggregate_test.cc +++ b/cpp/src/arrow/acero/hash_aggregate_test.cc @@ -39,6 +39,7 @@ #include "arrow/compute/cast.h" #include "arrow/compute/exec.h" #include "arrow/compute/exec_internal.h" +#include "arrow/compute/kernels/test_util.h" #include "arrow/compute/registry.h" #include "arrow/compute/row/grouper.h" #include "arrow/table.h" @@ -773,8 +774,9 @@ TEST_P(GroupBy, CountOnly) { auto transformed_table = table; if (!re_encode_cols.empty()) { - ASSERT_OK_AND_ASSIGN(transformed_table, - RunEndEncodeTableColumns(*table, re_encode_cols)); + ASSERT_OK_AND_ASSIGN( + transformed_table, + arrow::compute::RunEndEncodeTableColumns(*table, re_encode_cols)); } ASSERT_OK_AND_ASSIGN(Datum aggregated_and_grouped, diff --git a/cpp/src/arrow/compute/kernels/CMakeLists.txt b/cpp/src/arrow/compute/kernels/CMakeLists.txt index 81b7adeb4aa6..a3afb5705449 100644 --- a/cpp/src/arrow/compute/kernels/CMakeLists.txt +++ b/cpp/src/arrow/compute/kernels/CMakeLists.txt @@ -34,6 +34,8 @@ add_arrow_test(scalar_cast_test arrow_compute_kernels_testing arrow_compute_testing) +add_arrow_compute_test(test_util_test SOURCES test_util_test.cc) + # ---------------------------------------------------------------------- # Scalar kernels diff --git a/cpp/src/arrow/compute/kernels/test_util.cc b/cpp/src/arrow/compute/kernels/test_util.cc new file mode 100644 index 000000000000..1b50de4a780d --- /dev/null +++ b/cpp/src/arrow/compute/kernels/test_util.cc @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/compute/kernels/test_util.h" + +#include "arrow/compute/api_vector.h" +#include "arrow/datum.h" +#include "arrow/util/logging.h" + +namespace arrow::compute { + +Result> RunEndEncodeTableColumns( + const Table& table, const std::vector& column_indices) { + const int num_columns = table.num_columns(); + std::vector> encoded_columns; + encoded_columns.reserve(num_columns); + std::vector> encoded_fields; + encoded_fields.reserve(num_columns); + for (int i = 0; i < num_columns; i++) { + const auto& field = table.schema()->field(i); + if (std::find(column_indices.begin(), column_indices.end(), i) != + column_indices.end()) { + ARROW_ASSIGN_OR_RAISE(auto run_end_encoded, RunEndEncode(table.column(i))); + ARROW_DCHECK_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY); + encoded_columns.push_back(run_end_encoded.chunked_array()); + auto encoded_type = arrow::run_end_encoded(arrow::int32(), field->type()); + encoded_fields.push_back(field->WithType(encoded_type)); + } else { + encoded_columns.push_back(table.column(i)); + encoded_fields.push_back(field); + } + } + auto updated_schema = arrow::schema(std::move(encoded_fields)); + return Table::Make(std::move(updated_schema), std::move(encoded_columns)); +} + +} // namespace arrow::compute diff --git a/cpp/src/arrow/compute/kernels/test_util.h b/cpp/src/arrow/compute/kernels/test_util.h new file mode 100644 index 000000000000..8cd45004977f --- /dev/null +++ b/cpp/src/arrow/compute/kernels/test_util.h @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include "arrow/result.h" +#include "arrow/table.h" +#include "arrow/testing/visibility.h" + +namespace arrow::compute { + +ARROW_TESTING_EXPORT +Result> RunEndEncodeTableColumns( + const Table& table, const std::vector& column_indices); + +} // namespace arrow::compute diff --git a/cpp/src/arrow/compute/kernels/test_util_test.cc b/cpp/src/arrow/compute/kernels/test_util_test.cc new file mode 100644 index 000000000000..81e9c413b81f --- /dev/null +++ b/cpp/src/arrow/compute/kernels/test_util_test.cc @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include + +#include "arrow/compute/kernels/test_util.h" +#include "arrow/testing/gtest_util.h" + +namespace arrow::compute { + +TEST(RunEndEncodeGtestUtilTest, SchemaTypeIsModified) { + std::shared_ptr table = + arrow::TableFromJSON(arrow::schema({arrow::field("col", arrow::utf8())}), {R"([ + {"col": "a"}, + {"col": "b"}, + {"col": "c"}, + {"col": "d"} + ])"}); + ASSERT_OK_AND_ASSIGN(std::shared_ptr
ree_table, + RunEndEncodeTableColumns(*table, {0})); + ASSERT_TRUE(ree_table->schema()->field(0)->type()->Equals( + arrow::run_end_encoded(arrow::int32(), arrow::utf8()))); +} +} // namespace arrow::compute diff --git a/cpp/src/arrow/testing/gtest_util.cc b/cpp/src/arrow/testing/gtest_util.cc index 9eeca32e721e..061956ab1a03 100644 --- a/cpp/src/arrow/testing/gtest_util.cc +++ b/cpp/src/arrow/testing/gtest_util.cc @@ -47,7 +47,6 @@ #include "arrow/array.h" #include "arrow/buffer.h" -#include "arrow/compute/api_vector.h" #include "arrow/datum.h" #include "arrow/extension/json.h" #include "arrow/io/memory.h" @@ -473,31 +472,6 @@ std::shared_ptr TensorFromJSON(const std::shared_ptr& type, return *Tensor::Make(type, array->data()->buffers[1], shape, strides, dim_names); } -Result> RunEndEncodeTableColumns( - const Table& table, const std::vector& column_indices) { - const int num_columns = table.num_columns(); - std::vector> encoded_columns; - encoded_columns.reserve(num_columns); - std::vector> encoded_fields; - encoded_fields.reserve(num_columns); - for (int i = 0; i < num_columns; i++) { - const auto& field = table.schema()->field(i); - if (std::find(column_indices.begin(), column_indices.end(), i) != - column_indices.end()) { - ARROW_ASSIGN_OR_RAISE(auto run_end_encoded, compute::RunEndEncode(table.column(i))); - DCHECK_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY); - encoded_columns.push_back(run_end_encoded.chunked_array()); - auto encoded_type = arrow::run_end_encoded(arrow::int32(), field->type()); - encoded_fields.push_back(field->WithType(encoded_type)); - } else { - encoded_columns.push_back(table.column(i)); - encoded_fields.push_back(field); - } - } - auto updated_schema = arrow::schema(std::move(encoded_fields)); - return Table::Make(std::move(updated_schema), std::move(encoded_columns)); -} - Result> PrintArrayDiff(const ChunkedArray& expected, const ChunkedArray& actual) { if (actual.Equals(expected)) { diff --git a/cpp/src/arrow/testing/gtest_util.h b/cpp/src/arrow/testing/gtest_util.h index 89a986097f87..67fe1f43547a 100644 --- a/cpp/src/arrow/testing/gtest_util.h +++ b/cpp/src/arrow/testing/gtest_util.h @@ -370,10 +370,6 @@ std::shared_ptr TensorFromJSON(const std::shared_ptr& type, const std::vector& strides = {}, const std::vector& dim_names = {}); -ARROW_TESTING_EXPORT -Result> RunEndEncodeTableColumns( - const Table& table, const std::vector& column_indices); - // Given an array, return a new identical array except for one validity bit // set to a new value. // This is useful to force the underlying "value" of null entries to otherwise diff --git a/cpp/src/arrow/testing/gtest_util_test.cc b/cpp/src/arrow/testing/gtest_util_test.cc index 8dc496fa500c..4ad5159a6b1e 100644 --- a/cpp/src/arrow/testing/gtest_util_test.cc +++ b/cpp/src/arrow/testing/gtest_util_test.cc @@ -292,17 +292,4 @@ TEST(AssertTestWithinUlp, Basics) { EXPECT_FATAL_FAILURE(AssertWithinUlp(123.456f, 123.456085f, 10), "not within 10 ulps"); } -TEST(RunEndEncodeGtestUtilTest, SchemaTypeIsModified) { - std::shared_ptr
table = - arrow::TableFromJSON(arrow::schema({arrow::field("col", arrow::utf8())}), {R"([ - {"col": "a"}, - {"col": "b"}, - {"col": "c"}, - {"col": "d"} - ])"}); - ASSERT_OK_AND_ASSIGN(std::shared_ptr
ree_table, - RunEndEncodeTableColumns(*table, {0})); - ASSERT_TRUE(ree_table->schema()->field(0)->type()->Equals( - arrow::run_end_encoded(arrow::int32(), arrow::utf8()))); -} } // namespace arrow From 6ee47f2c648566cdb6cc1c3527eafc036448c201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Wed, 23 Apr 2025 10:40:27 +0200 Subject: [PATCH 2/5] Move test to test_util_internal instead of test_util --- cpp/src/arrow/CMakeLists.txt | 3 +- cpp/src/arrow/acero/hash_aggregate_test.cc | 2 +- cpp/src/arrow/compute/kernels/CMakeLists.txt | 2 +- cpp/src/arrow/compute/kernels/test_util.cc | 51 ------------------- cpp/src/arrow/compute/kernels/test_util.h | 30 ----------- .../compute/kernels/test_util_internal.cc | 27 ++++++++++ .../compute/kernels/test_util_internal.h | 7 +++ ...til_test.cc => test_util_internal_test.cc} | 4 +- 8 files changed, 40 insertions(+), 86 deletions(-) delete mode 100644 cpp/src/arrow/compute/kernels/test_util.cc delete mode 100644 cpp/src/arrow/compute/kernels/test_util.h rename cpp/src/arrow/compute/kernels/{test_util_test.cc => test_util_internal_test.cc} (92%) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index 79991da30ad1..3537b154c37e 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -802,7 +802,8 @@ if(ARROW_COMPUTE) append_runtime_avx2_src(ARROW_COMPUTE_SRCS compute/row/encode_internal_avx2.cc) append_runtime_avx2_bmi2_src(ARROW_COMPUTE_SRCS compute/util_avx2.cc) - list(APPEND ARROW_TESTING_SRCS compute/kernels/test_util.cc) + list(APPEND ARROW_TESTING_SRCS compute/kernels/test_util_internal.cc + compute/test_util_internal.cc) endif() arrow_add_object_library(ARROW_COMPUTE ${ARROW_COMPUTE_SRCS}) diff --git a/cpp/src/arrow/acero/hash_aggregate_test.cc b/cpp/src/arrow/acero/hash_aggregate_test.cc index f02431271978..ba751d3d6c91 100644 --- a/cpp/src/arrow/acero/hash_aggregate_test.cc +++ b/cpp/src/arrow/acero/hash_aggregate_test.cc @@ -39,7 +39,7 @@ #include "arrow/compute/cast.h" #include "arrow/compute/exec.h" #include "arrow/compute/exec_internal.h" -#include "arrow/compute/kernels/test_util.h" +#include "arrow/compute/kernels/test_util_internal.h" #include "arrow/compute/registry.h" #include "arrow/compute/row/grouper.h" #include "arrow/table.h" diff --git a/cpp/src/arrow/compute/kernels/CMakeLists.txt b/cpp/src/arrow/compute/kernels/CMakeLists.txt index a3afb5705449..4c236be272c7 100644 --- a/cpp/src/arrow/compute/kernels/CMakeLists.txt +++ b/cpp/src/arrow/compute/kernels/CMakeLists.txt @@ -34,7 +34,7 @@ add_arrow_test(scalar_cast_test arrow_compute_kernels_testing arrow_compute_testing) -add_arrow_compute_test(test_util_test SOURCES test_util_test.cc) +add_arrow_compute_test(test_util_internal_test SOURCES test_util_internal_test.cc) # ---------------------------------------------------------------------- # Scalar kernels diff --git a/cpp/src/arrow/compute/kernels/test_util.cc b/cpp/src/arrow/compute/kernels/test_util.cc deleted file mode 100644 index 1b50de4a780d..000000000000 --- a/cpp/src/arrow/compute/kernels/test_util.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include "arrow/compute/kernels/test_util.h" - -#include "arrow/compute/api_vector.h" -#include "arrow/datum.h" -#include "arrow/util/logging.h" - -namespace arrow::compute { - -Result> RunEndEncodeTableColumns( - const Table& table, const std::vector& column_indices) { - const int num_columns = table.num_columns(); - std::vector> encoded_columns; - encoded_columns.reserve(num_columns); - std::vector> encoded_fields; - encoded_fields.reserve(num_columns); - for (int i = 0; i < num_columns; i++) { - const auto& field = table.schema()->field(i); - if (std::find(column_indices.begin(), column_indices.end(), i) != - column_indices.end()) { - ARROW_ASSIGN_OR_RAISE(auto run_end_encoded, RunEndEncode(table.column(i))); - ARROW_DCHECK_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY); - encoded_columns.push_back(run_end_encoded.chunked_array()); - auto encoded_type = arrow::run_end_encoded(arrow::int32(), field->type()); - encoded_fields.push_back(field->WithType(encoded_type)); - } else { - encoded_columns.push_back(table.column(i)); - encoded_fields.push_back(field); - } - } - auto updated_schema = arrow::schema(std::move(encoded_fields)); - return Table::Make(std::move(updated_schema), std::move(encoded_columns)); -} - -} // namespace arrow::compute diff --git a/cpp/src/arrow/compute/kernels/test_util.h b/cpp/src/arrow/compute/kernels/test_util.h deleted file mode 100644 index 8cd45004977f..000000000000 --- a/cpp/src/arrow/compute/kernels/test_util.h +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#pragma once - -#include "arrow/result.h" -#include "arrow/table.h" -#include "arrow/testing/visibility.h" - -namespace arrow::compute { - -ARROW_TESTING_EXPORT -Result> RunEndEncodeTableColumns( - const Table& table, const std::vector& column_indices); - -} // namespace arrow::compute diff --git a/cpp/src/arrow/compute/kernels/test_util_internal.cc b/cpp/src/arrow/compute/kernels/test_util_internal.cc index d48b3b0781e7..674eab612220 100644 --- a/cpp/src/arrow/compute/kernels/test_util_internal.cc +++ b/cpp/src/arrow/compute/kernels/test_util_internal.cc @@ -24,6 +24,7 @@ #include "arrow/array.h" #include "arrow/array/validate.h" #include "arrow/chunked_array.h" +#include "arrow/compute/api_vector.h" #include "arrow/compute/cast.h" #include "arrow/compute/exec.h" #include "arrow/compute/function.h" @@ -33,6 +34,7 @@ #include "arrow/table.h" #include "arrow/testing/fixed_width_test_util.h" #include "arrow/testing/gtest_util.h" +#include "arrow/util/logging.h" namespace arrow { namespace compute { @@ -308,5 +310,30 @@ void CheckDispatchFails(std::string func_name, std::vector types) { ASSERT_NOT_OK(function->DispatchExact(types)); } +Result> RunEndEncodeTableColumns( + const Table& table, const std::vector& column_indices) { + const int num_columns = table.num_columns(); + std::vector> encoded_columns; + encoded_columns.reserve(num_columns); + std::vector> encoded_fields; + encoded_fields.reserve(num_columns); + for (int i = 0; i < num_columns; i++) { + const auto& field = table.schema()->field(i); + if (std::find(column_indices.begin(), column_indices.end(), i) != + column_indices.end()) { + ARROW_ASSIGN_OR_RAISE(auto run_end_encoded, RunEndEncode(table.column(i))); + ARROW_DCHECK_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY); + encoded_columns.push_back(run_end_encoded.chunked_array()); + auto encoded_type = arrow::run_end_encoded(arrow::int32(), field->type()); + encoded_fields.push_back(field->WithType(encoded_type)); + } else { + encoded_columns.push_back(table.column(i)); + encoded_fields.push_back(field); + } + } + auto updated_schema = arrow::schema(std::move(encoded_fields)); + return Table::Make(std::move(updated_schema), std::move(encoded_columns)); +} + } // namespace compute } // namespace arrow diff --git a/cpp/src/arrow/compute/kernels/test_util_internal.h b/cpp/src/arrow/compute/kernels/test_util_internal.h index e3a27ab9addb..88c856a5fd36 100644 --- a/cpp/src/arrow/compute/kernels/test_util_internal.h +++ b/cpp/src/arrow/compute/kernels/test_util_internal.h @@ -33,10 +33,13 @@ #include "arrow/datum.h" #include "arrow/memory_pool.h" #include "arrow/pretty_print.h" +#include "arrow/result.h" +#include "arrow/table.h" #include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" +#include "arrow/testing/visibility.h" #include "arrow/type.h" #include "arrow/util/checked_cast.h" @@ -267,5 +270,9 @@ class RandomRange : public RandomImpl { } }; +ARROW_TESTING_EXPORT +Result> RunEndEncodeTableColumns( + const Table& table, const std::vector& column_indices); + } // namespace compute } // namespace arrow diff --git a/cpp/src/arrow/compute/kernels/test_util_test.cc b/cpp/src/arrow/compute/kernels/test_util_internal_test.cc similarity index 92% rename from cpp/src/arrow/compute/kernels/test_util_test.cc rename to cpp/src/arrow/compute/kernels/test_util_internal_test.cc index 81e9c413b81f..9f798460489c 100644 --- a/cpp/src/arrow/compute/kernels/test_util_test.cc +++ b/cpp/src/arrow/compute/kernels/test_util_internal_test.cc @@ -17,12 +17,12 @@ #include -#include "arrow/compute/kernels/test_util.h" +#include "arrow/compute/kernels/test_util_internal.h" #include "arrow/testing/gtest_util.h" namespace arrow::compute { -TEST(RunEndEncodeGtestUtilTest, SchemaTypeIsModified) { +TEST(RunEndEncodeTableColumnsTest, SchemaTypeIsModified) { std::shared_ptr
table = arrow::TableFromJSON(arrow::schema({arrow::field("col", arrow::utf8())}), {R"([ {"col": "a"}, From 72fc9cfc6200743fff1bd3e794a7247ea900a0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Wed, 23 Apr 2025 11:38:34 +0200 Subject: [PATCH 3/5] Move utility test to acero and avoid ARROW_EXPORT as it is the only place is used --- cpp/src/arrow/CMakeLists.txt | 2 -- cpp/src/arrow/acero/CMakeLists.txt | 2 ++ cpp/src/arrow/acero/hash_aggregate_test.cc | 6 ++--- cpp/src/arrow/acero/test_util_internal.cc | 26 ++++++++++++++++++ cpp/src/arrow/acero/test_util_internal.h | 4 +++ .../test_util_internal_test.cc | 6 ++--- cpp/src/arrow/compute/kernels/CMakeLists.txt | 2 -- .../compute/kernels/test_util_internal.cc | 27 ------------------- .../compute/kernels/test_util_internal.h | 7 ----- 9 files changed, 37 insertions(+), 45 deletions(-) rename cpp/src/arrow/{compute/kernels => acero}/test_util_internal_test.cc (92%) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index 3537b154c37e..73112669b1de 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -802,8 +802,6 @@ if(ARROW_COMPUTE) append_runtime_avx2_src(ARROW_COMPUTE_SRCS compute/row/encode_internal_avx2.cc) append_runtime_avx2_bmi2_src(ARROW_COMPUTE_SRCS compute/util_avx2.cc) - list(APPEND ARROW_TESTING_SRCS compute/kernels/test_util_internal.cc - compute/test_util_internal.cc) endif() arrow_add_object_library(ARROW_COMPUTE ${ARROW_COMPUTE_SRCS}) diff --git a/cpp/src/arrow/acero/CMakeLists.txt b/cpp/src/arrow/acero/CMakeLists.txt index 5708d71737c6..dd08f96c3695 100644 --- a/cpp/src/arrow/acero/CMakeLists.txt +++ b/cpp/src/arrow/acero/CMakeLists.txt @@ -183,6 +183,8 @@ add_arrow_acero_test(aggregate_node_test SOURCES aggregate_node_test.cc) add_arrow_acero_test(util_test SOURCES util_test.cc task_util_test.cc) add_arrow_acero_test(hash_aggregate_test SOURCES hash_aggregate_test.cc) +add_arrow_acero_test(test_util_internal_test SOURCES test_util_internal_test.cc) + if(ARROW_BUILD_BENCHMARKS) function(add_arrow_acero_benchmark REL_BENCHMARK_NAME) set(options) diff --git a/cpp/src/arrow/acero/hash_aggregate_test.cc b/cpp/src/arrow/acero/hash_aggregate_test.cc index ba751d3d6c91..ce3eb1d3e88d 100644 --- a/cpp/src/arrow/acero/hash_aggregate_test.cc +++ b/cpp/src/arrow/acero/hash_aggregate_test.cc @@ -39,7 +39,6 @@ #include "arrow/compute/cast.h" #include "arrow/compute/exec.h" #include "arrow/compute/exec_internal.h" -#include "arrow/compute/kernels/test_util_internal.h" #include "arrow/compute/registry.h" #include "arrow/compute/row/grouper.h" #include "arrow/table.h" @@ -774,9 +773,8 @@ TEST_P(GroupBy, CountOnly) { auto transformed_table = table; if (!re_encode_cols.empty()) { - ASSERT_OK_AND_ASSIGN( - transformed_table, - arrow::compute::RunEndEncodeTableColumns(*table, re_encode_cols)); + ASSERT_OK_AND_ASSIGN(transformed_table, arrow::acero::RunEndEncodeTableColumns( + *table, re_encode_cols)); } ASSERT_OK_AND_ASSIGN(Datum aggregated_and_grouped, diff --git a/cpp/src/arrow/acero/test_util_internal.cc b/cpp/src/arrow/acero/test_util_internal.cc index 2748d4107ed3..3e2791758104 100644 --- a/cpp/src/arrow/acero/test_util_internal.cc +++ b/cpp/src/arrow/acero/test_util_internal.cc @@ -613,5 +613,31 @@ Result> MakeRandomTimeSeriesTable( return Table::Make(schema, columns, num_rows); } +Result> RunEndEncodeTableColumns( + const Table& table, const std::vector& column_indices) { + const int num_columns = table.num_columns(); + std::vector> encoded_columns; + encoded_columns.reserve(num_columns); + std::vector> encoded_fields; + encoded_fields.reserve(num_columns); + for (int i = 0; i < num_columns; i++) { + const auto& field = table.schema()->field(i); + if (std::find(column_indices.begin(), column_indices.end(), i) != + column_indices.end()) { + ARROW_ASSIGN_OR_RAISE(auto run_end_encoded, + arrow::compute::RunEndEncode(table.column(i))); + ARROW_DCHECK_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY); + encoded_columns.push_back(run_end_encoded.chunked_array()); + auto encoded_type = arrow::run_end_encoded(arrow::int32(), field->type()); + encoded_fields.push_back(field->WithType(encoded_type)); + } else { + encoded_columns.push_back(table.column(i)); + encoded_fields.push_back(field); + } + } + auto updated_schema = arrow::schema(std::move(encoded_fields)); + return Table::Make(std::move(updated_schema), std::move(encoded_columns)); +} + } // namespace acero } // namespace arrow diff --git a/cpp/src/arrow/acero/test_util_internal.h b/cpp/src/arrow/acero/test_util_internal.h index 2367524a5600..5fab9bfcd4f3 100644 --- a/cpp/src/arrow/acero/test_util_internal.h +++ b/cpp/src/arrow/acero/test_util_internal.h @@ -30,6 +30,7 @@ #include "arrow/acero/exec_plan.h" #include "arrow/compute/exec.h" #include "arrow/compute/kernel.h" +#include "arrow/table.h" #include "arrow/testing/visibility.h" #include "arrow/util/async_generator.h" #include "arrow/util/pcg_random.h" @@ -195,4 +196,7 @@ struct TableGenerationProperties { Result> MakeRandomTimeSeriesTable( const TableGenerationProperties& properties); +Result> RunEndEncodeTableColumns( + const Table& table, const std::vector& column_indices); + } // namespace arrow::acero diff --git a/cpp/src/arrow/compute/kernels/test_util_internal_test.cc b/cpp/src/arrow/acero/test_util_internal_test.cc similarity index 92% rename from cpp/src/arrow/compute/kernels/test_util_internal_test.cc rename to cpp/src/arrow/acero/test_util_internal_test.cc index 9f798460489c..b973983cdc00 100644 --- a/cpp/src/arrow/compute/kernels/test_util_internal_test.cc +++ b/cpp/src/arrow/acero/test_util_internal_test.cc @@ -17,10 +17,10 @@ #include -#include "arrow/compute/kernels/test_util_internal.h" +#include "arrow/acero/test_util_internal.h" #include "arrow/testing/gtest_util.h" -namespace arrow::compute { +namespace arrow::acero { TEST(RunEndEncodeTableColumnsTest, SchemaTypeIsModified) { std::shared_ptr
table = @@ -35,4 +35,4 @@ TEST(RunEndEncodeTableColumnsTest, SchemaTypeIsModified) { ASSERT_TRUE(ree_table->schema()->field(0)->type()->Equals( arrow::run_end_encoded(arrow::int32(), arrow::utf8()))); } -} // namespace arrow::compute +} // namespace arrow::acero diff --git a/cpp/src/arrow/compute/kernels/CMakeLists.txt b/cpp/src/arrow/compute/kernels/CMakeLists.txt index 4c236be272c7..81b7adeb4aa6 100644 --- a/cpp/src/arrow/compute/kernels/CMakeLists.txt +++ b/cpp/src/arrow/compute/kernels/CMakeLists.txt @@ -34,8 +34,6 @@ add_arrow_test(scalar_cast_test arrow_compute_kernels_testing arrow_compute_testing) -add_arrow_compute_test(test_util_internal_test SOURCES test_util_internal_test.cc) - # ---------------------------------------------------------------------- # Scalar kernels diff --git a/cpp/src/arrow/compute/kernels/test_util_internal.cc b/cpp/src/arrow/compute/kernels/test_util_internal.cc index 674eab612220..d48b3b0781e7 100644 --- a/cpp/src/arrow/compute/kernels/test_util_internal.cc +++ b/cpp/src/arrow/compute/kernels/test_util_internal.cc @@ -24,7 +24,6 @@ #include "arrow/array.h" #include "arrow/array/validate.h" #include "arrow/chunked_array.h" -#include "arrow/compute/api_vector.h" #include "arrow/compute/cast.h" #include "arrow/compute/exec.h" #include "arrow/compute/function.h" @@ -34,7 +33,6 @@ #include "arrow/table.h" #include "arrow/testing/fixed_width_test_util.h" #include "arrow/testing/gtest_util.h" -#include "arrow/util/logging.h" namespace arrow { namespace compute { @@ -310,30 +308,5 @@ void CheckDispatchFails(std::string func_name, std::vector types) { ASSERT_NOT_OK(function->DispatchExact(types)); } -Result> RunEndEncodeTableColumns( - const Table& table, const std::vector& column_indices) { - const int num_columns = table.num_columns(); - std::vector> encoded_columns; - encoded_columns.reserve(num_columns); - std::vector> encoded_fields; - encoded_fields.reserve(num_columns); - for (int i = 0; i < num_columns; i++) { - const auto& field = table.schema()->field(i); - if (std::find(column_indices.begin(), column_indices.end(), i) != - column_indices.end()) { - ARROW_ASSIGN_OR_RAISE(auto run_end_encoded, RunEndEncode(table.column(i))); - ARROW_DCHECK_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY); - encoded_columns.push_back(run_end_encoded.chunked_array()); - auto encoded_type = arrow::run_end_encoded(arrow::int32(), field->type()); - encoded_fields.push_back(field->WithType(encoded_type)); - } else { - encoded_columns.push_back(table.column(i)); - encoded_fields.push_back(field); - } - } - auto updated_schema = arrow::schema(std::move(encoded_fields)); - return Table::Make(std::move(updated_schema), std::move(encoded_columns)); -} - } // namespace compute } // namespace arrow diff --git a/cpp/src/arrow/compute/kernels/test_util_internal.h b/cpp/src/arrow/compute/kernels/test_util_internal.h index 88c856a5fd36..e3a27ab9addb 100644 --- a/cpp/src/arrow/compute/kernels/test_util_internal.h +++ b/cpp/src/arrow/compute/kernels/test_util_internal.h @@ -33,13 +33,10 @@ #include "arrow/datum.h" #include "arrow/memory_pool.h" #include "arrow/pretty_print.h" -#include "arrow/result.h" -#include "arrow/table.h" #include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" -#include "arrow/testing/visibility.h" #include "arrow/type.h" #include "arrow/util/checked_cast.h" @@ -270,9 +267,5 @@ class RandomRange : public RandomImpl { } }; -ARROW_TESTING_EXPORT -Result> RunEndEncodeTableColumns( - const Table& table, const std::vector& column_indices); - } // namespace compute } // namespace arrow From 855c938a88cfe9bfc86ef39d57b38791f063fb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Tue, 29 Apr 2025 11:21:38 +0200 Subject: [PATCH 4/5] Remove unnecessary namespace --- cpp/src/arrow/acero/hash_aggregate_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/acero/hash_aggregate_test.cc b/cpp/src/arrow/acero/hash_aggregate_test.cc index ce3eb1d3e88d..dce0e44eb135 100644 --- a/cpp/src/arrow/acero/hash_aggregate_test.cc +++ b/cpp/src/arrow/acero/hash_aggregate_test.cc @@ -773,8 +773,8 @@ TEST_P(GroupBy, CountOnly) { auto transformed_table = table; if (!re_encode_cols.empty()) { - ASSERT_OK_AND_ASSIGN(transformed_table, arrow::acero::RunEndEncodeTableColumns( - *table, re_encode_cols)); + ASSERT_OK_AND_ASSIGN(transformed_table, + RunEndEncodeTableColumns(*table, re_encode_cols)); } ASSERT_OK_AND_ASSIGN(Datum aggregated_and_grouped, From e055048bb8bbfbecf35eb83f0578cd1dadbfeeaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Tue, 29 Apr 2025 11:22:27 +0200 Subject: [PATCH 5/5] Update cpp/src/arrow/acero/test_util_internal_test.cc Co-authored-by: Antoine Pitrou --- cpp/src/arrow/acero/test_util_internal_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/src/arrow/acero/test_util_internal_test.cc b/cpp/src/arrow/acero/test_util_internal_test.cc index b973983cdc00..7a42b9d172d9 100644 --- a/cpp/src/arrow/acero/test_util_internal_test.cc +++ b/cpp/src/arrow/acero/test_util_internal_test.cc @@ -32,6 +32,7 @@ TEST(RunEndEncodeTableColumnsTest, SchemaTypeIsModified) { ])"}); ASSERT_OK_AND_ASSIGN(std::shared_ptr
ree_table, RunEndEncodeTableColumns(*table, {0})); + ASSERT_OK(ree_table->ValidateFull()); ASSERT_TRUE(ree_table->schema()->field(0)->type()->Equals( arrow::run_end_encoded(arrow::int32(), arrow::utf8()))); }