Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/acero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions cpp/src/arrow/acero/test_util_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,31 @@ Result<std::shared_ptr<Table>> MakeRandomTimeSeriesTable(
return Table::Make(schema, columns, num_rows);
}

Result<std::shared_ptr<Table>> RunEndEncodeTableColumns(
const Table& table, const std::vector<int>& column_indices) {
const int num_columns = table.num_columns();
std::vector<std::shared_ptr<ChunkedArray>> encoded_columns;
encoded_columns.reserve(num_columns);
std::vector<std::shared_ptr<Field>> 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
4 changes: 4 additions & 0 deletions cpp/src/arrow/acero/test_util_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -195,4 +196,7 @@ struct TableGenerationProperties {
Result<std::shared_ptr<Table>> MakeRandomTimeSeriesTable(
const TableGenerationProperties& properties);

Result<std::shared_ptr<Table>> RunEndEncodeTableColumns(
const Table& table, const std::vector<int>& column_indices);

} // namespace arrow::acero
39 changes: 39 additions & 0 deletions cpp/src/arrow/acero/test_util_internal_test.cc
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#include "arrow/acero/test_util_internal.h"
#include "arrow/testing/gtest_util.h"

namespace arrow::acero {

TEST(RunEndEncodeTableColumnsTest, SchemaTypeIsModified) {
std::shared_ptr<Table> 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<Table> ree_table,
RunEndEncodeTableColumns(*table, {0}));
Comment thread
raulcd marked this conversation as resolved.
Resolved
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
26 changes: 0 additions & 26 deletions cpp/src/arrow/testing/gtest_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -473,31 +472,6 @@ std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
return *Tensor::Make(type, array->data()->buffers[1], shape, strides, dim_names);
}

Result<std::shared_ptr<Table>> RunEndEncodeTableColumns(
const Table& table, const std::vector<int>& column_indices) {
const int num_columns = table.num_columns();
std::vector<std::shared_ptr<ChunkedArray>> encoded_columns;
encoded_columns.reserve(num_columns);
std::vector<std::shared_ptr<Field>> 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<std::optional<std::string>> PrintArrayDiff(const ChunkedArray& expected,
const ChunkedArray& actual) {
if (actual.Equals(expected)) {
Expand Down
4 changes: 0 additions & 4 deletions cpp/src/arrow/testing/gtest_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,6 @@ std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
const std::vector<int64_t>& strides = {},
const std::vector<std::string>& dim_names = {});

ARROW_TESTING_EXPORT
Result<std::shared_ptr<Table>> RunEndEncodeTableColumns(
const Table& table, const std::vector<int>& 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
Expand Down
13 changes: 0 additions & 13 deletions cpp/src/arrow/testing/gtest_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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<Table> ree_table,
RunEndEncodeTableColumns(*table, {0}));
ASSERT_TRUE(ree_table->schema()->field(0)->type()->Equals(
arrow::run_end_encoded(arrow::int32(), arrow::utf8())));
}
} // namespace arrow