From 942f757e8bc0aaa7cf788bdf0c4091b63c9af7e5 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 30 Aug 2024 13:37:07 +0900 Subject: [PATCH] Add support for CopyTo --- cpp/src/arrow/array/array_test.cc | 18 ++++++++++++++++++ cpp/src/arrow/array/data.cc | 2 ++ 2 files changed, 20 insertions(+) diff --git a/cpp/src/arrow/array/array_test.cc b/cpp/src/arrow/array/array_test.cc index 930095eb67e7b..73e0c692432b6 100644 --- a/cpp/src/arrow/array/array_test.cc +++ b/cpp/src/arrow/array/array_test.cc @@ -3812,6 +3812,24 @@ TEST_F(TestArrayDataStatistics, CopyAssignment) { ASSERT_TRUE(copied_data.statistics->is_max_exact); } +TEST_F(TestArrayDataStatistics, CopyTo) { + ASSERT_OK_AND_ASSIGN(auto copied_data, + data_->CopyTo(arrow::default_cpu_memory_manager())); + + ASSERT_TRUE(copied_data->statistics->null_count.has_value()); + ASSERT_EQ(null_count_, copied_data->statistics->null_count.value()); + + ASSERT_TRUE(copied_data->statistics->min.has_value()); + ASSERT_TRUE(std::holds_alternative(copied_data->statistics->min.value())); + ASSERT_EQ(min_, std::get(copied_data->statistics->min.value())); + ASSERT_TRUE(copied_data->statistics->is_min_exact); + + ASSERT_TRUE(copied_data->statistics->max.has_value()); + ASSERT_TRUE(std::holds_alternative(copied_data->statistics->max.value())); + ASSERT_EQ(max_, std::get(copied_data->statistics->max.value())); + ASSERT_TRUE(copied_data->statistics->is_max_exact); +} + TEST_F(TestArrayDataStatistics, Slice) { auto sliced_data = data_->Slice(0, 1); ASSERT_FALSE(sliced_data->statistics); diff --git a/cpp/src/arrow/array/data.cc b/cpp/src/arrow/array/data.cc index ee6b04bfca70f..8e29297a8c175 100644 --- a/cpp/src/arrow/array/data.cc +++ b/cpp/src/arrow/array/data.cc @@ -165,6 +165,8 @@ Result> CopyToImpl(const ArrayData& data, ARROW_ASSIGN_OR_RAISE(output->dictionary, CopyToImpl(*data.dictionary, to, copy_fn)); } + output->statistics = data.statistics; + return output; } } // namespace