From 91e3ac53e2e21736ce6291d73fc37da6fa21259d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 3 Jan 2022 23:53:44 +0100 Subject: [PATCH] ARROW-9483: [C++] Reorganize testing headers * Include less headers transitively from `gtest_util.h`. * Remove `gtest_common.h`, use `RandomArrayGenerator` instead. * Split `visitor_inline.h` into several topic-specific headers Closes #12065 from pitrou/ARROW-9483 Authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- cpp/src/arrow/adapters/orc/adapter_util.cc | 3 +- cpp/src/arrow/array/array_base.cc | 2 +- cpp/src/arrow/array/array_binary_test.cc | 13 +- cpp/src/arrow/array/array_dict.cc | 2 +- cpp/src/arrow/array/array_dict_test.cc | 6 +- cpp/src/arrow/array/array_list_test.cc | 23 +- cpp/src/arrow/array/array_struct_test.cc | 8 +- cpp/src/arrow/array/array_test.cc | 10 +- cpp/src/arrow/array/array_union_test.cc | 1 + cpp/src/arrow/array/builder_base.cc | 2 +- cpp/src/arrow/array/builder_dict.cc | 2 +- cpp/src/arrow/array/builder_dict.h | 2 +- cpp/src/arrow/array/concatenate.cc | 4 +- cpp/src/arrow/array/concatenate_test.cc | 2 +- cpp/src/arrow/array/dict_internal.h | 1 - cpp/src/arrow/array/diff.cc | 2 +- cpp/src/arrow/array/diff_test.cc | 2 +- cpp/src/arrow/array/util.cc | 6 +- cpp/src/arrow/array/validate.cc | 4 +- cpp/src/arrow/builder.cc | 2 +- cpp/src/arrow/c/bridge.cc | 2 +- cpp/src/arrow/c/bridge_test.cc | 1 + cpp/src/arrow/chunked_array_test.cc | 12 +- cpp/src/arrow/compare.cc | 3 +- cpp/src/arrow/compute/exec/hash_join.cc | 1 + .../arrow/compute/exec/hash_join_node_test.cc | 1 + cpp/src/arrow/compute/exec/ir_consumer.cc | 2 +- .../compute/kernels/aggregate_benchmark.cc | 1 + .../compute/kernels/aggregate_quantile.cc | 1 + .../arrow/compute/kernels/aggregate_test.cc | 1 - .../arrow/compute/kernels/codegen_internal.h | 2 +- .../arrow/compute/kernels/hash_aggregate.cc | 2 +- .../compute/kernels/hash_aggregate_test.cc | 1 - cpp/src/arrow/compute/kernels/row_encoder.h | 2 +- .../compute/kernels/scalar_arithmetic_test.cc | 8 +- .../compute/kernels/scalar_boolean_test.cc | 1 - .../compute/kernels/scalar_cast_string.cc | 2 +- .../arrow/compute/kernels/scalar_cast_test.cc | 1 - .../compute/kernels/scalar_compare_test.cc | 4 +- .../kernels/scalar_if_else_benchmark.cc | 2 + .../compute/kernels/scalar_if_else_test.cc | 3 + .../compute/kernels/scalar_set_lookup.cc | 2 +- .../arrow/compute/kernels/scalar_string.cc | 2 +- .../compute/kernels/scalar_validity_test.cc | 1 - .../arrow/compute/kernels/select_k_test.cc | 3 +- cpp/src/arrow/compute/kernels/test_util.h | 1 + .../compute/kernels/vector_array_sort.cc | 2 +- .../compute/kernels/vector_hash_benchmark.cc | 1 + .../arrow/compute/kernels/vector_hash_test.cc | 1 - .../arrow/compute/kernels/vector_nested.cc | 2 +- .../compute/kernels/vector_replace_test.cc | 1 - .../compute/kernels/vector_selection_test.cc | 4 +- cpp/src/arrow/compute/kernels/vector_sort.cc | 3 +- .../arrow/compute/kernels/vector_sort_test.cc | 13 +- cpp/src/arrow/csv/column_builder_test.cc | 1 + cpp/src/arrow/csv/converter_benchmark.cc | 1 + cpp/src/arrow/csv/converter_test.cc | 1 + cpp/src/arrow/csv/writer.cc | 4 +- cpp/src/arrow/dataset/dataset_writer_test.cc | 1 + cpp/src/arrow/dataset/file_test.cc | 1 + cpp/src/arrow/dataset/partition_test.cc | 1 + cpp/src/arrow/dataset/scanner_test.cc | 1 + cpp/src/arrow/datum_test.cc | 6 +- cpp/src/arrow/filesystem/s3_test_util.cc | 1 + cpp/src/arrow/filesystem/s3fs_benchmark.cc | 1 + cpp/src/arrow/filesystem/test_util.cc | 1 + cpp/src/arrow/flight/flight_benchmark.cc | 1 + cpp/src/arrow/flight/sql/client_test.cc | 1 + cpp/src/arrow/flight/sql/server_test.cc | 1 + cpp/src/arrow/flight/test_util.cc | 2 + cpp/src/arrow/io/buffered_test.cc | 1 + cpp/src/arrow/ipc/feather.cc | 2 +- cpp/src/arrow/ipc/feather_test.cc | 15 +- cpp/src/arrow/ipc/json_simple_test.cc | 2 + cpp/src/arrow/ipc/metadata_internal.cc | 2 +- cpp/src/arrow/ipc/read_write_benchmark.cc | 1 + cpp/src/arrow/ipc/reader.cc | 2 +- cpp/src/arrow/ipc/test_common.cc | 1 + cpp/src/arrow/ipc/writer.cc | 3 +- cpp/src/arrow/json/chunked_builder_test.cc | 1 + cpp/src/arrow/json/parser.cc | 2 +- cpp/src/arrow/json/test_common.h | 5 +- cpp/src/arrow/pretty_print.cc | 2 +- cpp/src/arrow/pretty_print_test.cc | 1 + cpp/src/arrow/python/arrow_to_pandas.cc | 2 +- cpp/src/arrow/python/numpy_to_arrow.cc | 2 +- cpp/src/arrow/python/python_to_arrow.cc | 2 +- cpp/src/arrow/record_batch_test.cc | 72 ++++-- cpp/src/arrow/scalar.cc | 2 +- cpp/src/arrow/scalar.h | 1 + cpp/src/arrow/scalar_test.cc | 3 + cpp/src/arrow/sparse_tensor.cc | 2 +- cpp/src/arrow/sparse_tensor_test.cc | 1 + cpp/src/arrow/stl_test.cc | 30 +-- cpp/src/arrow/table_builder_test.cc | 7 +- cpp/src/arrow/table_test.cc | 61 ++--- cpp/src/arrow/tensor.cc | 2 +- cpp/src/arrow/tensor/coo_converter.cc | 2 +- cpp/src/arrow/tensor/csf_converter.cc | 2 +- cpp/src/arrow/tensor/csx_converter.cc | 2 +- .../tensor/tensor_conversion_benchmark.cc | 5 +- cpp/src/arrow/testing/builder.h | 237 ++++++++++++++++++ cpp/src/arrow/testing/generator.cc | 74 +++++- cpp/src/arrow/testing/generator.h | 103 ++------ cpp/src/arrow/testing/gtest_common.h | 128 ---------- cpp/src/arrow/testing/gtest_util.h | 144 +---------- .../arrow/testing/json_integration_test.cc | 23 +- cpp/src/arrow/testing/json_internal.cc | 4 +- cpp/src/arrow/testing/pch.h | 1 - cpp/src/arrow/testing/random.cc | 2 + cpp/src/arrow/testing/random.h | 7 +- cpp/src/arrow/testing/random_test.cc | 1 + cpp/src/arrow/testing/util.h | 69 +---- cpp/src/arrow/type.cc | 2 +- cpp/src/arrow/util/bit_block_counter_test.cc | 1 - cpp/src/arrow/util/bit_util_test.cc | 3 +- cpp/src/arrow/util/byte_size.cc | 5 +- cpp/src/arrow/util/byte_size.h | 4 +- cpp/src/arrow/util/byte_size_test.cc | 4 + cpp/src/arrow/util/converter.h | 2 +- cpp/src/arrow/util/future_test.cc | 1 + cpp/src/arrow/util/int_util.cc | 2 +- cpp/src/arrow/util/io_util.cc | 4 + cpp/src/arrow/util/io_util_test.cc | 1 + cpp/src/arrow/util/tdigest_test.cc | 1 + cpp/src/arrow/visit_array_inline.h | 44 ++++ .../{visitor_inline.h => visit_data_inline.h} | 121 +-------- cpp/src/arrow/visit_scalar_inline.h | 48 ++++ cpp/src/arrow/visit_type_inline.h | 62 +++++ cpp/src/arrow/visitor_generate.h | 68 +++++ cpp/src/gandiva/tests/test_util.h | 1 + .../parquet/arrow/arrow_reader_writer_test.cc | 1 + cpp/src/parquet/arrow/arrow_schema_test.cc | 1 - cpp/src/parquet/arrow/path_internal.cc | 3 +- cpp/src/parquet/arrow/reader_internal.cc | 2 +- .../arrow/reconstruct_internal_test.cc | 1 + cpp/src/parquet/arrow/writer.cc | 1 - cpp/src/parquet/column_writer.cc | 2 +- cpp/src/parquet/encoding.cc | 2 +- cpp/src/parquet/encoding_test.cc | 1 + cpp/src/parquet/statistics.cc | 2 +- cpp/src/parquet/statistics_test.cc | 4 + 142 files changed, 857 insertions(+), 779 deletions(-) create mode 100644 cpp/src/arrow/testing/builder.h delete mode 100644 cpp/src/arrow/testing/gtest_common.h create mode 100644 cpp/src/arrow/visit_array_inline.h rename cpp/src/arrow/{visitor_inline.h => visit_data_inline.h} (72%) create mode 100644 cpp/src/arrow/visit_scalar_inline.h create mode 100644 cpp/src/arrow/visit_type_inline.h create mode 100644 cpp/src/arrow/visitor_generate.h diff --git a/cpp/src/arrow/adapters/orc/adapter_util.cc b/cpp/src/arrow/adapters/orc/adapter_util.cc index f956a6f6217ab..e908e70c4c3fe 100644 --- a/cpp/src/arrow/adapters/orc/adapter_util.cc +++ b/cpp/src/arrow/adapters/orc/adapter_util.cc @@ -31,7 +31,8 @@ #include "arrow/util/decimal.h" #include "arrow/util/range.h" #include "arrow/util/string_view.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" + #include "orc/Exceptions.hh" #include "orc/MemoryPool.hh" #include "orc/OrcFile.hh" diff --git a/cpp/src/arrow/array/array_base.cc b/cpp/src/arrow/array/array_base.cc index 136e6cadb956b..a3cff7dbb3e0b 100644 --- a/cpp/src/arrow/array/array_base.cc +++ b/cpp/src/arrow/array/array_base.cc @@ -39,8 +39,8 @@ #include "arrow/type_fwd.h" #include "arrow/type_traits.h" #include "arrow/util/logging.h" +#include "arrow/visit_array_inline.h" #include "arrow/visitor.h" -#include "arrow/visitor_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/array_binary_test.cc b/cpp/src/arrow/array/array_binary_test.cc index e9f86df3fc4c5..da1469ebea06b 100644 --- a/cpp/src/arrow/array/array_binary_test.cc +++ b/cpp/src/arrow/array/array_binary_test.cc @@ -29,15 +29,16 @@ #include "arrow/buffer.h" #include "arrow/memory_pool.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" +#include "arrow/testing/util.h" #include "arrow/type.h" #include "arrow/type_traits.h" #include "arrow/util/bit_util.h" #include "arrow/util/bitmap_builders.h" #include "arrow/util/checked_cast.h" #include "arrow/util/string_view.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" namespace arrow { @@ -403,17 +404,14 @@ TYPED_TEST(TestUTF8Array, TestValidateUTF8) { this->TestValidateUTF8(); } // String builder tests template -class TestStringBuilder : public TestBuilder { +class TestStringBuilder : public ::testing::Test { public: using TypeClass = T; using offset_type = typename TypeClass::offset_type; using ArrayType = typename TypeTraits::ArrayType; using BuilderType = typename TypeTraits::BuilderType; - void SetUp() { - TestBuilder::SetUp(); - builder_.reset(new BuilderType(pool_)); - } + void SetUp() { builder_.reset(new BuilderType(pool_)); } void Done() { std::shared_ptr out; @@ -671,6 +669,7 @@ class TestStringBuilder : public TestBuilder { } protected: + MemoryPool* pool_ = default_memory_pool(); std::unique_ptr builder_; std::shared_ptr result_; }; diff --git a/cpp/src/arrow/array/array_dict.cc b/cpp/src/arrow/array/array_dict.cc index 2fa95e9a176f4..dbfc7bd758659 100644 --- a/cpp/src/arrow/array/array_dict.cc +++ b/cpp/src/arrow/array/array_dict.cc @@ -40,7 +40,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/int_util.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/array_dict_test.cc b/cpp/src/arrow/array/array_dict_test.cc index 75f5205a10f93..9193e1d21ac9f 100644 --- a/cpp/src/arrow/array/array_dict_test.cc +++ b/cpp/src/arrow/array/array_dict_test.cc @@ -31,8 +31,8 @@ #include "arrow/chunked_array.h" #include "arrow/status.h" #include "arrow/table.h" +#include "arrow/testing/builder.h" #include "arrow/testing/extension_type.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/util.h" #include "arrow/type.h" @@ -69,7 +69,7 @@ std::shared_ptr DictExtensionFromJSON(const std::shared_ptr& ty // Dictionary tests template -class TestDictionaryBuilder : public TestBuilder {}; +class TestDictionaryBuilder : public ::testing::Test {}; typedef ::testing::Types @@ -1016,7 +1016,7 @@ void AssertIndexByteWidth(const std::shared_ptr& value_type = typedef ::testing::Types IndexTypes; template -class TestDictionaryBuilderIndexByteWidth : public TestBuilder {}; +class TestDictionaryBuilderIndexByteWidth : public ::testing::Test {}; TYPED_TEST_SUITE(TestDictionaryBuilderIndexByteWidth, IndexTypes); diff --git a/cpp/src/arrow/array/array_list_test.cc b/cpp/src/arrow/array/array_list_test.cc index e1aaa310814ce..930702e7cb8d2 100644 --- a/cpp/src/arrow/array/array_list_test.cc +++ b/cpp/src/arrow/array/array_list_test.cc @@ -29,7 +29,7 @@ #include "arrow/array/validate.h" #include "arrow/buffer.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/util/bit_util.h" @@ -47,7 +47,7 @@ using ListTypes = ::testing::Types; // List tests template -class TestListArray : public TestBuilder { +class TestListArray : public ::testing::Test { public: using TypeClass = T; using offset_type = typename TypeClass::offset_type; @@ -58,8 +58,6 @@ class TestListArray : public TestBuilder { using OffsetBuilderType = typename TypeTraits::OffsetBuilderType; void SetUp() { - TestBuilder::SetUp(); - value_type_ = int16(); type_ = std::make_shared(value_type_); @@ -523,6 +521,8 @@ class TestListArray : public TestBuilder { } protected: + MemoryPool* pool_ = default_memory_pool(); + std::shared_ptr type_; std::shared_ptr value_type_; std::shared_ptr builder_; @@ -572,14 +572,12 @@ TYPED_TEST(TestListArray, TestOverflowCheck) { this->TestOverflowCheck(); } // ---------------------------------------------------------------------- // Map tests -class TestMapArray : public TestBuilder { +class TestMapArray : public ::testing::Test { public: using offset_type = typename MapType::offset_type; using OffsetType = typename TypeTraits::OffsetType; void SetUp() { - TestBuilder::SetUp(); - key_type_ = utf8(); value_type_ = int32(); type_ = map(key_type_, value_type_); @@ -596,7 +594,8 @@ class TestMapArray : public TestBuilder { } protected: - std::shared_ptr value_type_, key_type_; + MemoryPool* pool_ = default_memory_pool(); + std::shared_ptr type_, value_type_, key_type_; std::shared_ptr builder_; std::shared_ptr result_; @@ -977,11 +976,9 @@ TEST_F(TestMapArray, ValueBuilder) { // ---------------------------------------------------------------------- // FixedSizeList tests -class TestFixedSizeListArray : public TestBuilder { +class TestFixedSizeListArray : public ::testing::Test { public: void SetUp() { - TestBuilder::SetUp(); - value_type_ = int32(); type_ = fixed_size_list(value_type_, list_size()); @@ -998,7 +995,9 @@ class TestFixedSizeListArray : public TestBuilder { protected: static constexpr int32_t list_size() { return 2; } - std::shared_ptr value_type_; + + MemoryPool* pool_ = default_memory_pool(); + std::shared_ptr type_, value_type_; std::shared_ptr builder_; std::shared_ptr result_; diff --git a/cpp/src/arrow/array/array_struct_test.cc b/cpp/src/arrow/array/array_struct_test.cc index 49573af8928ce..318c83860e009 100644 --- a/cpp/src/arrow/array/array_struct_test.cc +++ b/cpp/src/arrow/array/array_struct_test.cc @@ -26,7 +26,7 @@ #include "arrow/array/builder_nested.h" #include "arrow/chunked_array.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/util/checked_cast.h" @@ -305,11 +305,9 @@ TEST(StructArray, FlattenOfSlice) { // ---------------------------------------------------------------------------------- // Struct test -class TestStructBuilder : public TestBuilder { +class TestStructBuilder : public ::testing::Test { public: void SetUp() { - TestBuilder::SetUp(); - auto int32_type = int32(); auto char_type = int8(); auto list_type = list(char_type); @@ -337,6 +335,8 @@ class TestStructBuilder : public TestBuilder { protected: std::vector> value_fields_; + MemoryPool* pool_ = default_memory_pool(); + std::shared_ptr type_; std::shared_ptr builder_; std::shared_ptr result_; }; diff --git a/cpp/src/arrow/array/array_test.cc b/cpp/src/arrow/array/array_test.cc index 44c1546daca1b..6331105af8998 100644 --- a/cpp/src/arrow/array/array_test.cc +++ b/cpp/src/arrow/array/array_test.cc @@ -46,8 +46,8 @@ #include "arrow/result.h" #include "arrow/scalar.h" #include "arrow/status.h" +#include "arrow/testing/builder.h" #include "arrow/testing/extension_type.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_compat.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" @@ -60,7 +60,7 @@ #include "arrow/util/decimal.h" #include "arrow/util/macros.h" #include "arrow/util/range.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" // This file is compiled together with array-*-test.cc into a single // executable array-test. @@ -840,6 +840,12 @@ TEST(TestPrimitiveArray, CtorNoValidityBitmap) { ASSERT_EQ(arr.data()->null_count, 0); } +class TestBuilder : public ::testing::Test { + protected: + MemoryPool* pool_ = default_memory_pool(); + std::shared_ptr type_; +}; + TEST_F(TestBuilder, TestReserve) { UInt8Builder builder(pool_); diff --git a/cpp/src/arrow/array/array_union_test.cc b/cpp/src/arrow/array/array_union_test.cc index 3bd87a3438f4c..545425c264619 100644 --- a/cpp/src/arrow/array/array_union_test.cc +++ b/cpp/src/arrow/array/array_union_test.cc @@ -24,6 +24,7 @@ #include "arrow/array/builder_union.h" // TODO ipc shouldn't be included here #include "arrow/ipc/test_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/util.h" #include "arrow/type.h" diff --git a/cpp/src/arrow/array/builder_base.cc b/cpp/src/arrow/array/builder_base.cc index 117b9d3763204..49abd8e0234c4 100644 --- a/cpp/src/arrow/array/builder_base.cc +++ b/cpp/src/arrow/array/builder_base.cc @@ -30,7 +30,7 @@ #include "arrow/scalar.h" #include "arrow/status.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/builder_dict.cc b/cpp/src/arrow/array/builder_dict.cc index d247316999dc6..d51dd4c041ad3 100644 --- a/cpp/src/arrow/array/builder_dict.cc +++ b/cpp/src/arrow/array/builder_dict.cc @@ -27,7 +27,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/hashing.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/builder_dict.h b/cpp/src/arrow/array/builder_dict.h index 76199deac2aad..a9b0d2ddf6caf 100644 --- a/cpp/src/arrow/array/builder_dict.h +++ b/cpp/src/arrow/array/builder_dict.h @@ -33,11 +33,11 @@ #include "arrow/status.h" #include "arrow/type.h" #include "arrow/type_traits.h" +#include "arrow/util/bit_block_counter.h" #include "arrow/util/checked_cast.h" #include "arrow/util/decimal.h" #include "arrow/util/macros.h" #include "arrow/util/visibility.h" -#include "arrow/visitor_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/concatenate.cc b/cpp/src/arrow/array/concatenate.cc index f7720bd9dd03c..ec6da9c3e562e 100644 --- a/cpp/src/arrow/array/concatenate.cc +++ b/cpp/src/arrow/array/concatenate.cc @@ -25,7 +25,7 @@ #include #include -#include "arrow/array/array_base.h" +#include "arrow/array.h" #include "arrow/array/builder_primitive.h" #include "arrow/array/data.h" #include "arrow/array/util.h" @@ -41,7 +41,7 @@ #include "arrow/util/int_util.h" #include "arrow/util/int_util_internal.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/concatenate_test.cc b/cpp/src/arrow/array/concatenate_test.cc index cf385da44a287..aacd7518928da 100644 --- a/cpp/src/arrow/array/concatenate_test.cc +++ b/cpp/src/arrow/array/concatenate_test.cc @@ -35,7 +35,7 @@ #include "arrow/array/concatenate.h" #include "arrow/buffer.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" #include "arrow/type.h" diff --git a/cpp/src/arrow/array/dict_internal.h b/cpp/src/arrow/array/dict_internal.h index aa027ac22dea3..a8b69133cfed2 100644 --- a/cpp/src/arrow/array/dict_internal.h +++ b/cpp/src/arrow/array/dict_internal.h @@ -35,7 +35,6 @@ #include "arrow/util/hashing.h" #include "arrow/util/logging.h" #include "arrow/util/string_view.h" -#include "arrow/visitor_inline.h" namespace arrow { namespace internal { diff --git a/cpp/src/arrow/array/diff.cc b/cpp/src/arrow/array/diff.cc index 32a95450374f6..bcc065c69b42c 100644 --- a/cpp/src/arrow/array/diff.cc +++ b/cpp/src/arrow/array/diff.cc @@ -45,7 +45,7 @@ #include "arrow/util/string.h" #include "arrow/util/string_view.h" #include "arrow/vendored/datetime.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/diff_test.cc b/cpp/src/arrow/array/diff_test.cc index d802a52cdc2f5..e322006732f9a 100644 --- a/cpp/src/arrow/array/diff_test.cc +++ b/cpp/src/arrow/array/diff_test.cc @@ -31,7 +31,7 @@ #include "arrow/array/diff.h" #include "arrow/compute/api.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" #include "arrow/type.h" diff --git a/cpp/src/arrow/array/util.cc b/cpp/src/arrow/array/util.cc index afafc8b980f90..62c9fa20c34c2 100644 --- a/cpp/src/arrow/array/util.cc +++ b/cpp/src/arrow/array/util.cc @@ -27,9 +27,7 @@ #include #include -#include "arrow/array/array_base.h" -#include "arrow/array/array_dict.h" -#include "arrow/array/array_primitive.h" +#include "arrow/array.h" #include "arrow/array/builder_base.h" #include "arrow/array/concatenate.h" #include "arrow/buffer.h" @@ -45,7 +43,7 @@ #include "arrow/util/decimal.h" #include "arrow/util/endian.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/array/validate.cc b/cpp/src/arrow/array/validate.cc index 696c03c88411f..f54230145208f 100644 --- a/cpp/src/arrow/array/validate.cc +++ b/cpp/src/arrow/array/validate.cc @@ -27,10 +27,12 @@ #include "arrow/util/bit_util.h" #include "arrow/util/bitmap_ops.h" #include "arrow/util/checked_cast.h" +#include "arrow/util/decimal.h" #include "arrow/util/int_util_internal.h" #include "arrow/util/logging.h" #include "arrow/util/utf8.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { namespace internal { diff --git a/cpp/src/arrow/builder.cc b/cpp/src/arrow/builder.cc index 7b7ec1706d96a..f3d12dbece96d 100644 --- a/cpp/src/arrow/builder.cc +++ b/cpp/src/arrow/builder.cc @@ -26,7 +26,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/hashing.h" #include "arrow/util/make_unique.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/c/bridge.cc b/cpp/src/arrow/c/bridge.cc index f4137867313e6..f2671b5016122 100644 --- a/cpp/src/arrow/c/bridge.cc +++ b/cpp/src/arrow/c/bridge.cc @@ -42,7 +42,7 @@ #include "arrow/util/small_vector.h" #include "arrow/util/string_view.h" #include "arrow/util/value_parsing.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/c/bridge_test.cc b/cpp/src/arrow/c/bridge_test.cc index fd2beca8295da..2c20c54cfe209 100644 --- a/cpp/src/arrow/c/bridge_test.cc +++ b/cpp/src/arrow/c/bridge_test.cc @@ -26,6 +26,7 @@ #include #include +#include "arrow/array.h" #include "arrow/c/bridge.h" #include "arrow/c/helpers.h" #include "arrow/c/util_internal.h" diff --git a/cpp/src/arrow/chunked_array_test.cc b/cpp/src/arrow/chunked_array_test.cc index eb094854ce547..a623cd4706576 100644 --- a/cpp/src/arrow/chunked_array_test.cc +++ b/cpp/src/arrow/chunked_array_test.cc @@ -25,7 +25,7 @@ #include "arrow/scalar.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/type.h" @@ -34,7 +34,7 @@ namespace arrow { -class TestChunkedArray : public TestBase { +class TestChunkedArray : public ::testing::Test { protected: virtual void Construct() { one_ = std::make_shared(arrays_one_); @@ -147,9 +147,11 @@ TEST_F(TestChunkedArray, EqualsDifferingMetadata) { } TEST_F(TestChunkedArray, SliceEquals) { - arrays_one_.push_back(MakeRandomArray(100)); - arrays_one_.push_back(MakeRandomArray(50)); - arrays_one_.push_back(MakeRandomArray(50)); + random::RandomArrayGenerator gen(42); + + arrays_one_.push_back(gen.Int32(100, -12345, 12345)); + arrays_one_.push_back(gen.Int32(50, -12345, 12345)); + arrays_one_.push_back(gen.Int32(50, -12345, 12345)); Construct(); std::shared_ptr slice = one_->Slice(125, 50); diff --git a/cpp/src/arrow/compare.cc b/cpp/src/arrow/compare.cc index 83497915f4c3d..ae1783a515e36 100644 --- a/cpp/src/arrow/compare.cc +++ b/cpp/src/arrow/compare.cc @@ -46,7 +46,8 @@ #include "arrow/util/logging.h" #include "arrow/util/macros.h" #include "arrow/util/memory.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_scalar_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/exec/hash_join.cc b/cpp/src/arrow/compute/exec/hash_join.cc index 02f97dd6f8606..4c51c56d7d96e 100644 --- a/cpp/src/arrow/compute/exec/hash_join.cc +++ b/cpp/src/arrow/compute/exec/hash_join.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/cpp/src/arrow/compute/exec/hash_join_node_test.cc b/cpp/src/arrow/compute/exec/hash_join_node_test.cc index 236e8a5d9bb46..4db8e9e9ae7dd 100644 --- a/cpp/src/arrow/compute/exec/hash_join_node_test.cc +++ b/cpp/src/arrow/compute/exec/hash_join_node_test.cc @@ -17,6 +17,7 @@ #include +#include #include #include diff --git a/cpp/src/arrow/compute/exec/ir_consumer.cc b/cpp/src/arrow/compute/exec/ir_consumer.cc index b0e47d7108777..8627530d43490 100644 --- a/cpp/src/arrow/compute/exec/ir_consumer.cc +++ b/cpp/src/arrow/compute/exec/ir_consumer.cc @@ -27,7 +27,7 @@ #include "arrow/ipc/dictionary.h" #include "arrow/ipc/metadata_internal.h" #include "arrow/util/unreachable.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" #include "generated/Plan_generated.h" diff --git a/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc b/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc index 2507ef7fcda95..230d9649de0a6 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_benchmark.cc @@ -19,6 +19,7 @@ #include +#include "arrow/array/array_primitive.h" #include "arrow/compute/api.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" diff --git a/cpp/src/arrow/compute/kernels/aggregate_quantile.cc b/cpp/src/arrow/compute/kernels/aggregate_quantile.cc index 9d36471fb3bec..1ca030130b00b 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_quantile.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_quantile.cc @@ -16,6 +16,7 @@ // under the License. #include +#include #include #include "arrow/compute/api_aggregate.h" diff --git a/cpp/src/arrow/compute/kernels/aggregate_test.cc b/cpp/src/arrow/compute/kernels/aggregate_test.cc index d389ababce43b..f77ee92cd8ff6 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_test.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_test.cc @@ -40,7 +40,6 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/int_util_internal.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/matchers.h" #include "arrow/testing/random.h" diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index c07046c982c99..1efd3e22f9310 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -48,7 +48,7 @@ #include "arrow/util/make_unique.h" #include "arrow/util/optional.h" #include "arrow/util/string_view.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate.cc b/cpp/src/arrow/compute/kernels/hash_aggregate.cc index a982aec4372e4..ef6234a552190 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate.cc @@ -52,7 +52,7 @@ #include "arrow/util/task_group.h" #include "arrow/util/tdigest.h" #include "arrow/util/thread_pool.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc b/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc index 61f90f3f845a3..0cc24b73b7b60 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc @@ -42,7 +42,6 @@ #include "arrow/compute/registry.h" #include "arrow/table.h" #include "arrow/testing/generator.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/matchers.h" #include "arrow/testing/random.h" diff --git a/cpp/src/arrow/compute/kernels/row_encoder.h b/cpp/src/arrow/compute/kernels/row_encoder.h index 40509f2df7bf6..412b84af9ddff 100644 --- a/cpp/src/arrow/compute/kernels/row_encoder.h +++ b/cpp/src/arrow/compute/kernels/row_encoder.h @@ -21,7 +21,7 @@ #include "arrow/compute/exec.h" #include "arrow/compute/kernels/codegen_internal.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc b/cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc index 3d8d5813101e4..ed4a1616e484c 100644 --- a/cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc @@ -34,7 +34,7 @@ #include "arrow/util/math_constants.h" #include "arrow/util/string.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" @@ -73,7 +73,7 @@ void AssertNullToNull(const std::string& func_name) { } template -class TestBaseUnaryArithmetic : public TestBase { +class TestBaseUnaryArithmetic : public ::testing::Test { protected: using ArrowType = T; using CType = typename ArrowType::c_type; @@ -287,7 +287,7 @@ class TestArithmeticDecimal : public ::testing::Test { }; template -class TestBinaryArithmetic : public TestBase { +class TestBinaryArithmetic : public ::testing::Test { protected: using ArrowType = T; using CType = typename ArrowType::c_type; @@ -464,7 +464,7 @@ template class TestBinaryArithmeticFloating : public TestBinaryArithmetic {}; template -class TestBitWiseArithmetic : public TestBase { +class TestBitWiseArithmetic : public ::testing::Test { protected: using ArrowType = T; using CType = typename ArrowType::c_type; diff --git a/cpp/src/arrow/compute/kernels/scalar_boolean_test.cc b/cpp/src/arrow/compute/kernels/scalar_boolean_test.cc index f07b02d97361f..fe6ca527bfd70 100644 --- a/cpp/src/arrow/compute/kernels/scalar_boolean_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_boolean_test.cc @@ -25,7 +25,6 @@ #include "arrow/chunked_array.h" #include "arrow/compute/api_scalar.h" #include "arrow/compute/kernels/test_util.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/util/checked_cast.h" diff --git a/cpp/src/arrow/compute/kernels/scalar_cast_string.cc b/cpp/src/arrow/compute/kernels/scalar_cast_string.cc index 4130c6a94879a..efc4162200444 100644 --- a/cpp/src/arrow/compute/kernels/scalar_cast_string.cc +++ b/cpp/src/arrow/compute/kernels/scalar_cast_string.cc @@ -27,7 +27,7 @@ #include "arrow/util/int_util.h" #include "arrow/util/optional.h" #include "arrow/util/utf8.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/scalar_cast_test.cc b/cpp/src/arrow/compute/kernels/scalar_cast_test.cc index b5cafead6b2c7..226452404d06b 100644 --- a/cpp/src/arrow/compute/kernels/scalar_cast_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_cast_test.cc @@ -32,7 +32,6 @@ #include "arrow/extension_type.h" #include "arrow/status.h" #include "arrow/testing/extension_type.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/type.h" diff --git a/cpp/src/arrow/compute/kernels/scalar_compare_test.cc b/cpp/src/arrow/compute/kernels/scalar_compare_test.cc index 0fa97e17303c9..b674966401080 100644 --- a/cpp/src/arrow/compute/kernels/scalar_compare_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_compare_test.cc @@ -27,7 +27,7 @@ #include "arrow/array.h" #include "arrow/compute/api.h" #include "arrow/compute/kernels/test_util.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/matchers.h" #include "arrow/testing/random.h" @@ -1117,7 +1117,7 @@ TEST_F(TestStringCompareKernel, RandomCompareArrayArray) { } template -class TestVarArgsCompare : public TestBase { +class TestVarArgsCompare : public ::testing::Test { protected: static std::shared_ptr type_singleton() { return TypeTraits::type_singleton(); diff --git a/cpp/src/arrow/compute/kernels/scalar_if_else_benchmark.cc b/cpp/src/arrow/compute/kernels/scalar_if_else_benchmark.cc index b6d6bf6e44f22..bbe6eddd6c0bd 100644 --- a/cpp/src/arrow/compute/kernels/scalar_if_else_benchmark.cc +++ b/cpp/src/arrow/compute/kernels/scalar_if_else_benchmark.cc @@ -17,7 +17,9 @@ #include +#include "arrow/array.h" #include "arrow/array/concatenate.h" +#include "arrow/array/util.h" #include "arrow/compute/api_scalar.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" diff --git a/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc b/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc index 711b318feb743..9d874238b5ac9 100644 --- a/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_if_else_test.cc @@ -15,7 +15,10 @@ // specific language governing permissions and limitations // under the License. +#include + #include + #include "arrow/array.h" #include "arrow/array/concatenate.h" #include "arrow/compute/api_scalar.h" diff --git a/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc b/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc index f50bf55004a03..97eedd53eecaa 100644 --- a/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc +++ b/cpp/src/arrow/compute/kernels/scalar_set_lookup.cc @@ -24,7 +24,7 @@ #include "arrow/util/bit_util.h" #include "arrow/util/bitmap_writer.h" #include "arrow/util/hashing.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/scalar_string.cc b/cpp/src/arrow/compute/kernels/scalar_string.cc index 6ecd1756bd9a7..451b2fffff3ec 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string.cc @@ -38,7 +38,7 @@ #include "arrow/util/string.h" #include "arrow/util/utf8.h" #include "arrow/util/value_parsing.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/scalar_validity_test.cc b/cpp/src/arrow/compute/kernels/scalar_validity_test.cc index 5b0934828a23b..fb9358b1434dc 100644 --- a/cpp/src/arrow/compute/kernels/scalar_validity_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_validity_test.cc @@ -20,7 +20,6 @@ #include "arrow/array.h" #include "arrow/compute/api.h" #include "arrow/compute/kernels/test_util.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/type.h" diff --git a/cpp/src/arrow/compute/kernels/select_k_test.cc b/cpp/src/arrow/compute/kernels/select_k_test.cc index 2d1d5cffe3d05..c9dbe0bd4c075 100644 --- a/cpp/src/arrow/compute/kernels/select_k_test.cc +++ b/cpp/src/arrow/compute/kernels/select_k_test.cc @@ -28,7 +28,6 @@ #include "arrow/compute/kernels/test_util.h" #include "arrow/compute/kernels/util_internal.h" #include "arrow/table.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" @@ -84,7 +83,7 @@ void ValidateSelectK(const Datum& datum, Array& select_k_indices, SortOrder orde } template -class TestSelectKBase : public TestBase { +class TestSelectKBase : public ::testing::Test { using ArrayType = typename TypeTraits::ArrayType; protected: diff --git a/cpp/src/arrow/compute/kernels/test_util.h b/cpp/src/arrow/compute/kernels/test_util.h index ca37919b67601..c2d5a8f12e84d 100644 --- a/cpp/src/arrow/compute/kernels/test_util.h +++ b/cpp/src/arrow/compute/kernels/test_util.h @@ -32,6 +32,7 @@ #include "arrow/datum.h" #include "arrow/memory_pool.h" #include "arrow/pretty_print.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" diff --git a/cpp/src/arrow/compute/kernels/vector_array_sort.cc b/cpp/src/arrow/compute/kernels/vector_array_sort.cc index ade19ebfd1bd6..1335882a25212 100644 --- a/cpp/src/arrow/compute/kernels/vector_array_sort.cc +++ b/cpp/src/arrow/compute/kernels/vector_array_sort.cc @@ -33,7 +33,7 @@ #include "arrow/util/bitmap.h" #include "arrow/util/bitmap_ops.h" #include "arrow/util/checked_cast.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/vector_hash_benchmark.cc b/cpp/src/arrow/compute/kernels/vector_hash_benchmark.cc index 3be549d05ce60..e9548e133aa00 100644 --- a/cpp/src/arrow/compute/kernels/vector_hash_benchmark.cc +++ b/cpp/src/arrow/compute/kernels/vector_hash_benchmark.cc @@ -21,6 +21,7 @@ #include "arrow/array/builder_binary.h" #include "arrow/memory_pool.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" diff --git a/cpp/src/arrow/compute/kernels/vector_hash_test.cc b/cpp/src/arrow/compute/kernels/vector_hash_test.cc index df19490b9f20d..d157b0d5fab0d 100644 --- a/cpp/src/arrow/compute/kernels/vector_hash_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_hash_test.cc @@ -33,7 +33,6 @@ #include "arrow/buffer.h" #include "arrow/chunked_array.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/util.h" #include "arrow/type.h" #include "arrow/type_fwd.h" diff --git a/cpp/src/arrow/compute/kernels/vector_nested.cc b/cpp/src/arrow/compute/kernels/vector_nested.cc index 047101869dd7e..84a0725c22b73 100644 --- a/cpp/src/arrow/compute/kernels/vector_nested.cc +++ b/cpp/src/arrow/compute/kernels/vector_nested.cc @@ -20,7 +20,7 @@ #include "arrow/array/array_base.h" #include "arrow/compute/kernels/common.h" #include "arrow/result.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { namespace compute { diff --git a/cpp/src/arrow/compute/kernels/vector_replace_test.cc b/cpp/src/arrow/compute/kernels/vector_replace_test.cc index 6b5c0871d1df6..421f493c9ade0 100644 --- a/cpp/src/arrow/compute/kernels/vector_replace_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_replace_test.cc @@ -20,7 +20,6 @@ #include "arrow/compute/api_vector.h" #include "arrow/compute/kernels/test_util.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/util/checked_cast.h" #include "arrow/util/key_value_metadata.h" diff --git a/cpp/src/arrow/compute/kernels/vector_selection_test.cc b/cpp/src/arrow/compute/kernels/vector_selection_test.cc index 4e8f7d8a41bbd..c0eff3a8e9190 100644 --- a/cpp/src/arrow/compute/kernels/vector_selection_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_selection_test.cc @@ -28,7 +28,7 @@ #include "arrow/compute/api.h" #include "arrow/compute/kernels/test_util.h" #include "arrow/table.h" -#include "arrow/testing/gtest_common.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" @@ -1432,7 +1432,7 @@ TEST_F(TestTakeKernelWithUnion, TakeUnion) { ])"); } -class TestPermutationsWithTake : public TestBase { +class TestPermutationsWithTake : public ::testing::Test { protected: void DoTake(const Int16Array& values, const Int16Array& indices, std::shared_ptr* out) { diff --git a/cpp/src/arrow/compute/kernels/vector_sort.cc b/cpp/src/arrow/compute/kernels/vector_sort.cc index 310dee66c2bf5..dd5bead58aa67 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort.cc @@ -35,7 +35,8 @@ #include "arrow/type_traits.h" #include "arrow/util/checked_cast.h" #include "arrow/util/optional.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" +#include "arrow/visitor.h" namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/vector_sort_test.cc b/cpp/src/arrow/compute/kernels/vector_sort_test.cc index 2cf26d633a5bc..50add1aec419d 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort_test.cc @@ -32,7 +32,6 @@ #include "arrow/compute/kernels/test_util.h" #include "arrow/result.h" #include "arrow/table.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" #include "arrow/testing/util.h" @@ -148,7 +147,7 @@ struct SortComparator { }; template -class TestNthToIndicesBase : public TestBase { +class TestNthToIndicesBase : public ::testing::Test { using ArrayType = typename TypeTraits::ArrayType; protected: @@ -403,7 +402,7 @@ void AssertSortIndices(const std::shared_ptr& type, const std::string& ArrayFromJSON(uint64(), expected)); } -class TestArraySortIndicesBase : public TestBase { +class TestArraySortIndicesBase : public ::testing::Test { public: virtual std::shared_ptr type() = 0; @@ -768,13 +767,13 @@ TEST(TestArraySortIndices, TemporalTypeParameters) { } template -class TestArraySortIndicesRandom : public TestBase {}; +class TestArraySortIndicesRandom : public ::testing::Test {}; template -class TestArraySortIndicesRandomCount : public TestBase {}; +class TestArraySortIndicesRandomCount : public ::testing::Test {}; template -class TestArraySortIndicesRandomCompare : public TestBase {}; +class TestArraySortIndicesRandomCompare : public ::testing::Test {}; using SortIndicesableTypes = ::testing::Types -class TestChunkedArrayRandomBase : public TestBase { +class TestChunkedArrayRandomBase : public ::testing::Test { protected: // Generates a chunk. This should be implemented in subclasses. virtual std::shared_ptr GenerateArray(int length, double null_probability) = 0; diff --git a/cpp/src/arrow/csv/column_builder_test.cc b/cpp/src/arrow/csv/column_builder_test.cc index 53e69ada62f11..cb178c1d2b362 100644 --- a/cpp/src/arrow/csv/column_builder_test.cc +++ b/cpp/src/arrow/csv/column_builder_test.cc @@ -27,6 +27,7 @@ #include "arrow/csv/test_common.h" #include "arrow/memory_pool.h" #include "arrow/table.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/util.h" #include "arrow/type.h" diff --git a/cpp/src/arrow/csv/converter_benchmark.cc b/cpp/src/arrow/csv/converter_benchmark.cc index b7311880d9429..b55c11e4db7c3 100644 --- a/cpp/src/arrow/csv/converter_benchmark.cc +++ b/cpp/src/arrow/csv/converter_benchmark.cc @@ -20,6 +20,7 @@ #include #include +#include "arrow/array.h" #include "arrow/buffer.h" #include "arrow/csv/converter.h" #include "arrow/csv/options.h" diff --git a/cpp/src/arrow/csv/converter_test.cc b/cpp/src/arrow/csv/converter_test.cc index 9a83ef020dea9..0c5def554b0c0 100644 --- a/cpp/src/arrow/csv/converter_test.cc +++ b/cpp/src/arrow/csv/converter_test.cc @@ -30,6 +30,7 @@ #include "arrow/csv/options.h" #include "arrow/csv/test_common.h" #include "arrow/status.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/type_traits.h" diff --git a/cpp/src/arrow/csv/writer.cc b/cpp/src/arrow/csv/writer.cc index 34d6e85f8804a..823e5b182f8de 100644 --- a/cpp/src/arrow/csv/writer.cc +++ b/cpp/src/arrow/csv/writer.cc @@ -27,8 +27,8 @@ #include "arrow/util/iterator.h" #include "arrow/util/logging.h" #include "arrow/util/make_unique.h" - -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { namespace csv { diff --git a/cpp/src/arrow/dataset/dataset_writer_test.cc b/cpp/src/arrow/dataset/dataset_writer_test.cc index 337301e81fc4e..5ee6b0274396d 100644 --- a/cpp/src/arrow/dataset/dataset_writer_test.cc +++ b/cpp/src/arrow/dataset/dataset_writer_test.cc @@ -21,6 +21,7 @@ #include #include +#include "arrow/array/builder_primitive.h" #include "arrow/dataset/file_ipc.h" #include "arrow/filesystem/mockfs.h" #include "arrow/filesystem/test_util.h" diff --git a/cpp/src/arrow/dataset/file_test.cc b/cpp/src/arrow/dataset/file_test.cc index db2eedbcf16f5..360a32604da3a 100644 --- a/cpp/src/arrow/dataset/file_test.cc +++ b/cpp/src/arrow/dataset/file_test.cc @@ -23,6 +23,7 @@ #include #include +#include "arrow/array/array_primitive.h" #include "arrow/dataset/api.h" #include "arrow/dataset/partition.h" #include "arrow/dataset/test_util.h" diff --git a/cpp/src/arrow/dataset/partition_test.cc b/cpp/src/arrow/dataset/partition_test.cc index 0897a4ed62915..7643c9466058d 100644 --- a/cpp/src/arrow/dataset/partition_test.cc +++ b/cpp/src/arrow/dataset/partition_test.cc @@ -32,6 +32,7 @@ #include "arrow/dataset/test_util.h" #include "arrow/filesystem/path_util.h" #include "arrow/status.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/util/range.h" diff --git a/cpp/src/arrow/dataset/scanner_test.cc b/cpp/src/arrow/dataset/scanner_test.cc index 83151de2c02f3..45e1b3688ed51 100644 --- a/cpp/src/arrow/dataset/scanner_test.cc +++ b/cpp/src/arrow/dataset/scanner_test.cc @@ -33,6 +33,7 @@ #include "arrow/record_batch.h" #include "arrow/table.h" #include "arrow/testing/async_test_util.h" +#include "arrow/testing/builder.h" #include "arrow/testing/future_util.h" #include "arrow/testing/generator.h" #include "arrow/testing/gtest_util.h" diff --git a/cpp/src/arrow/datum_test.cc b/cpp/src/arrow/datum_test.cc index 4e64ead5319fb..a5bf1728f33d1 100644 --- a/cpp/src/arrow/datum_test.cc +++ b/cpp/src/arrow/datum_test.cc @@ -21,20 +21,18 @@ #include #include "arrow/array/array_base.h" +#include "arrow/array/array_binary.h" #include "arrow/chunked_array.h" #include "arrow/datum.h" +#include "arrow/record_batch.h" #include "arrow/scalar.h" #include "arrow/table.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/type_fwd.h" #include "arrow/util/checked_cast.h" namespace arrow { -class BinaryArray; -class RecordBatch; - using internal::checked_cast; // ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/filesystem/s3_test_util.cc b/cpp/src/arrow/filesystem/s3_test_util.cc index e47560f7c72b5..4e177b7fd4b6b 100644 --- a/cpp/src/arrow/filesystem/s3_test_util.cc +++ b/cpp/src/arrow/filesystem/s3_test_util.cc @@ -36,6 +36,7 @@ #include "arrow/filesystem/s3_test_util.h" #include "arrow/filesystem/s3fs.h" +#include "arrow/testing/util.h" #include "arrow/util/async_generator.h" #include "arrow/util/future.h" #include "arrow/util/io_util.h" diff --git a/cpp/src/arrow/filesystem/s3fs_benchmark.cc b/cpp/src/arrow/filesystem/s3fs_benchmark.cc index c664b76bf00d9..1380651c2cc7f 100644 --- a/cpp/src/arrow/filesystem/s3fs_benchmark.cc +++ b/cpp/src/arrow/filesystem/s3fs_benchmark.cc @@ -16,6 +16,7 @@ // under the License. #include +#include #include #include diff --git a/cpp/src/arrow/filesystem/test_util.cc b/cpp/src/arrow/filesystem/test_util.cc index 0f40ae38277be..db520336276fb 100644 --- a/cpp/src/arrow/filesystem/test_util.cc +++ b/cpp/src/arrow/filesystem/test_util.cc @@ -24,6 +24,7 @@ #include #include +#include "arrow/buffer.h" #include "arrow/filesystem/mockfs.h" #include "arrow/filesystem/test_util.h" #include "arrow/io/interfaces.h" diff --git a/cpp/src/arrow/flight/flight_benchmark.cc b/cpp/src/arrow/flight/flight_benchmark.cc index 1b5f27d312189..e90f4fa1352cc 100644 --- a/cpp/src/arrow/flight/flight_benchmark.cc +++ b/cpp/src/arrow/flight/flight_benchmark.cc @@ -23,6 +23,7 @@ #include +#include "arrow/array.h" #include "arrow/io/file.h" #include "arrow/io/memory.h" #include "arrow/ipc/api.h" diff --git a/cpp/src/arrow/flight/sql/client_test.cc b/cpp/src/arrow/flight/sql/client_test.cc index 8c0c8333074ec..5501cbe6e654f 100644 --- a/cpp/src/arrow/flight/sql/client_test.cc +++ b/cpp/src/arrow/flight/sql/client_test.cc @@ -23,6 +23,7 @@ #include +#include "arrow/buffer.h" #include "arrow/flight/sql/FlightSql.pb.h" #include "arrow/flight/sql/api.h" #include "arrow/testing/gtest_util.h" diff --git a/cpp/src/arrow/flight/sql/server_test.cc b/cpp/src/arrow/flight/sql/server_test.cc index d74b6d4013748..507745c075d4c 100644 --- a/cpp/src/arrow/flight/sql/server_test.cc +++ b/cpp/src/arrow/flight/sql/server_test.cc @@ -30,6 +30,7 @@ #include "arrow/flight/sql/example/sqlite_sql_info.h" #include "arrow/flight/test_util.h" #include "arrow/flight/types.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" using ::testing::_; diff --git a/cpp/src/arrow/flight/test_util.cc b/cpp/src/arrow/flight/test_util.cc index d10b8280768d3..45974086823b7 100644 --- a/cpp/src/arrow/flight/test_util.cc +++ b/cpp/src/arrow/flight/test_util.cc @@ -34,6 +34,8 @@ #include +#include "arrow/array.h" +#include "arrow/array/builder_primitive.h" #include "arrow/ipc/test_common.h" #include "arrow/testing/generator.h" #include "arrow/testing/gtest_util.h" diff --git a/cpp/src/arrow/io/buffered_test.cc b/cpp/src/arrow/io/buffered_test.cc index 1fefc261b1d33..ede18f20d4ce6 100644 --- a/cpp/src/arrow/io/buffered_test.cc +++ b/cpp/src/arrow/io/buffered_test.cc @@ -34,6 +34,7 @@ #include +#include "arrow/buffer.h" #include "arrow/io/buffered.h" #include "arrow/io/file.h" #include "arrow/io/interfaces.h" diff --git a/cpp/src/arrow/ipc/feather.cc b/cpp/src/arrow/ipc/feather.cc index 977c0b4b53412..ad4baf2527b9b 100644 --- a/cpp/src/arrow/ipc/feather.cc +++ b/cpp/src/arrow/ipc/feather.cc @@ -47,7 +47,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" #include "arrow/util/make_unique.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" #include "generated/feather_generated.h" diff --git a/cpp/src/arrow/ipc/feather_test.cc b/cpp/src/arrow/ipc/feather_test.cc index e9a3c72c61af1..8768056c57116 100644 --- a/cpp/src/arrow/ipc/feather_test.cc +++ b/cpp/src/arrow/ipc/feather_test.cc @@ -226,24 +226,15 @@ TEST_P(TestFeather, CategoryRoundtrip) { } TEST_P(TestFeather, TimeTypes) { - std::vector is_valid = {true, true, true, false, true, true, true}; auto f0 = field("f0", date32()); auto f1 = field("f1", time32(TimeUnit::MILLI)); auto f2 = field("f2", timestamp(TimeUnit::NANO)); auto f3 = field("f3", timestamp(TimeUnit::SECOND, "US/Los_Angeles")); auto schema = ::arrow::schema({f0, f1, f2, f3}); - std::vector values64_vec = {0, 1, 2, 3, 4, 5, 6}; - std::shared_ptr values64; - ArrayFromVector(is_valid, values64_vec, &values64); - - std::vector values32_vec = {10, 11, 12, 13, 14, 15, 16}; - std::shared_ptr values32; - ArrayFromVector(is_valid, values32_vec, &values32); - - std::vector date_values_vec = {20, 21, 22, 23, 24, 25, 26}; - std::shared_ptr date_array; - ArrayFromVector(is_valid, date_values_vec, &date_array); + auto values64 = ArrayFromJSON(int64(), "[0, 1, null, null, 4, 5, 6]"); + auto values32 = ArrayFromJSON(int32(), "[10, null, 12, 13, 14, 15, null]"); + auto date_array = ArrayFromJSON(date32(), "[20, 21, 22, 23, 24, null, 26]"); const auto& prim_values64 = checked_cast(*values64); BufferVector buffers64 = {prim_values64.null_bitmap(), prim_values64.values()}; diff --git a/cpp/src/arrow/ipc/json_simple_test.cc b/cpp/src/arrow/ipc/json_simple_test.cc index 34c300faa95b0..c6f66d003f4d1 100644 --- a/cpp/src/arrow/ipc/json_simple_test.cc +++ b/cpp/src/arrow/ipc/json_simple_test.cc @@ -35,6 +35,8 @@ #include "arrow/array/builder_primitive.h" #include "arrow/array/builder_time.h" #include "arrow/ipc/json_simple.h" +#include "arrow/scalar.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/type_traits.h" diff --git a/cpp/src/arrow/ipc/metadata_internal.cc b/cpp/src/arrow/ipc/metadata_internal.cc index 0ce0270a866cc..d2f2b20d16535 100644 --- a/cpp/src/arrow/ipc/metadata_internal.cc +++ b/cpp/src/arrow/ipc/metadata_internal.cc @@ -39,7 +39,7 @@ #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging.h" #include "arrow/util/ubsan.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" #include "generated/File_generated.h" #include "generated/Message_generated.h" diff --git a/cpp/src/arrow/ipc/read_write_benchmark.cc b/cpp/src/arrow/ipc/read_write_benchmark.cc index 01dd22a8cb83b..ed00208672a72 100644 --- a/cpp/src/arrow/ipc/read_write_benchmark.cc +++ b/cpp/src/arrow/ipc/read_write_benchmark.cc @@ -21,6 +21,7 @@ #include #include +#include "arrow/buffer.h" #include "arrow/io/file.h" #include "arrow/io/memory.h" #include "arrow/ipc/api.h" diff --git a/cpp/src/arrow/ipc/reader.cc b/cpp/src/arrow/ipc/reader.cc index b834aa429c1cc..c12254d271d03 100644 --- a/cpp/src/arrow/ipc/reader.cc +++ b/cpp/src/arrow/ipc/reader.cc @@ -56,7 +56,7 @@ #include "arrow/util/thread_pool.h" #include "arrow/util/ubsan.h" #include "arrow/util/vector.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" #include "generated/File_generated.h" // IWYU pragma: export #include "generated/Message_generated.h" diff --git a/cpp/src/arrow/ipc/test_common.cc b/cpp/src/arrow/ipc/test_common.cc index d499aba699996..d7c1d852b88b3 100644 --- a/cpp/src/arrow/ipc/test_common.cc +++ b/cpp/src/arrow/ipc/test_common.cc @@ -33,6 +33,7 @@ #include "arrow/record_batch.h" #include "arrow/status.h" #include "arrow/tensor.h" +#include "arrow/testing/builder.h" #include "arrow/testing/extension_type.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" diff --git a/cpp/src/arrow/ipc/writer.cc b/cpp/src/arrow/ipc/writer.cc index faa151dedf86c..658f1a1dd2bd3 100644 --- a/cpp/src/arrow/ipc/writer.cc +++ b/cpp/src/arrow/ipc/writer.cc @@ -54,7 +54,8 @@ #include "arrow/util/logging.h" #include "arrow/util/make_unique.h" #include "arrow/util/parallel.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_array_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/json/chunked_builder_test.cc b/cpp/src/arrow/json/chunked_builder_test.cc index d04f0d5c9bd2f..2d89ab9b026a6 100644 --- a/cpp/src/arrow/json/chunked_builder_test.cc +++ b/cpp/src/arrow/json/chunked_builder_test.cc @@ -27,6 +27,7 @@ #include "arrow/json/options.h" #include "arrow/json/test_common.h" #include "arrow/table.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/util/task_group.h" #include "arrow/util/thread_pool.h" diff --git a/cpp/src/arrow/json/parser.cc b/cpp/src/arrow/json/parser.cc index 16a2fa1ce56ba..815fa7dc7b7fd 100644 --- a/cpp/src/arrow/json/parser.cc +++ b/cpp/src/arrow/json/parser.cc @@ -38,7 +38,7 @@ #include "arrow/util/make_unique.h" #include "arrow/util/string_view.h" #include "arrow/util/trie.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/json/test_common.h b/cpp/src/arrow/json/test_common.h index 488da071dafe7..508be0c9102bb 100644 --- a/cpp/src/arrow/json/test_common.h +++ b/cpp/src/arrow/json/test_common.h @@ -24,6 +24,8 @@ #include #include +#include "arrow/array.h" +#include "arrow/array/builder_binary.h" #include "arrow/io/memory.h" #include "arrow/json/converter.h" #include "arrow/json/options.h" @@ -33,7 +35,8 @@ #include "arrow/type.h" #include "arrow/util/checked_cast.h" #include "arrow/util/string_view.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" + #include "rapidjson/document.h" #include "rapidjson/prettywriter.h" #include "rapidjson/reader.h" diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc index 3ec2961fae2ac..37135ed3ee84f 100644 --- a/cpp/src/arrow/pretty_print.cc +++ b/cpp/src/arrow/pretty_print.cc @@ -43,7 +43,7 @@ #include "arrow/util/string.h" #include "arrow/util/string_view.h" #include "arrow/vendored/datetime.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_array_inline.h" namespace arrow { diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 42995de32e0a9..7b47a05630ca4 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -29,6 +29,7 @@ #include "arrow/array.h" #include "arrow/table.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/util/key_value_metadata.h" diff --git a/cpp/src/arrow/python/arrow_to_pandas.cc b/cpp/src/arrow/python/arrow_to_pandas.cc index 3f386ad529ad8..41e537191a3cd 100644 --- a/cpp/src/arrow/python/arrow_to_pandas.cc +++ b/cpp/src/arrow/python/arrow_to_pandas.cc @@ -44,7 +44,7 @@ #include "arrow/util/macros.h" #include "arrow/util/parallel.h" #include "arrow/util/string_view.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" #include "arrow/compute/api.h" diff --git a/cpp/src/arrow/python/numpy_to_arrow.cc b/cpp/src/arrow/python/numpy_to_arrow.cc index 5b4c12ab03046..b61218462067b 100644 --- a/cpp/src/arrow/python/numpy_to_arrow.cc +++ b/cpp/src/arrow/python/numpy_to_arrow.cc @@ -45,7 +45,7 @@ #include "arrow/util/macros.h" #include "arrow/util/string.h" #include "arrow/util/utf8.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" #include "arrow/compute/api_scalar.h" diff --git a/cpp/src/arrow/python/python_to_arrow.cc b/cpp/src/arrow/python/python_to_arrow.cc index 10250d165747f..21ced0898ef06 100644 --- a/cpp/src/arrow/python/python_to_arrow.cc +++ b/cpp/src/arrow/python/python_to_arrow.cc @@ -51,7 +51,7 @@ #include "arrow/python/iterators.h" #include "arrow/python/numpy_convert.h" #include "arrow/python/type_traits.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/record_batch_test.cc b/cpp/src/arrow/record_batch_test.cc index b679870989685..32dc04984835a 100644 --- a/cpp/src/arrow/record_batch_test.cc +++ b/cpp/src/arrow/record_batch_test.cc @@ -25,19 +25,20 @@ #include #include "arrow/array/array_base.h" +#include "arrow/array/array_nested.h" #include "arrow/array/data.h" #include "arrow/array/util.h" #include "arrow/chunked_array.h" #include "arrow/status.h" #include "arrow/table.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" #include "arrow/type.h" #include "arrow/util/key_value_metadata.h" namespace arrow { -class TestRecordBatch : public TestBase {}; +class TestRecordBatch : public ::testing::Test {}; TEST_F(TestRecordBatch, Equals) { const int length = 10; @@ -53,9 +54,11 @@ TEST_F(TestRecordBatch, Equals) { auto schema2 = ::arrow::schema({f0, f1}); auto schema3 = ::arrow::schema({f0, f1, f2}, metadata); - auto a0 = MakeRandomArray(length); - auto a1 = MakeRandomArray(length); - auto a2 = MakeRandomArray(length); + random::RandomArrayGenerator gen(42); + + auto a0 = gen.ArrayOf(int32(), length); + auto a1 = gen.ArrayOf(uint8(), length); + auto a2 = gen.ArrayOf(int16(), length); auto b1 = RecordBatch::Make(schema, length, {a0, a1, a2}); auto b2 = RecordBatch::Make(schema3, length, {a0, a1, a2}); @@ -80,10 +83,12 @@ TEST_F(TestRecordBatch, Validate) { auto schema = ::arrow::schema({f0, f1, f2}); - auto a0 = MakeRandomArray(length); - auto a1 = MakeRandomArray(length); - auto a2 = MakeRandomArray(length); - auto a3 = MakeRandomArray(5); + random::RandomArrayGenerator gen(42); + + auto a0 = gen.ArrayOf(int32(), length); + auto a1 = gen.ArrayOf(uint8(), length); + auto a2 = gen.ArrayOf(int16(), length); + auto a3 = gen.ArrayOf(int16(), 5); auto b1 = RecordBatch::Make(schema, length, {a0, a1, a2}); @@ -108,8 +113,10 @@ TEST_F(TestRecordBatch, Slice) { std::vector> fields = {f0, f1, f2}; auto schema = ::arrow::schema(fields); - auto a0 = MakeRandomArray(length); - auto a1 = MakeRandomArray(length); + random::RandomArrayGenerator gen(42); + + auto a0 = gen.ArrayOf(int32(), length); + auto a1 = gen.ArrayOf(uint8(), length); auto a2 = ArrayFromJSON(int8(), "[0, 1, 2, 3, 4, 5, 6]"); auto batch = RecordBatch::Make(schema, length, {a0, a1, a2}); @@ -144,9 +151,11 @@ TEST_F(TestRecordBatch, AddColumn) { auto schema2 = ::arrow::schema({field2, field3}); auto schema3 = ::arrow::schema({field2}); - auto array1 = MakeRandomArray(length); - auto array2 = MakeRandomArray(length); - auto array3 = MakeRandomArray(length); + random::RandomArrayGenerator gen(42); + + auto array1 = gen.ArrayOf(int32(), length); + auto array2 = gen.ArrayOf(uint8(), length); + auto array3 = gen.ArrayOf(int16(), length); auto batch1 = RecordBatch::Make(schema1, length, {array1, array2}); auto batch2 = RecordBatch::Make(schema2, length, {array2, array3}); @@ -160,7 +169,7 @@ TEST_F(TestRecordBatch, AddColumn) { ASSERT_RAISES(Invalid, batch.AddColumn(-1, field1, array1)); // Negative test with wrong length - auto longer_col = MakeRandomArray(length + 1); + auto longer_col = gen.ArrayOf(int32(), length + 1); ASSERT_RAISES(Invalid, batch.AddColumn(0, field1, longer_col)); // Negative test with mismatch type @@ -189,9 +198,11 @@ TEST_F(TestRecordBatch, SetColumn) { auto schema2 = ::arrow::schema({field1, field3}); auto schema3 = ::arrow::schema({field3, field2}); - auto array1 = MakeRandomArray(length); - auto array2 = MakeRandomArray(length); - auto array3 = MakeRandomArray(length); + random::RandomArrayGenerator gen(42); + + auto array1 = gen.ArrayOf(int32(), length); + auto array2 = gen.ArrayOf(uint8(), length); + auto array3 = gen.ArrayOf(int16(), length); auto batch1 = RecordBatch::Make(schema1, length, {array1, array2}); auto batch2 = RecordBatch::Make(schema2, length, {array1, array3}); @@ -204,7 +215,7 @@ TEST_F(TestRecordBatch, SetColumn) { ASSERT_RAISES(Invalid, batch.SetColumn(-1, field1, array1)); // Negative test with wrong length - auto longer_col = MakeRandomArray(length + 1); + auto longer_col = gen.ArrayOf(int32(), length + 1); ASSERT_RAISES(Invalid, batch.SetColumn(0, field1, longer_col)); // Negative test with mismatch type @@ -229,9 +240,11 @@ TEST_F(TestRecordBatch, RemoveColumn) { auto schema3 = ::arrow::schema({field1, field3}); auto schema4 = ::arrow::schema({field1, field2}); - auto array1 = MakeRandomArray(length); - auto array2 = MakeRandomArray(length); - auto array3 = MakeRandomArray(length); + random::RandomArrayGenerator gen(42); + + auto array1 = gen.ArrayOf(int32(), length); + auto array2 = gen.ArrayOf(uint8(), length); + auto array3 = gen.ArrayOf(int16(), length); auto batch1 = RecordBatch::Make(schema1, length, {array1, array2, array3}); auto batch2 = RecordBatch::Make(schema2, length, {array2, array3}); @@ -264,9 +277,11 @@ TEST_F(TestRecordBatch, SelectColumns) { auto schema1 = ::arrow::schema({field1, field2, field3}); - auto array1 = MakeRandomArray(length); - auto array2 = MakeRandomArray(length); - auto array3 = MakeRandomArray(length); + random::RandomArrayGenerator gen(42); + + auto array1 = gen.ArrayOf(int32(), length); + auto array2 = gen.ArrayOf(uint8(), length); + auto array3 = gen.ArrayOf(int16(), length); auto batch = RecordBatch::Make(schema1, length, {array1, array2, array3}); @@ -286,9 +301,11 @@ TEST_F(TestRecordBatch, SelectColumns) { TEST_F(TestRecordBatch, RemoveColumnEmpty) { const int length = 10; + random::RandomArrayGenerator gen(42); + auto field1 = field("f1", int32()); auto schema1 = ::arrow::schema({field1}); - auto array1 = MakeRandomArray(length); + auto array1 = gen.ArrayOf(int32(), length); auto batch1 = RecordBatch::Make(schema1, length, {array1}); ASSERT_OK_AND_ASSIGN(auto empty, batch1->RemoveColumn(0)); @@ -308,7 +325,8 @@ TEST_F(TestRecordBatch, ToFromEmptyStructArray) { } TEST_F(TestRecordBatch, FromStructArrayInvalidType) { - ASSERT_RAISES(TypeError, RecordBatch::FromStructArray(MakeRandomArray(10))); + random::RandomArrayGenerator gen(42); + ASSERT_RAISES(TypeError, RecordBatch::FromStructArray(gen.ArrayOf(int32(), 6))); } TEST_F(TestRecordBatch, FromStructArrayInvalidNullCount) { diff --git a/cpp/src/arrow/scalar.cc b/cpp/src/arrow/scalar.cc index f268e75a50ba0..23c07e6ade296 100644 --- a/cpp/src/arrow/scalar.cc +++ b/cpp/src/arrow/scalar.cc @@ -36,7 +36,7 @@ #include "arrow/util/unreachable.h" #include "arrow/util/utf8.h" #include "arrow/util/value_parsing.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_scalar_inline.h" namespace arrow { diff --git a/cpp/src/arrow/scalar.h b/cpp/src/arrow/scalar.h index b99e1144b90f1..7a33126eaeee7 100644 --- a/cpp/src/arrow/scalar.h +++ b/cpp/src/arrow/scalar.h @@ -36,6 +36,7 @@ #include "arrow/util/decimal.h" #include "arrow/util/string_view.h" #include "arrow/util/visibility.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/scalar_test.cc b/cpp/src/arrow/scalar_test.cc index 7289d3aa84df6..c9b3a2217bc6c 100644 --- a/cpp/src/arrow/scalar_test.cc +++ b/cpp/src/arrow/scalar_test.cc @@ -26,12 +26,15 @@ #include #include +#include "arrow/array.h" +#include "arrow/array/util.h" #include "arrow/buffer.h" #include "arrow/memory_pool.h" #include "arrow/scalar.h" #include "arrow/status.h" #include "arrow/testing/extension_type.h" #include "arrow/testing/gtest_util.h" +#include "arrow/testing/util.h" #include "arrow/type_traits.h" namespace arrow { diff --git a/cpp/src/arrow/sparse_tensor.cc b/cpp/src/arrow/sparse_tensor.cc index 03d59c3d79311..7e48bb80f0863 100644 --- a/cpp/src/arrow/sparse_tensor.cc +++ b/cpp/src/arrow/sparse_tensor.cc @@ -27,7 +27,7 @@ #include "arrow/type_traits.h" #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/sparse_tensor_test.cc b/cpp/src/arrow/sparse_tensor_test.cc index 219cdd9347277..5105724e68f78 100644 --- a/cpp/src/arrow/sparse_tensor_test.cc +++ b/cpp/src/arrow/sparse_tensor_test.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/cpp/src/arrow/stl_test.cc b/cpp/src/arrow/stl_test.cc index 159d1d98312c1..42b54d2207795 100644 --- a/cpp/src/arrow/stl_test.cc +++ b/cpp/src/arrow/stl_test.cc @@ -423,26 +423,16 @@ TEST(TestTupleVectorFromTable, PrimitiveTypes) { field("column9", boolean(), false), field("column10", utf8(), false)})); // Construct expected arrays - std::shared_ptr int8_array; - ArrayFromVector({-1, -10}, &int8_array); - std::shared_ptr int16_array; - ArrayFromVector({-2, -20}, &int16_array); - std::shared_ptr int32_array; - ArrayFromVector({-3, -30}, &int32_array); - std::shared_ptr int64_array; - ArrayFromVector({-4, -40}, &int64_array); - std::shared_ptr uint8_array; - ArrayFromVector({1, 10}, &uint8_array); - std::shared_ptr uint16_array; - ArrayFromVector({2, 20}, &uint16_array); - std::shared_ptr uint32_array; - ArrayFromVector({3, 30}, &uint32_array); - std::shared_ptr uint64_array; - ArrayFromVector({4, 40}, &uint64_array); - std::shared_ptr bool_array; - ArrayFromVector({true, false}, &bool_array); - std::shared_ptr string_array; - ArrayFromVector({"Tests", "Other"}, &string_array); + auto int8_array = ArrayFromJSON(int8(), "[-1, -10]"); + auto int16_array = ArrayFromJSON(int16(), "[-2, -20]"); + auto int32_array = ArrayFromJSON(int32(), "[-3, -30]"); + auto int64_array = ArrayFromJSON(int64(), "[-4, -40]"); + auto uint8_array = ArrayFromJSON(uint8(), "[1, 10]"); + auto uint16_array = ArrayFromJSON(uint16(), "[2, 20]"); + auto uint32_array = ArrayFromJSON(uint32(), "[3, 30]"); + auto uint64_array = ArrayFromJSON(uint64(), "[4, 40]"); + auto bool_array = ArrayFromJSON(boolean(), "[true, false]"); + auto string_array = ArrayFromJSON(utf8(), R"(["Tests", "Other"])"); auto table = Table::Make( schema, {int8_array, int16_array, int32_array, int64_array, uint8_array, uint16_array, uint32_array, uint64_array, bool_array, string_array}); diff --git a/cpp/src/arrow/table_builder_test.cc b/cpp/src/arrow/table_builder_test.cc index c730913122ab6..e04a4a44783b7 100644 --- a/cpp/src/arrow/table_builder_test.cc +++ b/cpp/src/arrow/table_builder_test.cc @@ -31,17 +31,18 @@ #include "arrow/record_batch.h" #include "arrow/status.h" #include "arrow/table_builder.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" +#include "arrow/type_fwd.h" #include "arrow/util/checked_cast.h" namespace arrow { using internal::checked_cast; -class TestRecordBatchBuilder : public TestBase { - public: +class TestRecordBatchBuilder : public ::testing::Test { + protected: + MemoryPool* pool_ = default_memory_pool(); }; std::shared_ptr ExampleSchema1() { diff --git a/cpp/src/arrow/table_test.cc b/cpp/src/arrow/table_test.cc index 92d13ac181256..3f6589fdf947d 100644 --- a/cpp/src/arrow/table_test.cc +++ b/cpp/src/arrow/table_test.cc @@ -25,19 +25,20 @@ #include #include "arrow/array/array_base.h" +#include "arrow/array/builder_binary.h" #include "arrow/array/data.h" #include "arrow/array/util.h" #include "arrow/chunked_array.h" #include "arrow/record_batch.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" #include "arrow/type.h" #include "arrow/util/key_value_metadata.h" namespace arrow { -class TestTable : public TestBase { +class TestTable : public ::testing::Test { public: void MakeExample1(int length) { auto f0 = field("f0", int32()); @@ -47,8 +48,8 @@ class TestTable : public TestBase { std::vector> fields = {f0, f1, f2}; schema_ = std::make_shared(fields); - arrays_ = {MakeRandomArray(length), MakeRandomArray(length), - MakeRandomArray(length)}; + arrays_ = {gen_.ArrayOf(int32(), length), gen_.ArrayOf(uint8(), length), + gen_.ArrayOf(int16(), length)}; columns_ = {std::make_shared(arrays_[0]), std::make_shared(arrays_[1]), @@ -56,6 +57,7 @@ class TestTable : public TestBase { } protected: + random::RandomArrayGenerator gen_{42}; std::shared_ptr table_; std::shared_ptr schema_; @@ -113,15 +115,14 @@ TEST_F(TestTable, InvalidColumns) { table_ = Table::Make(schema_, columns_, length - 1); ASSERT_RAISES(Invalid, table_->ValidateFull()); - columns_.clear(); - // Wrong number of columns + columns_.clear(); table_ = Table::Make(schema_, columns_, length); ASSERT_RAISES(Invalid, table_->ValidateFull()); - columns_ = {std::make_shared(MakeRandomArray(length)), - std::make_shared(MakeRandomArray(length)), - std::make_shared(MakeRandomArray(length - 1))}; + columns_ = {std::make_shared(gen_.ArrayOf(int32(), length)), + std::make_shared(gen_.ArrayOf(uint8(), length)), + std::make_shared(gen_.ArrayOf(int16(), length - 1))}; table_ = Table::Make(schema_, columns_, length); ASSERT_RAISES(Invalid, table_->ValidateFull()); @@ -167,9 +168,12 @@ TEST_F(TestTable, Equals) { ASSERT_FALSE(table_->Equals(*other)); // Differing columns std::vector> other_columns = { - std::make_shared(MakeRandomArray(length, 10)), - std::make_shared(MakeRandomArray(length, 10)), - std::make_shared(MakeRandomArray(length, 10))}; + std::make_shared( + gen_.ArrayOf(int32(), length, /*null_probability=*/0.3)), + std::make_shared( + gen_.ArrayOf(uint8(), length, /*null_probability=*/0.3)), + std::make_shared( + gen_.ArrayOf(int16(), length, /*null_probability=*/0.3))}; other = Table::Make(schema_, other_columns); ASSERT_FALSE(table_->Equals(*other)); @@ -428,9 +432,8 @@ TEST_F(TestPromoteTableToSchema, IncompatibleNullity) { TEST_F(TestPromoteTableToSchema, DuplicateFieldNames) { const int length = 10; - auto table = Table::Make( - schema({field("field", int32()), field("field", null())}), - {MakeRandomArray(length), MakeRandomArray(length)}); + auto table = Table::Make(schema({field("field", int32()), field("field", null())}), + {gen_.ArrayOf(int32(), length), gen_.ArrayOf(null(), length)}); ASSERT_RAISES(Invalid, PromoteTableToSchema(table, schema({field("field", int32())}))); } @@ -439,7 +442,7 @@ TEST_F(TestPromoteTableToSchema, TableFieldAbsentFromSchema) { const int length = 10; auto table = - Table::Make(schema({field("f0", int32())}), {MakeRandomArray(length)}); + Table::Make(schema({field("f0", int32())}), {gen_.ArrayOf(int32(), length)}); std::shared_ptr
result; ASSERT_RAISES(Invalid, PromoteTableToSchema(table, schema({field("f1", int32())}))); @@ -460,7 +463,7 @@ class ConcatenateTablesWithPromotionTest : public TestTable { std::vector> fields = {f0, f1}; schema_ = std::make_shared(fields); - arrays_ = {MakeRandomArray(length), MakeRandomArray(length)}; + arrays_ = {gen_.ArrayOf(int32(), length), gen_.ArrayOf(null(), length)}; columns_ = {std::make_shared(arrays_[0]), std::make_shared(arrays_[1])}; @@ -612,7 +615,7 @@ TEST_F(TestTable, RemoveColumnEmpty) { auto f0 = field("f0", int32()); auto schema = ::arrow::schema({f0}); - auto a0 = MakeRandomArray(length); + auto a0 = gen_.ArrayOf(int32(), length); auto table = Table::Make(schema, {std::make_shared(a0)}); @@ -639,8 +642,7 @@ TEST_F(TestTable, AddColumn) { ASSERT_RAISES(Invalid, table.AddColumn(-1, f0, columns_[0])); // Add column with wrong length - auto longer_col = - std::make_shared(MakeRandomArray(length + 1)); + auto longer_col = std::make_shared(gen_.ArrayOf(int32(), length + 1)); ASSERT_RAISES(Invalid, table.AddColumn(0, f0, longer_col)); // Add column 0 in different places @@ -675,15 +677,18 @@ TEST_F(TestTable, AddColumn) { ASSERT_TRUE(result->Equals(*expected)); } -class TestTableBatchReader : public TestBase {}; +class TestTableBatchReader : public ::testing::Test { + protected: + random::RandomArrayGenerator gen_{42}; +}; TEST_F(TestTableBatchReader, ReadNext) { ArrayVector c1, c2; - auto a1 = MakeRandomArray(10); - auto a2 = MakeRandomArray(20); - auto a3 = MakeRandomArray(30); - auto a4 = MakeRandomArray(10); + auto a1 = gen_.ArrayOf(int32(), 10); + auto a2 = gen_.ArrayOf(int32(), 20); + auto a3 = gen_.ArrayOf(int32(), 30); + auto a4 = gen_.ArrayOf(int32(), 10); auto sch1 = arrow::schema({field("f1", int32()), field("f2", int32())}); @@ -731,9 +736,9 @@ TEST_F(TestTableBatchReader, ReadNext) { } TEST_F(TestTableBatchReader, Chunksize) { - auto a1 = MakeRandomArray(10); - auto a2 = MakeRandomArray(20); - auto a3 = MakeRandomArray(10); + auto a1 = gen_.ArrayOf(int32(), 10); + auto a2 = gen_.ArrayOf(int32(), 20); + auto a3 = gen_.ArrayOf(int32(), 10); auto sch1 = arrow::schema({field("f1", int32())}); diff --git a/cpp/src/arrow/tensor.cc b/cpp/src/arrow/tensor.cc index 30ae8c4655531..dd99370c97926 100644 --- a/cpp/src/arrow/tensor.cc +++ b/cpp/src/arrow/tensor.cc @@ -33,7 +33,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/int_util_internal.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/tensor/coo_converter.cc b/cpp/src/arrow/tensor/coo_converter.cc index 2124d0a4e4b79..148aa7c1b7569 100644 --- a/cpp/src/arrow/tensor/coo_converter.cc +++ b/cpp/src/arrow/tensor/coo_converter.cc @@ -28,7 +28,7 @@ #include "arrow/type.h" #include "arrow/util/checked_cast.h" #include "arrow/util/macros.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/tensor/csf_converter.cc b/cpp/src/arrow/tensor/csf_converter.cc index 77a71d8a12e4b..f8facfd957c26 100644 --- a/cpp/src/arrow/tensor/csf_converter.cc +++ b/cpp/src/arrow/tensor/csf_converter.cc @@ -30,7 +30,7 @@ #include "arrow/type.h" #include "arrow/util/checked_cast.h" #include "arrow/util/sort.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/tensor/csx_converter.cc b/cpp/src/arrow/tensor/csx_converter.cc index 137b5d3202f22..882e277efbb0d 100644 --- a/cpp/src/arrow/tensor/csx_converter.cc +++ b/cpp/src/arrow/tensor/csx_converter.cc @@ -26,7 +26,7 @@ #include "arrow/status.h" #include "arrow/type.h" #include "arrow/util/checked_cast.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/tensor/tensor_conversion_benchmark.cc b/cpp/src/arrow/tensor/tensor_conversion_benchmark.cc index 8456b2c4e29ce..2101cd5dddbf5 100644 --- a/cpp/src/arrow/tensor/tensor_conversion_benchmark.cc +++ b/cpp/src/arrow/tensor/tensor_conversion_benchmark.cc @@ -17,11 +17,12 @@ #include "benchmark/benchmark.h" +#include +#include + #include "arrow/sparse_tensor.h" #include "arrow/testing/gtest_util.h" -#include - namespace arrow { enum ContiguousType { ROW_MAJOR, COLUMN_MAJOR, STRIDED }; diff --git a/cpp/src/arrow/testing/builder.h b/cpp/src/arrow/testing/builder.h new file mode 100644 index 0000000000000..f8a375589cea9 --- /dev/null +++ b/cpp/src/arrow/testing/builder.h @@ -0,0 +1,237 @@ +// 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 +#include +#include + +#include "arrow/array.h" +#include "arrow/array/builder_binary.h" +#include "arrow/array/builder_primitive.h" +#include "arrow/array/builder_time.h" +#include "arrow/buffer.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/util/bit_util.h" +#include "arrow/visit_type_inline.h" + +namespace arrow { + +// ArrayFromVector: construct an Array from vectors of C values + +template +void ArrayFromVector(const std::shared_ptr& type, + const std::vector& is_valid, const std::vector& values, + std::shared_ptr* out) { + auto type_id = TYPE::type_id; + ASSERT_EQ(type_id, type->id()) + << "template parameter and concrete DataType instance don't agree"; + + std::unique_ptr builder_ptr; + ASSERT_OK(MakeBuilder(default_memory_pool(), type, &builder_ptr)); + // Get the concrete builder class to access its Append() specializations + auto& builder = dynamic_cast::BuilderType&>(*builder_ptr); + + for (size_t i = 0; i < values.size(); ++i) { + if (is_valid[i]) { + ASSERT_OK(builder.Append(values[i])); + } else { + ASSERT_OK(builder.AppendNull()); + } + } + ASSERT_OK(builder.Finish(out)); +} + +template +void ArrayFromVector(const std::shared_ptr& type, + const std::vector& values, std::shared_ptr* out) { + auto type_id = TYPE::type_id; + ASSERT_EQ(type_id, type->id()) + << "template parameter and concrete DataType instance don't agree"; + + std::unique_ptr builder_ptr; + ASSERT_OK(MakeBuilder(default_memory_pool(), type, &builder_ptr)); + // Get the concrete builder class to access its Append() specializations + auto& builder = dynamic_cast::BuilderType&>(*builder_ptr); + + for (size_t i = 0; i < values.size(); ++i) { + ASSERT_OK(builder.Append(values[i])); + } + ASSERT_OK(builder.Finish(out)); +} + +// Overloads without a DataType argument, for parameterless types + +template +void ArrayFromVector(const std::vector& is_valid, const std::vector& values, + std::shared_ptr* out) { + auto type = TypeTraits::type_singleton(); + ArrayFromVector(type, is_valid, values, out); +} + +template +void ArrayFromVector(const std::vector& values, std::shared_ptr* out) { + auto type = TypeTraits::type_singleton(); + ArrayFromVector(type, values, out); +} + +// ChunkedArrayFromVector: construct a ChunkedArray from vectors of C values + +template +void ChunkedArrayFromVector(const std::shared_ptr& type, + const std::vector>& is_valid, + const std::vector>& values, + std::shared_ptr* out) { + ArrayVector chunks; + ASSERT_EQ(is_valid.size(), values.size()); + for (size_t i = 0; i < values.size(); ++i) { + std::shared_ptr array; + ArrayFromVector(type, is_valid[i], values[i], &array); + chunks.push_back(array); + } + *out = std::make_shared(chunks); +} + +template +void ChunkedArrayFromVector(const std::shared_ptr& type, + const std::vector>& values, + std::shared_ptr* out) { + ArrayVector chunks; + for (size_t i = 0; i < values.size(); ++i) { + std::shared_ptr array; + ArrayFromVector(type, values[i], &array); + chunks.push_back(array); + } + *out = std::make_shared(chunks); +} + +// Overloads without a DataType argument, for parameterless types + +template +void ChunkedArrayFromVector(const std::vector>& is_valid, + const std::vector>& values, + std::shared_ptr* out) { + auto type = TypeTraits::type_singleton(); + ChunkedArrayFromVector(type, is_valid, values, out); +} + +template +void ChunkedArrayFromVector(const std::vector>& values, + std::shared_ptr* out) { + auto type = TypeTraits::type_singleton(); + ChunkedArrayFromVector(type, values, out); +} + +template +void FinishAndCheckPadding(BuilderType* builder, std::shared_ptr* out) { + ASSERT_OK_AND_ASSIGN(*out, builder->Finish()); + AssertZeroPadded(**out); + TestInitialized(**out); +} + +template +Status MakeArray(const std::vector& valid_bytes, const std::vector& values, + int64_t size, Builder* builder, std::shared_ptr* out) { + // Append the first 1000 + for (int64_t i = 0; i < size; ++i) { + if (valid_bytes[i] > 0) { + RETURN_NOT_OK(builder->Append(values[i])); + } else { + RETURN_NOT_OK(builder->AppendNull()); + } + } + return builder->Finish(out); +} + +template +struct VisitBuilderImpl { + template ::BuilderType, + // need to let SFINAE drop this Visit when it would result in + // [](NullBuilder*){}(double_builder) + typename = decltype(std::declval()(std::declval()))> + Status Visit(const T&) { + fn_(internal::checked_cast(builder_)); + return Status::OK(); + } + + Status Visit(const DataType& t) { + return Status::NotImplemented("visiting builders of type ", t); + } + + Status Visit() { return VisitTypeInline(*builder_->type(), this); } + + ArrayBuilder* builder_; + Fn fn_; +}; + +template +Status VisitBuilder(ArrayBuilder* builder, Fn&& fn) { + return VisitBuilderImpl{builder, std::forward(fn)}.Visit(); +} + +template +Result> ArrayFromBuilderVisitor( + const std::shared_ptr& type, int64_t initial_capacity, + int64_t visitor_repetitions, Fn&& fn) { + std::unique_ptr builder; + RETURN_NOT_OK(MakeBuilder(default_memory_pool(), type, &builder)); + + if (initial_capacity != 0) { + RETURN_NOT_OK(builder->Resize(initial_capacity)); + } + + for (int64_t i = 0; i < visitor_repetitions; ++i) { + RETURN_NOT_OK(VisitBuilder(builder.get(), std::forward(fn))); + } + + std::shared_ptr out; + RETURN_NOT_OK(builder->Finish(&out)); + return std::move(out); +} + +template +Result> ArrayFromBuilderVisitor( + const std::shared_ptr& type, int64_t length, Fn&& fn) { + return ArrayFromBuilderVisitor(type, length, length, std::forward(fn)); +} + +template +static inline Status GetBitmapFromVector(const std::vector& is_valid, + std::shared_ptr* result) { + size_t length = is_valid.size(); + + ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateEmptyBitmap(length)); + + uint8_t* bitmap = buffer->mutable_data(); + for (size_t i = 0; i < static_cast(length); ++i) { + if (is_valid[i]) { + bit_util::SetBit(bitmap, i); + } + } + + *result = buffer; + return Status::OK(); +} + +template +inline void BitmapFromVector(const std::vector& is_valid, + std::shared_ptr* out) { + ASSERT_OK(GetBitmapFromVector(is_valid, out)); +} + +} // namespace arrow diff --git a/cpp/src/arrow/testing/generator.cc b/cpp/src/arrow/testing/generator.cc index 33371d55c6d95..8f05cc6817d53 100644 --- a/cpp/src/arrow/testing/generator.cc +++ b/cpp/src/arrow/testing/generator.cc @@ -26,9 +26,12 @@ #include "arrow/array.h" #include "arrow/buffer.h" +#include "arrow/builder.h" +#include "arrow/record_batch.h" +#include "arrow/scalar.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" -#include "arrow/type_fwd.h" #include "arrow/type_traits.h" #include "arrow/util/bit_util.h" @@ -95,6 +98,75 @@ std::shared_ptr ConstantArrayGenerator::String(int64_t size, return ConstantArray(size, value); } +std::shared_ptr ConstantArrayGenerator::Zeroes( + int64_t size, const std::shared_ptr& type) { + switch (type->id()) { + case Type::NA: + return std::make_shared(size); + case Type::BOOL: + return Boolean(size); + case Type::UINT8: + return UInt8(size); + case Type::INT8: + return Int8(size); + case Type::UINT16: + return UInt16(size); + case Type::INT16: + return Int16(size); + case Type::UINT32: + return UInt32(size); + case Type::INT32: + return Int32(size); + case Type::UINT64: + return UInt64(size); + case Type::INT64: + return Int64(size); + case Type::TIME64: + case Type::DATE64: + case Type::TIMESTAMP: { + EXPECT_OK_AND_ASSIGN(auto viewed, Int64(size)->View(type)); + return viewed; + } + case Type::INTERVAL_DAY_TIME: + case Type::INTERVAL_MONTHS: + case Type::TIME32: + case Type::DATE32: { + EXPECT_OK_AND_ASSIGN(auto viewed, Int32(size)->View(type)); + return viewed; + } + case Type::FLOAT: + return Float32(size); + case Type::DOUBLE: + return Float64(size); + case Type::STRING: + return String(size); + default: + return nullptr; + } +} + +std::shared_ptr ConstantArrayGenerator::Zeroes( + int64_t size, const std::shared_ptr& schema) { + std::vector> arrays; + + for (const auto& field : schema->fields()) { + arrays.emplace_back(Zeroes(size, field->type())); + } + + return RecordBatch::Make(schema, size, arrays); +} + +std::shared_ptr ConstantArrayGenerator::Repeat( + int64_t n_batch, const std::shared_ptr batch) { + std::vector> batches(static_cast(n_batch), batch); + return *RecordBatchReader::Make(batches); +} + +std::shared_ptr ConstantArrayGenerator::Zeroes( + int64_t n_batch, int64_t batch_size, const std::shared_ptr& schema) { + return Repeat(n_batch, Zeroes(batch_size, schema)); +} + Result> ScalarVectorToArray(const ScalarVector& scalars) { if (scalars.empty()) { return Status::NotImplemented("ScalarVectorToArray with no scalars"); diff --git a/cpp/src/arrow/testing/generator.h b/cpp/src/arrow/testing/generator.h index c300022432a94..9d9ed1a5772fd 100644 --- a/cpp/src/arrow/testing/generator.h +++ b/cpp/src/arrow/testing/generator.h @@ -22,10 +22,9 @@ #include #include -#include "arrow/record_batch.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/visibility.h" -#include "arrow/type.h" +#include "arrow/type_fwd.h" namespace arrow { @@ -37,7 +36,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Boolean(int64_t size, bool value = false); + static std::shared_ptr Boolean(int64_t size, bool value = false); /// \brief Generates a constant UInt8Array /// @@ -45,7 +44,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr UInt8(int64_t size, uint8_t value = 0); + static std::shared_ptr UInt8(int64_t size, uint8_t value = 0); /// \brief Generates a constant Int8Array /// @@ -53,7 +52,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Int8(int64_t size, int8_t value = 0); + static std::shared_ptr Int8(int64_t size, int8_t value = 0); /// \brief Generates a constant UInt16Array /// @@ -61,7 +60,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr UInt16(int64_t size, uint16_t value = 0); + static std::shared_ptr UInt16(int64_t size, uint16_t value = 0); /// \brief Generates a constant UInt16Array /// @@ -69,7 +68,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Int16(int64_t size, int16_t value = 0); + static std::shared_ptr Int16(int64_t size, int16_t value = 0); /// \brief Generates a constant UInt32Array /// @@ -77,7 +76,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr UInt32(int64_t size, uint32_t value = 0); + static std::shared_ptr UInt32(int64_t size, uint32_t value = 0); /// \brief Generates a constant UInt32Array /// @@ -85,7 +84,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Int32(int64_t size, int32_t value = 0); + static std::shared_ptr Int32(int64_t size, int32_t value = 0); /// \brief Generates a constant UInt64Array /// @@ -93,7 +92,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr UInt64(int64_t size, uint64_t value = 0); + static std::shared_ptr UInt64(int64_t size, uint64_t value = 0); /// \brief Generates a constant UInt64Array /// @@ -101,7 +100,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Int64(int64_t size, int64_t value = 0); + static std::shared_ptr Int64(int64_t size, int64_t value = 0); /// \brief Generates a constant Float32Array /// @@ -109,7 +108,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Float32(int64_t size, float value = 0); + static std::shared_ptr Float32(int64_t size, float value = 0); /// \brief Generates a constant Float64Array /// @@ -117,7 +116,7 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr Float64(int64_t size, double value = 0); + static std::shared_ptr Float64(int64_t size, double value = 0); /// \brief Generates a constant StringArray /// @@ -125,10 +124,10 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] value to repeat /// /// \return a generated Array - static std::shared_ptr String(int64_t size, std::string value = ""); + static std::shared_ptr String(int64_t size, std::string value = ""); template - static std::shared_ptr Numeric(int64_t size, CType value = 0) { + static std::shared_ptr Numeric(int64_t size, CType value = 0) { switch (ArrowType::type_id) { case Type::BOOL: return Boolean(size, static_cast(value)); @@ -163,52 +162,8 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] type the type of the Array /// /// \return a generated Array - static std::shared_ptr Zeroes(int64_t size, - const std::shared_ptr& type) { - switch (type->id()) { - case Type::NA: - return std::make_shared(size); - case Type::BOOL: - return Boolean(size); - case Type::UINT8: - return UInt8(size); - case Type::INT8: - return Int8(size); - case Type::UINT16: - return UInt16(size); - case Type::INT16: - return Int16(size); - case Type::UINT32: - return UInt32(size); - case Type::INT32: - return Int32(size); - case Type::UINT64: - return UInt64(size); - case Type::INT64: - return Int64(size); - case Type::TIME64: - case Type::DATE64: - case Type::TIMESTAMP: { - EXPECT_OK_AND_ASSIGN(auto viewed, Int64(size)->View(type)); - return viewed; - } - case Type::INTERVAL_DAY_TIME: - case Type::INTERVAL_MONTHS: - case Type::TIME32: - case Type::DATE32: { - EXPECT_OK_AND_ASSIGN(auto viewed, Int32(size)->View(type)); - return viewed; - } - case Type::FLOAT: - return Float32(size); - case Type::DOUBLE: - return Float64(size); - case Type::STRING: - return String(size); - default: - return nullptr; - } - } + static std::shared_ptr Zeroes(int64_t size, + const std::shared_ptr& type); /// \brief Generates a RecordBatch of zeroes /// @@ -218,16 +173,8 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// This function is handy to return of RecordBatch of a desired shape. /// /// \return a generated RecordBatch - static std::shared_ptr Zeroes( - int64_t size, const std::shared_ptr& schema) { - std::vector> arrays; - - for (const auto& field : schema->fields()) { - arrays.emplace_back(Zeroes(size, field->type())); - } - - return RecordBatch::Make(schema, size, arrays); - } + static std::shared_ptr Zeroes(int64_t size, + const std::shared_ptr& schema); /// \brief Generates a RecordBatchReader by repeating a RecordBatch /// @@ -235,12 +182,8 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] batch the RecordBatch to repeat /// /// \return a generated RecordBatchReader - static std::shared_ptr Repeat( - int64_t n_batch, const std::shared_ptr batch) { - std::vector> batches(static_cast(n_batch), - batch); - return *RecordBatchReader::Make(batches); - } + static std::shared_ptr Repeat( + int64_t n_batch, const std::shared_ptr batch); /// \brief Generates a RecordBatchReader of zeroes batches /// @@ -249,10 +192,8 @@ class ARROW_TESTING_EXPORT ConstantArrayGenerator { /// \param[in] schema to conform to /// /// \return a generated RecordBatchReader - static std::shared_ptr Zeroes( - int64_t n_batch, int64_t batch_size, const std::shared_ptr& schema) { - return Repeat(n_batch, Zeroes(batch_size, schema)); - } + static std::shared_ptr Zeroes(int64_t n_batch, int64_t batch_size, + const std::shared_ptr& schema); }; ARROW_TESTING_EXPORT diff --git a/cpp/src/arrow/testing/gtest_common.h b/cpp/src/arrow/testing/gtest_common.h deleted file mode 100644 index b3f25d10e329c..0000000000000 --- a/cpp/src/arrow/testing/gtest_common.h +++ /dev/null @@ -1,128 +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 -#include -#include -#include -#include -#include - -#include - -#include "arrow/array.h" -#include "arrow/array/builder_binary.h" -#include "arrow/array/builder_primitive.h" -#include "arrow/testing/gtest_util.h" -#include "arrow/testing/util.h" -#include "arrow/type_fwd.h" - -namespace arrow { - -class TestBase : public ::testing::Test { - public: - void SetUp() { - pool_ = default_memory_pool(); - random_seed_ = 0; - } - - std::shared_ptr MakeRandomNullBitmap(int64_t length, int64_t null_count) { - const int64_t null_nbytes = bit_util::BytesForBits(length); - - std::shared_ptr null_bitmap = *AllocateBuffer(null_nbytes, pool_); - memset(null_bitmap->mutable_data(), 255, null_nbytes); - for (int64_t i = 0; i < null_count; i++) { - bit_util::ClearBit(null_bitmap->mutable_data(), i * (length / null_count)); - } - return null_bitmap; - } - - template - inline std::shared_ptr MakeRandomArray(int64_t length, int64_t null_count = 0); - - protected: - uint32_t random_seed_; - MemoryPool* pool_; -}; - -template -std::shared_ptr TestBase::MakeRandomArray(int64_t length, int64_t null_count) { - const int64_t data_nbytes = length * sizeof(typename ArrayType::value_type); - auto data = *AllocateBuffer(data_nbytes, pool_); - - // Fill with random data - random_bytes(data_nbytes, random_seed_++, data->mutable_data()); - std::shared_ptr null_bitmap = MakeRandomNullBitmap(length, null_count); - - return std::make_shared(length, std::move(data), null_bitmap, null_count); -} - -template <> -inline std::shared_ptr TestBase::MakeRandomArray(int64_t length, - int64_t null_count) { - return std::make_shared(length); -} - -template <> -inline std::shared_ptr TestBase::MakeRandomArray( - int64_t length, int64_t null_count) { - const int byte_width = 10; - std::shared_ptr null_bitmap = MakeRandomNullBitmap(length, null_count); - auto data = *AllocateBuffer(byte_width * length, pool_); - - ::arrow::random_bytes(data->size(), 0, data->mutable_data()); - return std::make_shared(fixed_size_binary(byte_width), length, - std::move(data), null_bitmap, null_count); -} - -template <> -inline std::shared_ptr TestBase::MakeRandomArray(int64_t length, - int64_t null_count) { - std::vector valid_bytes(length, 1); - for (int64_t i = 0; i < null_count; i++) { - valid_bytes[i * 2] = 0; - } - BinaryBuilder builder(pool_); - - const int kBufferSize = 10; - uint8_t buffer[kBufferSize]; - for (int64_t i = 0; i < length; i++) { - if (!valid_bytes[i]) { - ARROW_EXPECT_OK(builder.AppendNull()); - } else { - ::arrow::random_bytes(kBufferSize, static_cast(i), buffer); - ARROW_EXPECT_OK(builder.Append(buffer, kBufferSize)); - } - } - - std::shared_ptr out; - ARROW_EXPECT_OK(builder.Finish(&out)); - return out; -} - -class TestBuilder : public ::testing::Test { - public: - void SetUp() { pool_ = default_memory_pool(); } - - protected: - MemoryPool* pool_; - std::shared_ptr type_; -}; - -} // namespace arrow diff --git a/cpp/src/arrow/testing/gtest_util.h b/cpp/src/arrow/testing/gtest_util.h index 22cb80f239872..c8cb6af986e73 100644 --- a/cpp/src/arrow/testing/gtest_util.h +++ b/cpp/src/arrow/testing/gtest_util.h @@ -30,19 +30,17 @@ #include -#include "arrow/array/builder_binary.h" -#include "arrow/array/builder_primitive.h" -#include "arrow/array/builder_time.h" +#include "arrow/compare.h" #include "arrow/result.h" #include "arrow/status.h" #include "arrow/testing/gtest_compat.h" -#include "arrow/testing/util.h" #include "arrow/testing/visibility.h" #include "arrow/type_fwd.h" #include "arrow/type_traits.h" -#include "arrow/util/bit_util.h" #include "arrow/util/macros.h" +#include "arrow/util/optional.h" #include "arrow/util/string_builder.h" +#include "arrow/util/string_view.h" #include "arrow/util/type_fwd.h" // NOTE: failing must be inline in the macros below, to get correct file / line number @@ -310,13 +308,6 @@ ARROW_TESTING_EXPORT void AssertZeroPadded(const Array& array); ARROW_TESTING_EXPORT void TestInitialized(const ArrayData& array); ARROW_TESTING_EXPORT void TestInitialized(const Array& array); -template -void FinishAndCheckPadding(BuilderType* builder, std::shared_ptr* out) { - ASSERT_OK_AND_ASSIGN(*out, builder->Finish()); - AssertZeroPadded(**out); - TestInitialized(**out); -} - #define DECL_T() typedef typename TestFixture::T T; #define DECL_TYPE() typedef typename TestFixture::Type Type; @@ -353,135 +344,6 @@ ARROW_TESTING_EXPORT std::shared_ptr
TableFromJSON(const std::shared_ptr&, const std::vector& json); -// ArrayFromVector: construct an Array from vectors of C values - -template -void ArrayFromVector(const std::shared_ptr& type, - const std::vector& is_valid, const std::vector& values, - std::shared_ptr* out) { - auto type_id = TYPE::type_id; - ASSERT_EQ(type_id, type->id()) - << "template parameter and concrete DataType instance don't agree"; - - std::unique_ptr builder_ptr; - ASSERT_OK(MakeBuilder(default_memory_pool(), type, &builder_ptr)); - // Get the concrete builder class to access its Append() specializations - auto& builder = dynamic_cast::BuilderType&>(*builder_ptr); - - for (size_t i = 0; i < values.size(); ++i) { - if (is_valid[i]) { - ASSERT_OK(builder.Append(values[i])); - } else { - ASSERT_OK(builder.AppendNull()); - } - } - ASSERT_OK(builder.Finish(out)); -} - -template -void ArrayFromVector(const std::shared_ptr& type, - const std::vector& values, std::shared_ptr* out) { - auto type_id = TYPE::type_id; - ASSERT_EQ(type_id, type->id()) - << "template parameter and concrete DataType instance don't agree"; - - std::unique_ptr builder_ptr; - ASSERT_OK(MakeBuilder(default_memory_pool(), type, &builder_ptr)); - // Get the concrete builder class to access its Append() specializations - auto& builder = dynamic_cast::BuilderType&>(*builder_ptr); - - for (size_t i = 0; i < values.size(); ++i) { - ASSERT_OK(builder.Append(values[i])); - } - ASSERT_OK(builder.Finish(out)); -} - -// Overloads without a DataType argument, for parameterless types - -template -void ArrayFromVector(const std::vector& is_valid, const std::vector& values, - std::shared_ptr* out) { - auto type = TypeTraits::type_singleton(); - ArrayFromVector(type, is_valid, values, out); -} - -template -void ArrayFromVector(const std::vector& values, std::shared_ptr* out) { - auto type = TypeTraits::type_singleton(); - ArrayFromVector(type, values, out); -} - -// ChunkedArrayFromVector: construct a ChunkedArray from vectors of C values - -template -void ChunkedArrayFromVector(const std::shared_ptr& type, - const std::vector>& is_valid, - const std::vector>& values, - std::shared_ptr* out) { - ArrayVector chunks; - ASSERT_EQ(is_valid.size(), values.size()); - for (size_t i = 0; i < values.size(); ++i) { - std::shared_ptr array; - ArrayFromVector(type, is_valid[i], values[i], &array); - chunks.push_back(array); - } - *out = std::make_shared(chunks); -} - -template -void ChunkedArrayFromVector(const std::shared_ptr& type, - const std::vector>& values, - std::shared_ptr* out) { - ArrayVector chunks; - for (size_t i = 0; i < values.size(); ++i) { - std::shared_ptr array; - ArrayFromVector(type, values[i], &array); - chunks.push_back(array); - } - *out = std::make_shared(chunks); -} - -// Overloads without a DataType argument, for parameterless types - -template -void ChunkedArrayFromVector(const std::vector>& is_valid, - const std::vector>& values, - std::shared_ptr* out) { - auto type = TypeTraits::type_singleton(); - ChunkedArrayFromVector(type, is_valid, values, out); -} - -template -void ChunkedArrayFromVector(const std::vector>& values, - std::shared_ptr* out) { - auto type = TypeTraits::type_singleton(); - ChunkedArrayFromVector(type, values, out); -} - -template -static inline Status GetBitmapFromVector(const std::vector& is_valid, - std::shared_ptr* result) { - size_t length = is_valid.size(); - - ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateEmptyBitmap(length)); - - uint8_t* bitmap = buffer->mutable_data(); - for (size_t i = 0; i < static_cast(length); ++i) { - if (is_valid[i]) { - bit_util::SetBit(bitmap, i); - } - } - - *result = buffer; - return Status::OK(); -} - -template -inline void BitmapFromVector(const std::vector& is_valid, - std::shared_ptr* out) { - ASSERT_OK(GetBitmapFromVector(is_valid, out)); -} - // 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/json_integration_test.cc b/cpp/src/arrow/testing/json_integration_test.cc index 146f16a95b4f7..7e1e93eae3fa1 100644 --- a/cpp/src/arrow/testing/json_integration_test.cc +++ b/cpp/src/arrow/testing/json_integration_test.cc @@ -38,11 +38,13 @@ #include "arrow/ipc/writer.h" #include "arrow/pretty_print.h" #include "arrow/status.h" +#include "arrow/testing/builder.h" #include "arrow/testing/extension_type.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/json_integration.h" #include "arrow/testing/json_internal.h" #include "arrow/testing/random.h" +#include "arrow/testing/util.h" #include "arrow/type.h" #include "arrow/type_fwd.h" #include "arrow/util/io_util.h" @@ -858,15 +860,8 @@ TEST(TestJsonArrayWriter, PrimitiveTypes) { TEST(TestJsonArrayWriter, NestedTypes) { auto value_type = int32(); - std::vector values_is_valid = {true, false, true, true, false, true, true}; - - std::vector values = {0, 1, 2, 3, 4, 5, 6}; - std::shared_ptr values_array; - ArrayFromVector(values_is_valid, values, &values_array); - - std::vector i16_values = {0, 1, 2, 3, 4, 5, 6}; - std::shared_ptr i16_values_array; - ArrayFromVector(values_is_valid, i16_values, &i16_values_array); + auto values_array = ArrayFromJSON(int32(), "[0, null, 2, 3, null, 5, 6]"); + auto i16_values_array = ArrayFromJSON(int32(), "[0, null, 2, 3, null, 5, 6]"); // List std::vector list_is_valid = {true, false, true, true, true}; @@ -1016,16 +1011,10 @@ TEST(TestJsonFileReadWrite, JsonExample1) { std::shared_ptr batch; ReadOneBatchJson(json_example1, ex_schema, &batch); - std::vector foo_valid = {true, false, true, true, true}; - std::vector foo_values = {1, 2, 3, 4, 5}; - std::shared_ptr foo; - ArrayFromVector(foo_valid, foo_values, &foo); + auto foo = ArrayFromJSON(int32(), "[1, null, 3, 4, 5]"); ASSERT_TRUE(batch->column(0)->Equals(foo)); - std::vector bar_valid = {true, false, false, true, true}; - std::vector bar_values = {1, 2, 3, 4, 5}; - std::shared_ptr bar; - ArrayFromVector(bar_valid, bar_values, &bar); + auto bar = ArrayFromJSON(float64(), "[1, null, null, 4, 5]"); ASSERT_TRUE(batch->column(1)->Equals(bar)); } diff --git a/cpp/src/arrow/testing/json_internal.cc b/cpp/src/arrow/testing/json_internal.cc index 4c0ca7d89264f..b6f942ae103ed 100644 --- a/cpp/src/arrow/testing/json_internal.cc +++ b/cpp/src/arrow/testing/json_internal.cc @@ -35,6 +35,7 @@ #include "arrow/ipc/dictionary.h" #include "arrow/record_batch.h" #include "arrow/result.h" +#include "arrow/scalar.h" #include "arrow/status.h" #include "arrow/type.h" #include "arrow/type_fwd.h" @@ -47,7 +48,8 @@ #include "arrow/util/logging.h" #include "arrow/util/string.h" #include "arrow/util/value_parsing.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_array_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/testing/pch.h b/cpp/src/arrow/testing/pch.h index d6c3c74962be9..e544ad806adc9 100644 --- a/cpp/src/arrow/testing/pch.h +++ b/cpp/src/arrow/testing/pch.h @@ -21,6 +21,5 @@ // may incur a slowdown, since it makes the precompiled header heavier to load. #include "arrow/pch.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/util.h" diff --git a/cpp/src/arrow/testing/random.cc b/cpp/src/arrow/testing/random.cc index cbf9edfde3c4c..c5ffe9c2aa809 100644 --- a/cpp/src/arrow/testing/random.cc +++ b/cpp/src/arrow/testing/random.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include "arrow/array/builder_decimal.h" #include "arrow/array/builder_primitive.h" #include "arrow/buffer.h" +#include "arrow/record_batch.h" #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/type_fwd.h" diff --git a/cpp/src/arrow/testing/random.h b/cpp/src/arrow/testing/random.h index c77ae2525c44f..5e486d90ac377 100644 --- a/cpp/src/arrow/testing/random.h +++ b/cpp/src/arrow/testing/random.h @@ -330,7 +330,8 @@ class ARROW_TESTING_EXPORT RandomArrayGenerator { /// \param[in] force_empty_nulls if true, null list entries must have 0 length /// /// \return a generated Array - std::shared_ptr List(const Array& values, int64_t size, double null_probability, + std::shared_ptr List(const Array& values, int64_t size, + double null_probability = 0, bool force_empty_nulls = false); /// \brief Generate a random MapArray @@ -344,7 +345,7 @@ class ARROW_TESTING_EXPORT RandomArrayGenerator { /// \return a generated Array std::shared_ptr Map(const std::shared_ptr& keys, const std::shared_ptr& items, int64_t size, - double null_probability, bool force_empty_nulls = false); + double null_probability = 0, bool force_empty_nulls = false); /// \brief Generate a random SparseUnionArray /// @@ -378,7 +379,7 @@ class ARROW_TESTING_EXPORT RandomArrayGenerator { /// \param[in] null_probability the probability of a slot being null /// \return a generated Array std::shared_ptr ArrayOf(std::shared_ptr type, int64_t size, - double null_probability); + double null_probability = 0); /// \brief Generate an array with random data based on the given field. See BatchOf /// for usage info. diff --git a/cpp/src/arrow/testing/random_test.cc b/cpp/src/arrow/testing/random_test.cc index 261998d459072..588c4f226873b 100644 --- a/cpp/src/arrow/testing/random_test.cc +++ b/cpp/src/arrow/testing/random_test.cc @@ -23,6 +23,7 @@ #include "arrow/testing/random.h" #include "arrow/type.h" #include "arrow/util/checked_cast.h" +#include "arrow/util/decimal.h" #include "arrow/util/key_value_metadata.h" #include "arrow/util/pcg_random.h" diff --git a/cpp/src/arrow/testing/util.h b/cpp/src/arrow/testing/util.h index 0ce5f714ca74c..786ab3814aa3a 100644 --- a/cpp/src/arrow/testing/util.h +++ b/cpp/src/arrow/testing/util.h @@ -28,13 +28,12 @@ #include #include -#include "arrow/array/builder_primitive.h" +#include "arrow/buffer.h" #include "arrow/record_batch.h" #include "arrow/status.h" #include "arrow/testing/visibility.h" #include "arrow/type_fwd.h" #include "arrow/util/macros.h" -#include "arrow/visitor_inline.h" namespace arrow { @@ -72,20 +71,6 @@ ARROW_TESTING_EXPORT Status MakeRandomByteBuffer(int64_t length, MemoryPool* poo ARROW_TESTING_EXPORT uint64_t random_seed(); -template -Status MakeArray(const std::vector& valid_bytes, const std::vector& values, - int64_t size, Builder* builder, std::shared_ptr* out) { - // Append the first 1000 - for (int64_t i = 0; i < size; ++i) { - if (valid_bytes[i] > 0) { - RETURN_NOT_OK(builder->Append(values[i])); - } else { - RETURN_NOT_OK(builder->AppendNull()); - } - } - return builder->Finish(out); -} - #define DECL_T() typedef typename TestFixture::T T; #define DECL_TYPE() typedef typename TestFixture::Type Type; @@ -116,58 +101,6 @@ class BatchIterator : public RecordBatchReader { size_t position_; }; -template -struct VisitBuilderImpl { - template ::BuilderType, - // need to let SFINAE drop this Visit when it would result in - // [](NullBuilder*){}(double_builder) - typename = decltype(std::declval()(std::declval()))> - Status Visit(const T&) { - fn_(internal::checked_cast(builder_)); - return Status::OK(); - } - - Status Visit(const DataType& t) { - return Status::NotImplemented("visiting builders of type ", t); - } - - Status Visit() { return VisitTypeInline(*builder_->type(), this); } - - ArrayBuilder* builder_; - Fn fn_; -}; - -template -Status VisitBuilder(ArrayBuilder* builder, Fn&& fn) { - return VisitBuilderImpl{builder, std::forward(fn)}.Visit(); -} - -template -Result> ArrayFromBuilderVisitor( - const std::shared_ptr& type, int64_t initial_capacity, - int64_t visitor_repetitions, Fn&& fn) { - std::unique_ptr builder; - RETURN_NOT_OK(MakeBuilder(default_memory_pool(), type, &builder)); - - if (initial_capacity != 0) { - RETURN_NOT_OK(builder->Resize(initial_capacity)); - } - - for (int64_t i = 0; i < visitor_repetitions; ++i) { - RETURN_NOT_OK(VisitBuilder(builder.get(), std::forward(fn))); - } - - std::shared_ptr out; - RETURN_NOT_OK(builder->Finish(&out)); - return std::move(out); -} - -template -Result> ArrayFromBuilderVisitor( - const std::shared_ptr& type, int64_t length, Fn&& fn) { - return ArrayFromBuilderVisitor(type, length, length, std::forward(fn)); -} - static inline std::vector (*)(FieldVector, std::vector)> UnionTypeFactories() { return {sparse_union, dense_union}; diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc index e96abf7ba4bfe..2a382662497a9 100644 --- a/cpp/src/arrow/type.cc +++ b/cpp/src/arrow/type.cc @@ -43,7 +43,7 @@ #include "arrow/util/make_unique.h" #include "arrow/util/range.h" #include "arrow/util/vector.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/util/bit_block_counter_test.cc b/cpp/src/arrow/util/bit_block_counter_test.cc index b71ff8f561121..959604393b682 100644 --- a/cpp/src/arrow/util/bit_block_counter_test.cc +++ b/cpp/src/arrow/util/bit_block_counter_test.cc @@ -25,7 +25,6 @@ #include "arrow/buffer.h" #include "arrow/memory_pool.h" #include "arrow/result.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/util.h" #include "arrow/util/bit_block_counter.h" diff --git a/cpp/src/arrow/util/bit_util_test.cc b/cpp/src/arrow/util/bit_util_test.cc index 9fa7b882b7161..e3e5d960bdba8 100644 --- a/cpp/src/arrow/util/bit_util_test.cc +++ b/cpp/src/arrow/util/bit_util_test.cc @@ -37,7 +37,6 @@ #include "arrow/buffer_builder.h" #include "arrow/result.h" #include "arrow/status.h" -#include "arrow/testing/gtest_common.h" #include "arrow/testing/gtest_compat.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" @@ -1336,7 +1335,7 @@ struct BitmapAndNotOp : public BitmapOperation { } }; -class BitmapOp : public TestBase { +class BitmapOp : public ::testing::Test { public: void TestAligned(const BitmapOperation& op, const std::vector& left_bits, const std::vector& right_bits, diff --git a/cpp/src/arrow/util/byte_size.cc b/cpp/src/arrow/util/byte_size.cc index 1c9d69488d61e..fe232c9accd77 100644 --- a/cpp/src/arrow/util/byte_size.cc +++ b/cpp/src/arrow/util/byte_size.cc @@ -23,8 +23,11 @@ #include "arrow/array.h" #include "arrow/array/builder_primitive.h" #include "arrow/buffer.h" +#include "arrow/chunked_array.h" +#include "arrow/record_batch.h" +#include "arrow/table.h" #include "arrow/util/logging.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { diff --git a/cpp/src/arrow/util/byte_size.h b/cpp/src/arrow/util/byte_size.h index da9f12a99aab7..6cf3116675a80 100644 --- a/cpp/src/arrow/util/byte_size.h +++ b/cpp/src/arrow/util/byte_size.h @@ -19,9 +19,7 @@ #include -#include "arrow/array.h" -#include "arrow/record_batch.h" -#include "arrow/table.h" +#include "arrow/type_fwd.h" namespace arrow { diff --git a/cpp/src/arrow/util/byte_size_test.cc b/cpp/src/arrow/util/byte_size_test.cc index 33ba552f6ccfd..fc18049fddf0a 100644 --- a/cpp/src/arrow/util/byte_size_test.cc +++ b/cpp/src/arrow/util/byte_size_test.cc @@ -22,7 +22,11 @@ #include #include "arrow/array.h" +#include "arrow/array/builder_primitive.h" #include "arrow/buffer.h" +#include "arrow/chunked_array.h" +#include "arrow/record_batch.h" +#include "arrow/table.h" #include "arrow/testing/extension_type.h" #include "arrow/testing/generator.h" #include "arrow/testing/gtest_util.h" diff --git a/cpp/src/arrow/util/converter.h b/cpp/src/arrow/util/converter.h index 0b29e0f5bc7e3..f87fbc7122f1e 100644 --- a/cpp/src/arrow/util/converter.h +++ b/cpp/src/arrow/util/converter.h @@ -26,7 +26,7 @@ #include "arrow/type_traits.h" #include "arrow/util/checked_cast.h" #include "arrow/util/make_unique.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { namespace internal { diff --git a/cpp/src/arrow/util/future_test.cc b/cpp/src/arrow/util/future_test.cc index 84a9fa15554e8..f481018cdc0c7 100644 --- a/cpp/src/arrow/util/future_test.cc +++ b/cpp/src/arrow/util/future_test.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/cpp/src/arrow/util/int_util.cc b/cpp/src/arrow/util/int_util.cc index f96521216db65..ed9ea25579b3c 100644 --- a/cpp/src/arrow/util/int_util.cc +++ b/cpp/src/arrow/util/int_util.cc @@ -32,7 +32,7 @@ #include "arrow/util/logging.h" #include "arrow/util/macros.h" #include "arrow/util/ubsan.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_type_inline.h" namespace arrow { namespace internal { diff --git a/cpp/src/arrow/util/io_util.cc b/cpp/src/arrow/util/io_util.cc index 20e631a863f7f..853e30081dcec 100644 --- a/cpp/src/arrow/util/io_util.cc +++ b/cpp/src/arrow/util/io_util.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -1691,6 +1692,9 @@ int64_t GetRandomSeed() { // The process-global seed generator to aims to avoid calling std::random_device // unless truly necessary (it can block on some systems, see ARROW-10287). static auto seed_gen = GetSeedGenerator(); + static std::mutex seed_gen_mutex; + + std::lock_guard lock(seed_gen_mutex); return static_cast(seed_gen()); } diff --git a/cpp/src/arrow/util/io_util_test.cc b/cpp/src/arrow/util/io_util_test.cc index c09e4b974dd5b..2e3a9d86eb693 100644 --- a/cpp/src/arrow/util/io_util_test.cc +++ b/cpp/src/arrow/util/io_util_test.cc @@ -32,6 +32,7 @@ #include #include +#include "arrow/buffer.h" #include "arrow/testing/gtest_util.h" #include "arrow/util/bit_util.h" #include "arrow/util/io_util.h" diff --git a/cpp/src/arrow/util/tdigest_test.cc b/cpp/src/arrow/util/tdigest_test.cc index 532046b20cb0e..f501285b34f5a 100644 --- a/cpp/src/arrow/util/tdigest_test.cc +++ b/cpp/src/arrow/util/tdigest_test.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/cpp/src/arrow/visit_array_inline.h b/cpp/src/arrow/visit_array_inline.h new file mode 100644 index 0000000000000..ecb9b6d39c36c --- /dev/null +++ b/cpp/src/arrow/visit_array_inline.h @@ -0,0 +1,44 @@ +// 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/array.h" +#include "arrow/extension_type.h" +#include "arrow/visitor_generate.h" + +namespace arrow { + +#define ARRAY_VISIT_INLINE(TYPE_CLASS) \ + case TYPE_CLASS##Type::type_id: \ + return visitor->Visit( \ + internal::checked_cast::ArrayType&>( \ + array)); + +template +inline Status VisitArrayInline(const Array& array, VISITOR* visitor) { + switch (array.type_id()) { + ARROW_GENERATE_FOR_ALL_TYPES(ARRAY_VISIT_INLINE); + default: + break; + } + return Status::NotImplemented("Type not implemented"); +} + +#undef ARRAY_VISIT_INLINE + +} // namespace arrow diff --git a/cpp/src/arrow/visitor_inline.h b/cpp/src/arrow/visit_data_inline.h similarity index 72% rename from cpp/src/arrow/visitor_inline.h rename to cpp/src/arrow/visit_data_inline.h index 4ede11224bc9e..fdefd97c9fbdc 100644 --- a/cpp/src/arrow/visitor_inline.h +++ b/cpp/src/arrow/visit_data_inline.h @@ -15,17 +15,12 @@ // specific language governing permissions and limitations // under the License. -// Private header, not to be exported - #pragma once -#include - #include "arrow/array.h" -#include "arrow/extension_type.h" -#include "arrow/scalar.h" #include "arrow/status.h" #include "arrow/type.h" +#include "arrow/type_traits.h" #include "arrow/util/bit_block_counter.h" #include "arrow/util/bit_util.h" #include "arrow/util/checked_cast.h" @@ -34,103 +29,6 @@ namespace arrow { -#define ARROW_GENERATE_FOR_ALL_INTEGER_TYPES(ACTION) \ - ACTION(Int8); \ - ACTION(UInt8); \ - ACTION(Int16); \ - ACTION(UInt16); \ - ACTION(Int32); \ - ACTION(UInt32); \ - ACTION(Int64); \ - ACTION(UInt64) - -#define ARROW_GENERATE_FOR_ALL_NUMERIC_TYPES(ACTION) \ - ARROW_GENERATE_FOR_ALL_INTEGER_TYPES(ACTION); \ - ACTION(HalfFloat); \ - ACTION(Float); \ - ACTION(Double) - -#define ARROW_GENERATE_FOR_ALL_TYPES(ACTION) \ - ACTION(Null); \ - ACTION(Boolean); \ - ARROW_GENERATE_FOR_ALL_NUMERIC_TYPES(ACTION); \ - ACTION(String); \ - ACTION(Binary); \ - ACTION(LargeString); \ - ACTION(LargeBinary); \ - ACTION(FixedSizeBinary); \ - ACTION(Duration); \ - ACTION(Date32); \ - ACTION(Date64); \ - ACTION(Timestamp); \ - ACTION(Time32); \ - ACTION(Time64); \ - ACTION(MonthDayNanoInterval); \ - ACTION(MonthInterval); \ - ACTION(DayTimeInterval); \ - ACTION(Decimal128); \ - ACTION(Decimal256); \ - ACTION(List); \ - ACTION(LargeList); \ - ACTION(Map); \ - ACTION(FixedSizeList); \ - ACTION(Struct); \ - ACTION(SparseUnion); \ - ACTION(DenseUnion); \ - ACTION(Dictionary); \ - ACTION(Extension) - -#define TYPE_VISIT_INLINE(TYPE_CLASS) \ - case TYPE_CLASS##Type::type_id: \ - return visitor->Visit(internal::checked_cast(type)); - -template -inline Status VisitTypeInline(const DataType& type, VISITOR* visitor) { - switch (type.id()) { - ARROW_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE); - default: - break; - } - return Status::NotImplemented("Type not implemented"); -} - -#undef TYPE_VISIT_INLINE - -#define TYPE_ID_VISIT_INLINE(TYPE_CLASS) \ - case TYPE_CLASS##Type::type_id: { \ - const TYPE_CLASS##Type* concrete_ptr = nullptr; \ - return visitor->Visit(concrete_ptr); \ - } - -// Calls `visitor` with a nullptr of the corresponding concrete type class -template -inline Status VisitTypeIdInline(Type::type id, VISITOR* visitor) { - switch (id) { - ARROW_GENERATE_FOR_ALL_TYPES(TYPE_ID_VISIT_INLINE); - default: - break; - } - return Status::NotImplemented("Type not implemented"); -} - -#undef TYPE_ID_VISIT_INLINE - -#define ARRAY_VISIT_INLINE(TYPE_CLASS) \ - case TYPE_CLASS##Type::type_id: \ - return visitor->Visit( \ - internal::checked_cast::ArrayType&>( \ - array)); - -template -inline Status VisitArrayInline(const Array& array, VISITOR* visitor) { - switch (array.type_id()) { - ARROW_GENERATE_FOR_ALL_TYPES(ARRAY_VISIT_INLINE); - default: - break; - } - return Status::NotImplemented("Type not implemented"); -} - namespace internal { template @@ -359,23 +257,6 @@ struct ArrayDataVisitor { } }; -#define SCALAR_VISIT_INLINE(TYPE_CLASS) \ - case TYPE_CLASS##Type::type_id: \ - return visitor->Visit(internal::checked_cast(scalar)); - -template -inline Status VisitScalarInline(const Scalar& scalar, VISITOR* visitor) { - switch (scalar.type->id()) { - ARROW_GENERATE_FOR_ALL_TYPES(SCALAR_VISIT_INLINE); - default: - break; - } - return Status::NotImplemented("Scalar visitor for type not implemented ", - scalar.type->ToString()); -} - -#undef TYPE_VISIT_INLINE - // Visit a null bitmap, in order, without overhead. // // The given `ValidFunc` should be a callable with either of these signatures: diff --git a/cpp/src/arrow/visit_scalar_inline.h b/cpp/src/arrow/visit_scalar_inline.h new file mode 100644 index 0000000000000..cad861b7a0096 --- /dev/null +++ b/cpp/src/arrow/visit_scalar_inline.h @@ -0,0 +1,48 @@ +// 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. + +// Private header, not to be exported + +#pragma once + +#include + +#include "arrow/scalar.h" +#include "arrow/status.h" +#include "arrow/type.h" +#include "arrow/visitor_generate.h" + +namespace arrow { + +#define SCALAR_VISIT_INLINE(TYPE_CLASS) \ + case TYPE_CLASS##Type::type_id: \ + return visitor->Visit(internal::checked_cast(scalar)); + +template +inline Status VisitScalarInline(const Scalar& scalar, VISITOR* visitor) { + switch (scalar.type->id()) { + ARROW_GENERATE_FOR_ALL_TYPES(SCALAR_VISIT_INLINE); + default: + break; + } + return Status::NotImplemented("Scalar visitor for type not implemented ", + scalar.type->ToString()); +} + +#undef SCALAR_VISIT_INLINE + +} // namespace arrow diff --git a/cpp/src/arrow/visit_type_inline.h b/cpp/src/arrow/visit_type_inline.h new file mode 100644 index 0000000000000..2b60de2a5e13b --- /dev/null +++ b/cpp/src/arrow/visit_type_inline.h @@ -0,0 +1,62 @@ +// 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/extension_type.h" +#include "arrow/type.h" +#include "arrow/util/macros.h" +#include "arrow/visitor_generate.h" + +namespace arrow { + +#define TYPE_VISIT_INLINE(TYPE_CLASS) \ + case TYPE_CLASS##Type::type_id: \ + return visitor->Visit(internal::checked_cast(type)); + +template +inline Status VisitTypeInline(const DataType& type, VISITOR* visitor) { + switch (type.id()) { + ARROW_GENERATE_FOR_ALL_TYPES(TYPE_VISIT_INLINE); + default: + break; + } + return Status::NotImplemented("Type not implemented"); +} + +#undef TYPE_VISIT_INLINE + +#define TYPE_ID_VISIT_INLINE(TYPE_CLASS) \ + case TYPE_CLASS##Type::type_id: { \ + const TYPE_CLASS##Type* concrete_ptr = NULLPTR; \ + return visitor->Visit(concrete_ptr); \ + } + +// Calls `visitor` with a nullptr of the corresponding concrete type class +template +inline Status VisitTypeIdInline(Type::type id, VISITOR* visitor) { + switch (id) { + ARROW_GENERATE_FOR_ALL_TYPES(TYPE_ID_VISIT_INLINE); + default: + break; + } + return Status::NotImplemented("Type not implemented"); +} + +#undef TYPE_ID_VISIT_INLINE + +} // namespace arrow diff --git a/cpp/src/arrow/visitor_generate.h b/cpp/src/arrow/visitor_generate.h new file mode 100644 index 0000000000000..265c76197a4d4 --- /dev/null +++ b/cpp/src/arrow/visitor_generate.h @@ -0,0 +1,68 @@ +// 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 + +namespace arrow { + +#define ARROW_GENERATE_FOR_ALL_INTEGER_TYPES(ACTION) \ + ACTION(Int8); \ + ACTION(UInt8); \ + ACTION(Int16); \ + ACTION(UInt16); \ + ACTION(Int32); \ + ACTION(UInt32); \ + ACTION(Int64); \ + ACTION(UInt64) + +#define ARROW_GENERATE_FOR_ALL_NUMERIC_TYPES(ACTION) \ + ARROW_GENERATE_FOR_ALL_INTEGER_TYPES(ACTION); \ + ACTION(HalfFloat); \ + ACTION(Float); \ + ACTION(Double) + +#define ARROW_GENERATE_FOR_ALL_TYPES(ACTION) \ + ACTION(Null); \ + ACTION(Boolean); \ + ARROW_GENERATE_FOR_ALL_NUMERIC_TYPES(ACTION); \ + ACTION(String); \ + ACTION(Binary); \ + ACTION(LargeString); \ + ACTION(LargeBinary); \ + ACTION(FixedSizeBinary); \ + ACTION(Duration); \ + ACTION(Date32); \ + ACTION(Date64); \ + ACTION(Timestamp); \ + ACTION(Time32); \ + ACTION(Time64); \ + ACTION(MonthDayNanoInterval); \ + ACTION(MonthInterval); \ + ACTION(DayTimeInterval); \ + ACTION(Decimal128); \ + ACTION(Decimal256); \ + ACTION(List); \ + ACTION(LargeList); \ + ACTION(Map); \ + ACTION(FixedSizeList); \ + ACTION(Struct); \ + ACTION(SparseUnion); \ + ACTION(DenseUnion); \ + ACTION(Dictionary); \ + ACTION(Extension) + +} // namespace arrow diff --git a/cpp/src/gandiva/tests/test_util.h b/cpp/src/gandiva/tests/test_util.h index 54270436cb7ad..99df90769e0ad 100644 --- a/cpp/src/gandiva/tests/test_util.h +++ b/cpp/src/gandiva/tests/test_util.h @@ -20,6 +20,7 @@ #include #include +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "gandiva/arrow.h" #include "gandiva/configuration.h" diff --git a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc index 4849d65dbf32e..bef04660fb778 100644 --- a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc +++ b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc @@ -40,6 +40,7 @@ #include "arrow/record_batch.h" #include "arrow/scalar.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" diff --git a/cpp/src/parquet/arrow/arrow_schema_test.cc b/cpp/src/parquet/arrow/arrow_schema_test.cc index 99ce0c962f719..c8581984efaac 100644 --- a/cpp/src/parquet/arrow/arrow_schema_test.cc +++ b/cpp/src/parquet/arrow/arrow_schema_test.cc @@ -35,7 +35,6 @@ #include "arrow/type.h" #include "arrow/util/key_value_metadata.h" -using arrow::ArrayFromVector; using arrow::Field; using arrow::TimeUnit; diff --git a/cpp/src/parquet/arrow/path_internal.cc b/cpp/src/parquet/arrow/path_internal.cc index 7f706e50d55ed..8002f13e79941 100644 --- a/cpp/src/parquet/arrow/path_internal.cc +++ b/cpp/src/parquet/arrow/path_internal.cc @@ -105,7 +105,8 @@ #include "arrow/util/macros.h" #include "arrow/util/make_unique.h" #include "arrow/util/variant.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_array_inline.h" + #include "parquet/properties.h" namespace parquet { diff --git a/cpp/src/parquet/arrow/reader_internal.cc b/cpp/src/parquet/arrow/reader_internal.cc index f1f3cb114a6a3..85d6359b6115d 100644 --- a/cpp/src/parquet/arrow/reader_internal.cc +++ b/cpp/src/parquet/arrow/reader_internal.cc @@ -45,7 +45,7 @@ #include "arrow/util/logging.h" #include "arrow/util/string_view.h" #include "arrow/util/ubsan.h" -#include "arrow/visitor_inline.h" + #include "parquet/arrow/reader.h" #include "parquet/arrow/schema.h" #include "parquet/arrow/schema_internal.h" diff --git a/cpp/src/parquet/arrow/reconstruct_internal_test.cc b/cpp/src/parquet/arrow/reconstruct_internal_test.cc index 9254e774b3e86..8a69f8266f1e6 100644 --- a/cpp/src/parquet/arrow/reconstruct_internal_test.cc +++ b/cpp/src/parquet/arrow/reconstruct_internal_test.cc @@ -25,6 +25,7 @@ #include #include +#include "arrow/array.h" #include "arrow/array/concatenate.h" #include "arrow/chunked_array.h" #include "arrow/io/memory.h" diff --git a/cpp/src/parquet/arrow/writer.cc b/cpp/src/parquet/arrow/writer.cc index a2776b4563c35..cf174dc61c859 100644 --- a/cpp/src/parquet/arrow/writer.cc +++ b/cpp/src/parquet/arrow/writer.cc @@ -34,7 +34,6 @@ #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging.h" #include "arrow/util/make_unique.h" -#include "arrow/visitor_inline.h" #include "parquet/arrow/path_internal.h" #include "parquet/arrow/reader_internal.h" diff --git a/cpp/src/parquet/column_writer.cc b/cpp/src/parquet/column_writer.cc index 6ac33d90a32d1..0aa365b9f2ff3 100644 --- a/cpp/src/parquet/column_writer.cc +++ b/cpp/src/parquet/column_writer.cc @@ -41,7 +41,7 @@ #include "arrow/util/endian.h" #include "arrow/util/logging.h" #include "arrow/util/rle_encoding.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_array_inline.h" #include "parquet/column_page.h" #include "parquet/encoding.h" #include "parquet/encryption/encryption_internal.h" diff --git a/cpp/src/parquet/encoding.cc b/cpp/src/parquet/encoding.cc index f5b2ca73be4ec..777c5e40793aa 100644 --- a/cpp/src/parquet/encoding.cc +++ b/cpp/src/parquet/encoding.cc @@ -44,7 +44,7 @@ #include "arrow/util/rle_encoding.h" #include "arrow/util/string_view.h" #include "arrow/util/ubsan.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" #include "parquet/exception.h" #include "parquet/platform.h" #include "parquet/schema.h" diff --git a/cpp/src/parquet/encoding_test.cc b/cpp/src/parquet/encoding_test.cc index 99af5c050d097..6b494205c5ea0 100644 --- a/cpp/src/parquet/encoding_test.cc +++ b/cpp/src/parquet/encoding_test.cc @@ -25,6 +25,7 @@ #include #include "arrow/array.h" +#include "arrow/array/builder_binary.h" #include "arrow/array/builder_dict.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/random.h" diff --git a/cpp/src/parquet/statistics.cc b/cpp/src/parquet/statistics.cc index 715c1a1ab663c..034a3a317c4f2 100644 --- a/cpp/src/parquet/statistics.cc +++ b/cpp/src/parquet/statistics.cc @@ -32,7 +32,7 @@ #include "arrow/util/logging.h" #include "arrow/util/optional.h" #include "arrow/util/ubsan.h" -#include "arrow/visitor_inline.h" +#include "arrow/visit_data_inline.h" #include "parquet/encoding.h" #include "parquet/exception.h" #include "parquet/platform.h" diff --git a/cpp/src/parquet/statistics_test.cc b/cpp/src/parquet/statistics_test.cc index af923e5394c00..91ebce834b9da 100644 --- a/cpp/src/parquet/statistics_test.cc +++ b/cpp/src/parquet/statistics_test.cc @@ -26,6 +26,10 @@ #include #include +#include "arrow/array.h" +#include "arrow/buffer.h" +#include "arrow/memory_pool.h" +#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" #include "arrow/type_traits.h" #include "arrow/util/bit_util.h"