diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index 7bfdc332f14c..73112669b1de 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -801,6 +801,7 @@ 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) + 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/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/acero/test_util_internal_test.cc b/cpp/src/arrow/acero/test_util_internal_test.cc new file mode 100644 index 000000000000..7a42b9d172d9 --- /dev/null +++ b/cpp/src/arrow/acero/test_util_internal_test.cc @@ -0,0 +1,39 @@ +// 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/acero/test_util_internal.h" +#include "arrow/testing/gtest_util.h" + +namespace arrow::acero { + +TEST(RunEndEncodeTableColumnsTest, 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_OK(ree_table->ValidateFull()); + ASSERT_TRUE(ree_table->schema()->field(0)->type()->Equals( + arrow::run_end_encoded(arrow::int32(), arrow::utf8()))); +} +} // namespace arrow::acero 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