From 01ec55083a6aeb121ea47c4ee61434b6e3852bf2 Mon Sep 17 00:00:00 2001 From: Jackie Yan Date: Sun, 21 Dec 2025 15:54:56 +0800 Subject: [PATCH 1/4] refactor: replace arrow::util::span with std::span --- cpp/src/arrow/array/data.h | 2 +- cpp/src/arrow/array/util.cc | 2 +- cpp/src/arrow/buffer.h | 2 +- cpp/src/arrow/chunk_resolver.h | 2 +- .../arrow/compute/kernels/aggregate_pivot.cc | 2 +- .../arrow/compute/kernels/chunked_internal.h | 2 +- .../arrow/compute/kernels/hash_aggregate.cc | 5 +- .../compute/kernels/hash_aggregate_numeric.cc | 2 +- .../compute/kernels/hash_aggregate_pivot.cc | 4 +- .../arrow/compute/kernels/pivot_internal.cc | 2 +- cpp/src/arrow/compute/kernels/vector_rank.cc | 2 +- cpp/src/arrow/integration/json_internal.cc | 2 +- cpp/src/arrow/util/binary_view_util.h | 2 +- cpp/src/arrow/util/bitmap.h | 2 +- cpp/src/arrow/util/bitmap_builders.h | 2 +- cpp/src/arrow/util/float16_test.cc | 2 +- cpp/src/arrow/util/rle_encoding_test.cc | 2 +- cpp/src/arrow/util/secure_string.cc | 2 +- cpp/src/arrow/util/secure_string.h | 2 +- cpp/src/arrow/util/span.h | 132 ------------------ cpp/src/arrow/util/span_test.cc | 56 ++++---- cpp/src/parquet/column_writer.cc | 2 +- cpp/src/parquet/encoding_test.cc | 9 +- cpp/src/parquet/encryption/encryption.h | 3 +- .../parquet/encryption/encryption_internal.cc | 3 +- .../parquet/encryption/encryption_internal.h | 28 ++-- .../encryption/encryption_internal_nossl.cc | 26 ++-- .../encryption/encryption_internal_test.cc | 2 +- .../encryption/internal_file_decryptor.cc | 4 +- .../encryption/internal_file_decryptor.h | 5 +- .../encryption/internal_file_encryptor.cc | 4 +- .../encryption/internal_file_encryptor.h | 5 +- .../encryption/key_toolkit_internal.cc | 2 +- cpp/src/parquet/geospatial/util_internal.cc | 4 +- cpp/src/parquet/geospatial/util_internal.h | 13 +- cpp/src/parquet/metadata.cc | 9 +- cpp/src/parquet/size_statistics.cc | 8 +- cpp/src/parquet/size_statistics.h | 6 +- cpp/src/parquet/size_statistics_test.cc | 2 +- cpp/src/parquet/stream_writer.h | 4 +- cpp/src/parquet/thrift_internal.h | 5 +- 41 files changed, 126 insertions(+), 249 deletions(-) delete mode 100644 cpp/src/arrow/util/span.h diff --git a/cpp/src/arrow/array/data.h b/cpp/src/arrow/array/data.h index c6636df9bb3..9617e17b5ae 100644 --- a/cpp/src/arrow/array/data.h +++ b/cpp/src/arrow/array/data.h @@ -31,7 +31,7 @@ #include "arrow/type_fwd.h" #include "arrow/util/bit_util.h" #include "arrow/util/macros.h" -#include "arrow/util/span.h" +#include #include "arrow/util/visibility.h" namespace arrow { diff --git a/cpp/src/arrow/array/util.cc b/cpp/src/arrow/array/util.cc index 03d8c32c4e3..bc62033abcc 100644 --- a/cpp/src/arrow/array/util.cc +++ b/cpp/src/arrow/array/util.cc @@ -44,7 +44,7 @@ #include "arrow/util/endian.h" #include "arrow/util/logging_internal.h" #include "arrow/util/sort_internal.h" -#include "arrow/util/span.h" +#include #include "arrow/visit_data_inline.h" #include "arrow/visit_type_inline.h" diff --git a/cpp/src/arrow/buffer.h b/cpp/src/arrow/buffer.h index ce909a3ea18..69ab4512217 100644 --- a/cpp/src/arrow/buffer.h +++ b/cpp/src/arrow/buffer.h @@ -30,7 +30,7 @@ #include "arrow/status.h" #include "arrow/type_fwd.h" #include "arrow/util/macros.h" -#include "arrow/util/span.h" +#include #include "arrow/util/visibility.h" namespace arrow { diff --git a/cpp/src/arrow/chunk_resolver.h b/cpp/src/arrow/chunk_resolver.h index 3d6458167fa..b76713b6652 100644 --- a/cpp/src/arrow/chunk_resolver.h +++ b/cpp/src/arrow/chunk_resolver.h @@ -26,7 +26,7 @@ #include "arrow/type_fwd.h" #include "arrow/util/macros.h" -#include "arrow/util/span.h" +#include namespace arrow { diff --git a/cpp/src/arrow/compute/kernels/aggregate_pivot.cc b/cpp/src/arrow/compute/kernels/aggregate_pivot.cc index 504c7cdd26d..21dcfe3bf4c 100644 --- a/cpp/src/arrow/compute/kernels/aggregate_pivot.cc +++ b/cpp/src/arrow/compute/kernels/aggregate_pivot.cc @@ -29,7 +29,7 @@ namespace arrow::compute::internal { namespace { using arrow::internal::VisitSetBitRunsVoid; -using arrow::util::span; +using std::span; struct PivotImpl : public ScalarAggregator { Status Init(const PivotWiderOptions& options, const std::vector& in_types, diff --git a/cpp/src/arrow/compute/kernels/chunked_internal.h b/cpp/src/arrow/compute/kernels/chunked_internal.h index 330bd185f25..624238b2005 100644 --- a/cpp/src/arrow/compute/kernels/chunked_internal.h +++ b/cpp/src/arrow/compute/kernels/chunked_internal.h @@ -26,7 +26,7 @@ #include "arrow/array.h" #include "arrow/chunk_resolver.h" #include "arrow/compute/kernels/codegen_internal.h" -#include "arrow/util/span.h" +#include #include "arrow/util/visibility.h" namespace arrow::compute::internal { diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate.cc b/cpp/src/arrow/compute/kernels/hash_aggregate.cc index 19f7fc2e5b0..e203685c679 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "arrow/array/builder_nested.h" #include "arrow/array/builder_primitive.h" @@ -44,14 +45,14 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/int_util_overflow.h" #include "arrow/util/ree_util.h" -#include "arrow/util/span.h" +#include #include "arrow/visit_type_inline.h" namespace arrow::compute::internal { using ::arrow::internal::checked_cast; using ::arrow::internal::FirstTimeBitmapWriter; -using ::arrow::util::span; +using std::span; namespace { diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc b/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc index aa231430aa0..73319a23e99 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc @@ -32,7 +32,7 @@ #include "arrow/compute/row/grouper.h" #include "arrow/util/checked_cast.h" #include "arrow/util/int128_internal.h" -#include "arrow/util/span.h" +#include #include "arrow/util/tdigest_internal.h" #include "arrow/visit_type_inline.h" diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate_pivot.cc b/cpp/src/arrow/compute/kernels/hash_aggregate_pivot.cc index f60aa367ca2..e110e4b0c1b 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate_pivot.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate_pivot.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "arrow/array/concatenate.h" #include "arrow/compute/api_aggregate.h" @@ -33,12 +34,11 @@ #include "arrow/util/bit_block_counter.h" #include "arrow/util/checked_cast.h" #include "arrow/util/logging_internal.h" -#include "arrow/util/span.h" #include "arrow/visit_type_inline.h" namespace arrow::compute::internal { -using ::arrow::util::span; +using std::span; namespace { diff --git a/cpp/src/arrow/compute/kernels/pivot_internal.cc b/cpp/src/arrow/compute/kernels/pivot_internal.cc index e9065152d7f..9a442da3d3d 100644 --- a/cpp/src/arrow/compute/kernels/pivot_internal.cc +++ b/cpp/src/arrow/compute/kernels/pivot_internal.cc @@ -37,7 +37,7 @@ namespace arrow::compute::internal { -using ::arrow::util::span; +using std::span; struct ConcretePivotWiderKeyMapper : public PivotWiderKeyMapper { Status Init(const DataType& key_type, const PivotWiderOptions* options, diff --git a/cpp/src/arrow/compute/kernels/vector_rank.cc b/cpp/src/arrow/compute/kernels/vector_rank.cc index ef7419ea7c5..8c7c2d90cd9 100644 --- a/cpp/src/arrow/compute/kernels/vector_rank.cc +++ b/cpp/src/arrow/compute/kernels/vector_rank.cc @@ -27,7 +27,7 @@ namespace arrow::compute::internal { -using ::arrow::util::span; +using std::span; namespace { diff --git a/cpp/src/arrow/integration/json_internal.cc b/cpp/src/arrow/integration/json_internal.cc index 4b0fc693931..0c0c2b6a7f0 100644 --- a/cpp/src/arrow/integration/json_internal.cc +++ b/cpp/src/arrow/integration/json_internal.cc @@ -48,7 +48,7 @@ #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging_internal.h" #include "arrow/util/range.h" -#include "arrow/util/span.h" +#include #include "arrow/util/string.h" #include "arrow/util/value_parsing.h" #include "arrow/visit_array_inline.h" diff --git a/cpp/src/arrow/util/binary_view_util.h b/cpp/src/arrow/util/binary_view_util.h index eb079e2c548..7891dac2d60 100644 --- a/cpp/src/arrow/util/binary_view_util.h +++ b/cpp/src/arrow/util/binary_view_util.h @@ -21,7 +21,7 @@ #include #include "arrow/type.h" -#include "arrow/util/span.h" +#include namespace arrow::util { diff --git a/cpp/src/arrow/util/bitmap.h b/cpp/src/arrow/util/bitmap.h index 141d558c3a8..d799954b2d8 100644 --- a/cpp/src/arrow/util/bitmap.h +++ b/cpp/src/arrow/util/bitmap.h @@ -36,7 +36,7 @@ #include "arrow/util/compare.h" #include "arrow/util/endian.h" #include "arrow/util/functional.h" -#include "arrow/util/span.h" +#include #include "arrow/util/string_util.h" #include "arrow/util/visibility.h" diff --git a/cpp/src/arrow/util/bitmap_builders.h b/cpp/src/arrow/util/bitmap_builders.h index 4bf2edfdcbd..1bb90866af2 100644 --- a/cpp/src/arrow/util/bitmap_builders.h +++ b/cpp/src/arrow/util/bitmap_builders.h @@ -23,7 +23,7 @@ #include "arrow/result.h" #include "arrow/type_fwd.h" -#include "arrow/util/span.h" +#include #include "arrow/util/visibility.h" namespace arrow { diff --git a/cpp/src/arrow/util/float16_test.cc b/cpp/src/arrow/util/float16_test.cc index 5918381a269..f0dc2a0f7cc 100644 --- a/cpp/src/arrow/util/float16_test.cc +++ b/cpp/src/arrow/util/float16_test.cc @@ -24,7 +24,7 @@ #include "arrow/testing/gtest_util.h" #include "arrow/util/endian.h" #include "arrow/util/float16.h" -#include "arrow/util/span.h" +#include #include "arrow/util/ubsan.h" namespace arrow::util { diff --git a/cpp/src/arrow/util/rle_encoding_test.cc b/cpp/src/arrow/util/rle_encoding_test.cc index b2d4f7df6f1..2314c1bab00 100644 --- a/cpp/src/arrow/util/rle_encoding_test.cc +++ b/cpp/src/arrow/util/rle_encoding_test.cc @@ -35,7 +35,7 @@ #include "arrow/util/bit_util.h" #include "arrow/util/io_util.h" #include "arrow/util/rle_encoding_internal.h" -#include "arrow/util/span.h" +#include namespace arrow::util { diff --git a/cpp/src/arrow/util/secure_string.cc b/cpp/src/arrow/util/secure_string.cc index bd52c55f312..a45ecce929c 100644 --- a/cpp/src/arrow/util/secure_string.cc +++ b/cpp/src/arrow/util/secure_string.cc @@ -33,7 +33,7 @@ #include "arrow/util/logging.h" #include "arrow/util/secure_string.h" -#include "arrow/util/span.h" +#include namespace arrow::util { diff --git a/cpp/src/arrow/util/secure_string.h b/cpp/src/arrow/util/secure_string.h index 30088c78d4c..d9f31f4c0b8 100644 --- a/cpp/src/arrow/util/secure_string.h +++ b/cpp/src/arrow/util/secure_string.h @@ -20,7 +20,7 @@ #include #include -#include "arrow/util/span.h" +#include #include "arrow/util/visibility.h" namespace arrow::util { diff --git a/cpp/src/arrow/util/span.h b/cpp/src/arrow/util/span.h deleted file mode 100644 index 1e57ee8c8d1..00000000000 --- a/cpp/src/arrow/util/span.h +++ /dev/null @@ -1,132 +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 - -namespace arrow::util { - -template -class span; - -/// std::span polyfill. -/// -/// Does not support static extents. -template -class span { - static_assert(sizeof(T), - R"( -std::span allows contiguous_iterators instead of just pointers, the enforcement -of which requires T to be a complete type. arrow::util::span does not support -contiguous_iterators, but T is still required to be a complete type to prevent -writing code which would break when it is replaced by std::span.)"); - - public: - using element_type = T; - using value_type = std::remove_cv_t; - using iterator = T*; - using const_iterator = T const*; - - span() = default; - span(const span&) = default; - span& operator=(const span&) = default; - - template >> - // NOLINTNEXTLINE runtime/explicit - constexpr span(span mut) : span{mut.data(), mut.size()} {} - - constexpr span(T* data, size_t count) : data_{data}, size_{count} {} - - constexpr span(T* begin, T* end) - : data_{begin}, size_{static_cast(end - begin)} {} - - template ())), - typename RS = decltype(std::size(std::declval())), - typename E = std::enable_if_t && - std::is_constructible_v>> - // NOLINTNEXTLINE runtime/explicit, non-const reference - constexpr span(R&& range) : data_{std::data(range)}, size_{std::size(range)} {} - - constexpr T* begin() const { return data_; } - constexpr T* end() const { return data_ + size_; } - constexpr T* data() const { return data_; } - - constexpr size_t size() const { return size_; } - constexpr size_t size_bytes() const { return size_ * sizeof(T); } - constexpr bool empty() const { return size_ == 0; } - - constexpr T& operator[](size_t i) { return data_[i]; } - constexpr const T& operator[](size_t i) const { return data_[i]; } - - constexpr span subspan(size_t offset) const { - if (offset > size_) return {data_, data_}; - return {data_ + offset, size_ - offset}; - } - - constexpr span subspan(size_t offset, size_t count) const { - auto out = subspan(offset); - if (count < out.size_) { - out.size_ = count; - } - return out; - } - - constexpr bool operator==(const span& other) const { - if (size_ != other.size_) return false; - - if constexpr (std::is_integral_v) { - if (size_ == 0) { - return true; // memcmp does not handle null pointers, even if size_ == 0 - } - return std::memcmp(data_, other.data_, size_bytes()) == 0; - } else { - T* ptr = data_; - for (T const& e : other) { - if (*ptr++ != e) return false; - } - return true; - } - } - constexpr bool operator!=(const span& other) const { return !(*this == other); } - - private: - T* data_{}; - size_t size_{}; -}; - -template -span(R& range) -> span>; - -template -span(T*, size_t) -> span; - -template -constexpr span as_bytes(span s) { - return {reinterpret_cast(s.data()), s.size_bytes()}; -} - -template -constexpr span as_writable_bytes(span s) { - return {reinterpret_cast(s.data()), s.size_bytes()}; -} - -} // namespace arrow::util diff --git a/cpp/src/arrow/util/span_test.cc b/cpp/src/arrow/util/span_test.cc index 01460c2bd03..68320d06004 100644 --- a/cpp/src/arrow/util/span_test.cc +++ b/cpp/src/arrow/util/span_test.cc @@ -22,16 +22,16 @@ #include "arrow/testing/gtest_util.h" #include "arrow/testing/matchers.h" -#include "arrow/util/span.h" +#include using testing::ElementsAre; using testing::ElementsAreArray; using testing::PrintToString; -namespace arrow::util { +namespace arrow_util_span_test { template -std::ostream& operator<<(std::ostream& os, const span& span) { +std::ostream& operator<<(std::ostream& os, const std::span& span) { // Inefficient but good enough for testing os << PrintToString(std::vector(span.begin(), span.end())); return os; @@ -39,33 +39,33 @@ std::ostream& operator<<(std::ostream& os, const span& span) { TEST(Span, Construction) { // const spans may be constructed from mutable spans - static_assert(std::is_constructible_v, span>); + static_assert(std::is_constructible_v, std::span>); // ... but mutable spans may be constructed from const spans - static_assert(!std::is_constructible_v, span>); + static_assert(!std::is_constructible_v, std::span>); int arr[] = {1, 2, 3}; constexpr int const_arr[] = {7, 8, 9}; - static_assert(std::is_constructible_v, decltype(arr)&>); - static_assert(!std::is_constructible_v, decltype(const_arr)&>); + static_assert(std::is_constructible_v, decltype(arr)&>); + static_assert(!std::is_constructible_v, decltype(const_arr)&>); - static_assert(std::is_constructible_v, decltype(arr)&>); - static_assert(std::is_constructible_v, decltype(const_arr)&>); + static_assert(std::is_constructible_v, decltype(arr)&>); + static_assert(std::is_constructible_v, decltype(const_arr)&>); - static_assert(std::is_constructible_v, std::vector&>); - static_assert(!std::is_constructible_v, const std::vector&>); - static_assert(!std::is_constructible_v, std::vector&&>); + static_assert(std::is_constructible_v, std::vector&>); + static_assert(!std::is_constructible_v, const std::vector&>); + static_assert(!std::is_constructible_v, std::vector&&>); - static_assert(std::is_constructible_v, std::vector&>); - static_assert(std::is_constructible_v, const std::vector&>); + static_assert(std::is_constructible_v, std::vector&>); + static_assert(std::is_constructible_v, const std::vector&>); // const spans may even be constructed from rvalue ranges - static_assert(std::is_constructible_v, std::vector&&>); + static_assert(std::is_constructible_v, std::vector&&>); - EXPECT_THAT(span(const_arr), ElementsAreArray(const_arr)); - EXPECT_THAT(span(arr), ElementsAreArray(arr)); + EXPECT_THAT(std::span(const_arr), ElementsAreArray(const_arr)); + EXPECT_THAT(std::span(arr), ElementsAreArray(arr)); - static_assert(!std::is_constructible_v, decltype(const_arr)&>); - static_assert(!std::is_constructible_v, decltype(const_arr)&>); + static_assert(!std::is_constructible_v, decltype(const_arr)&>); + static_assert(!std::is_constructible_v, decltype(const_arr)&>); } TEST(Span, TemplateArgumentDeduction) { @@ -73,10 +73,10 @@ TEST(Span, TemplateArgumentDeduction) { const int const_arr[] = {1, 2, 3}; std::vector vec; const std::vector const_vec; - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); } TEST(Span, Size) { @@ -109,7 +109,7 @@ TEST(Span, Equality) { { // exercise integral branch with memcmp - check_eq(span(), span()); + check_eq(std::span(), std::span()); int arr[] = {1, 2, 3}; check_eq(span(arr), span(arr)); @@ -131,7 +131,7 @@ TEST(Span, Equality) { } { // exercise non-integral branch with for loop - check_eq(span(), span()); + check_eq(std::span(), std::span()); std::string arr[] = {"a", "b", "c"}; check_eq(span(arr), span(arr)); @@ -156,7 +156,7 @@ TEST(Span, SubSpan) { int arr[] = {1, 2, 3}; span s(arr); - auto ExpectIdentical = [](span l, span r) { + auto ExpectIdentical = [](std::span l, std::span r) { EXPECT_EQ(l.data(), r.data()); EXPECT_EQ(l.size(), r.size()); }; @@ -190,7 +190,7 @@ TEST(Span, Mutation) { EXPECT_THAT(arr, ElementsAre(0, 1, 4, 9, 16)); - auto set = [](span lhs, size_t rhs) { + auto set = [](std::span lhs, size_t rhs) { for (size_t& i : lhs) { i = rhs; } @@ -201,4 +201,4 @@ TEST(Span, Mutation) { EXPECT_THAT(arr, ElementsAre(0, 1, 23, 23, 1)); } -} // namespace arrow::util +} // namespace arrow_util_span_test diff --git a/cpp/src/parquet/column_writer.cc b/cpp/src/parquet/column_writer.cc index 94b67dfa807..f671651b31e 100644 --- a/cpp/src/parquet/column_writer.cc +++ b/cpp/src/parquet/column_writer.cc @@ -1781,7 +1781,7 @@ class TypedColumnWriterImpl : public ColumnWriterImpl, } auto add_levels = [](std::vector& level_histogram, - ::arrow::util::span levels, int16_t max_level) { + std::span levels, int16_t max_level) { if (max_level == 0) { return; } diff --git a/cpp/src/parquet/encoding_test.cc b/cpp/src/parquet/encoding_test.cc index 66a3f7647fa..1149cc7d024 100644 --- a/cpp/src/parquet/encoding_test.cc +++ b/cpp/src/parquet/encoding_test.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include "arrow/array.h" #include "arrow/array/builder_binary.h" @@ -39,7 +40,7 @@ #include "arrow/util/bitmap_writer.h" #include "arrow/util/checked_cast.h" #include "arrow/util/endian.h" -#include "arrow/util/span.h" +#include #include "arrow/util/string.h" #include "parquet/encoding.h" #include "parquet/platform.h" @@ -50,7 +51,7 @@ using arrow::default_memory_pool; using arrow::MemoryPool; using arrow::internal::checked_cast; -using arrow::util::span; +using std::span; namespace bit_util = arrow::bit_util; @@ -2111,7 +2112,7 @@ std::shared_ptr DeltaEncode(std::vector lengths) { return encoder->FlushValues(); } -std::shared_ptr DeltaEncode(::arrow::util::span lengths) { +std::shared_ptr DeltaEncode(std::span lengths) { auto encoder = MakeTypedEncoder(Encoding::DELTA_BINARY_PACKED); encoder->Put(lengths.data(), static_cast(lengths.size())); return encoder->FlushValues(); @@ -2119,7 +2120,7 @@ std::shared_ptr DeltaEncode(::arrow::util::span lengths) std::shared_ptr DeltaEncode(std::shared_ptr<::arrow::Array>& lengths) { auto data = ::arrow::internal::checked_pointer_cast(lengths); - auto span = ::arrow::util::span{data->raw_values(), + auto span = std::span{data->raw_values(), static_cast(lengths->length())}; return DeltaEncode(span); } diff --git a/cpp/src/parquet/encryption/encryption.h b/cpp/src/parquet/encryption/encryption.h index b4634b70473..023a536fd91 100644 --- a/cpp/src/parquet/encryption/encryption.h +++ b/cpp/src/parquet/encryption/encryption.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -95,7 +96,7 @@ class PARQUET_EXPORT KeyAccessDeniedException : public ParquetException { : ParquetException(columnPath.c_str()) {} }; -inline ::arrow::util::span str2span(const std::string& str) { +inline std::span str2span(const std::string& str) { if (str.empty()) { return {}; } diff --git a/cpp/src/parquet/encryption/encryption_internal.cc b/cpp/src/parquet/encryption/encryption_internal.cc index 9400fae0adf..4e90ab95b10 100644 --- a/cpp/src/parquet/encryption/encryption_internal.cc +++ b/cpp/src/parquet/encryption/encryption_internal.cc @@ -29,11 +29,12 @@ #include #include #include +#include #include "parquet/encryption/openssl_internal.h" #include "parquet/exception.h" -using ::arrow::util::span; +using std::span; using parquet::ParquetException; namespace parquet::encryption { diff --git a/cpp/src/parquet/encryption/encryption_internal.h b/cpp/src/parquet/encryption/encryption_internal.h index 06252749565..e3f795575ad 100644 --- a/cpp/src/parquet/encryption/encryption_internal.h +++ b/cpp/src/parquet/encryption/encryption_internal.h @@ -21,7 +21,7 @@ #include #include -#include "arrow/util/span.h" +#include #include "parquet/properties.h" #include "parquet/types.h" @@ -62,17 +62,17 @@ class PARQUET_EXPORT AesEncryptor { /// Encrypts plaintext with the key and aad. Key length is passed only for validation. /// If different from value in constructor, exception will be thrown. - int32_t Encrypt(::arrow::util::span plaintext, - ::arrow::util::span key, - ::arrow::util::span aad, - ::arrow::util::span ciphertext); + int32_t Encrypt(std::span plaintext, + std::span key, + std::span aad, + std::span ciphertext); /// Encrypts plaintext footer, in order to compute footer signature (tag). - int32_t SignedFooterEncrypt(::arrow::util::span footer, - ::arrow::util::span key, - ::arrow::util::span aad, - ::arrow::util::span nonce, - ::arrow::util::span encrypted_footer); + int32_t SignedFooterEncrypt(std::span footer, + std::span key, + std::span aad, + std::span nonce, + std::span encrypted_footer); private: // PIMPL Idiom @@ -107,10 +107,10 @@ class PARQUET_EXPORT AesDecryptor { /// validation. If different from value in constructor, exception will be thrown. /// The caller is responsible for ensuring that the plaintext buffer is at least as /// large as PlaintextLength(ciphertext_len). - int32_t Decrypt(::arrow::util::span ciphertext, - ::arrow::util::span key, - ::arrow::util::span aad, - ::arrow::util::span plaintext); + int32_t Decrypt(std::span ciphertext, + std::span key, + std::span aad, + std::span plaintext); private: // PIMPL Idiom diff --git a/cpp/src/parquet/encryption/encryption_internal_nossl.cc b/cpp/src/parquet/encryption/encryption_internal_nossl.cc index 2450f8654d6..715806e65e5 100644 --- a/cpp/src/parquet/encryption/encryption_internal_nossl.cc +++ b/cpp/src/parquet/encryption/encryption_internal_nossl.cc @@ -33,11 +33,11 @@ class AesEncryptor::AesEncryptorImpl {}; AesEncryptor::~AesEncryptor() {} -int32_t AesEncryptor::SignedFooterEncrypt(::arrow::util::span footer, - ::arrow::util::span key, - ::arrow::util::span aad, - ::arrow::util::span nonce, - ::arrow::util::span encrypted_footer) { +int32_t AesEncryptor::SignedFooterEncrypt(std::span footer, + std::span key, + std::span aad, + std::span nonce, + std::span encrypted_footer) { ThrowOpenSSLRequiredException(); return -1; } @@ -47,10 +47,10 @@ int32_t AesEncryptor::CiphertextLength(int64_t plaintext_len) const { return -1; } -int32_t AesEncryptor::Encrypt(::arrow::util::span plaintext, - ::arrow::util::span key, - ::arrow::util::span aad, - ::arrow::util::span ciphertext) { +int32_t AesEncryptor::Encrypt(std::span plaintext, + std::span key, + std::span aad, + std::span ciphertext) { ThrowOpenSSLRequiredException(); return -1; } @@ -62,10 +62,10 @@ AesEncryptor::AesEncryptor(ParquetCipher::type alg_id, int32_t key_len, bool met class AesDecryptor::AesDecryptorImpl {}; -int32_t AesDecryptor::Decrypt(::arrow::util::span ciphertext, - ::arrow::util::span key, - ::arrow::util::span aad, - ::arrow::util::span plaintext) { +int32_t AesDecryptor::Decrypt(std::span ciphertext, + std::span key, + std::span aad, + std::span plaintext) { ThrowOpenSSLRequiredException(); return -1; } diff --git a/cpp/src/parquet/encryption/encryption_internal_test.cc b/cpp/src/parquet/encryption/encryption_internal_test.cc index bf6607e3287..1c96f4cb721 100644 --- a/cpp/src/parquet/encryption/encryption_internal_test.cc +++ b/cpp/src/parquet/encryption/encryption_internal_test.cc @@ -97,7 +97,7 @@ class TestAesEncryption : public ::testing::Test { int32_t expected_plaintext_length = decryptor.PlaintextLength(ciphertext_length); std::vector decrypted_text(expected_plaintext_length, '\0'); - ::arrow::util::span truncated_ciphertext(ciphertext.data(), + std::span truncated_ciphertext(ciphertext.data(), ciphertext_length - 1); EXPECT_THROW(decryptor.Decrypt(truncated_ciphertext, str2span(key_), str2span(aad_), decrypted_text), diff --git a/cpp/src/parquet/encryption/internal_file_decryptor.cc b/cpp/src/parquet/encryption/internal_file_decryptor.cc index b90d3158559..e7eed4529b9 100644 --- a/cpp/src/parquet/encryption/internal_file_decryptor.cc +++ b/cpp/src/parquet/encryption/internal_file_decryptor.cc @@ -47,8 +47,8 @@ int32_t Decryptor::CiphertextLength(int32_t plaintext_len) const { return aes_decryptor_->CiphertextLength(plaintext_len); } -int32_t Decryptor::Decrypt(::arrow::util::span ciphertext, - ::arrow::util::span plaintext) { +int32_t Decryptor::Decrypt(std::span ciphertext, + std::span plaintext) { return aes_decryptor_->Decrypt(ciphertext, key_.as_span(), str2span(aad_), plaintext); } diff --git a/cpp/src/parquet/encryption/internal_file_decryptor.h b/cpp/src/parquet/encryption/internal_file_decryptor.h index a365b4df4bf..7a21fa55a66 100644 --- a/cpp/src/parquet/encryption/internal_file_decryptor.h +++ b/cpp/src/parquet/encryption/internal_file_decryptor.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -52,8 +53,8 @@ class PARQUET_EXPORT Decryptor { [[nodiscard]] int32_t PlaintextLength(int32_t ciphertext_len) const; [[nodiscard]] int32_t CiphertextLength(int32_t plaintext_len) const; - int32_t Decrypt(::arrow::util::span ciphertext, - ::arrow::util::span plaintext); + int32_t Decrypt(std::span ciphertext, + std::span plaintext); private: std::unique_ptr aes_decryptor_; diff --git a/cpp/src/parquet/encryption/internal_file_encryptor.cc b/cpp/src/parquet/encryption/internal_file_encryptor.cc index f6fc0849984..ce5620d1e9b 100644 --- a/cpp/src/parquet/encryption/internal_file_encryptor.cc +++ b/cpp/src/parquet/encryption/internal_file_encryptor.cc @@ -37,8 +37,8 @@ int32_t Encryptor::CiphertextLength(int64_t plaintext_len) const { return aes_encryptor_->CiphertextLength(plaintext_len); } -int32_t Encryptor::Encrypt(::arrow::util::span plaintext, - ::arrow::util::span ciphertext) { +int32_t Encryptor::Encrypt(std::span plaintext, + std::span ciphertext) { return aes_encryptor_->Encrypt(plaintext, key_.as_span(), str2span(aad_), ciphertext); } diff --git a/cpp/src/parquet/encryption/internal_file_encryptor.h b/cpp/src/parquet/encryption/internal_file_encryptor.h index ee15fe32de9..b430c5cc139 100644 --- a/cpp/src/parquet/encryption/internal_file_encryptor.h +++ b/cpp/src/parquet/encryption/internal_file_encryptor.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -44,8 +45,8 @@ class PARQUET_EXPORT Encryptor { [[nodiscard]] int32_t CiphertextLength(int64_t plaintext_len) const; - int32_t Encrypt(::arrow::util::span plaintext, - ::arrow::util::span ciphertext); + int32_t Encrypt(std::span plaintext, + std::span ciphertext); bool EncryptColumnMetaData( bool encrypted_footer, diff --git a/cpp/src/parquet/encryption/key_toolkit_internal.cc b/cpp/src/parquet/encryption/key_toolkit_internal.cc index 60a8a52206c..407d4297b2a 100644 --- a/cpp/src/parquet/encryption/key_toolkit_internal.cc +++ b/cpp/src/parquet/encryption/key_toolkit_internal.cc @@ -38,7 +38,7 @@ std::string EncryptKeyLocally(const SecureString& key_bytes, int32_t encrypted_key_len = key_encryptor.CiphertextLength(static_cast(key_bytes.size())); std::string encrypted_key(encrypted_key_len, '\0'); - ::arrow::util::span encrypted_key_span( + std::span encrypted_key_span( reinterpret_cast(&encrypted_key[0]), encrypted_key_len); encrypted_key_len = key_encryptor.Encrypt(key_bytes.as_span(), master_key.as_span(), diff --git a/cpp/src/parquet/geospatial/util_internal.cc b/cpp/src/parquet/geospatial/util_internal.cc index d5c8d662884..9605d627a2a 100644 --- a/cpp/src/parquet/geospatial/util_internal.cc +++ b/cpp/src/parquet/geospatial/util_internal.cc @@ -147,11 +147,11 @@ std::vector WKBGeometryBounder::GeometryTypes() const { } void WKBGeometryBounder::MergeGeometry(std::string_view bytes_wkb) { - MergeGeometry(::arrow::util::span(reinterpret_cast(bytes_wkb.data()), + MergeGeometry(std::span(reinterpret_cast(bytes_wkb.data()), bytes_wkb.size())); } -void WKBGeometryBounder::MergeGeometry(::arrow::util::span bytes_wkb) { +void WKBGeometryBounder::MergeGeometry(std::span bytes_wkb) { WKBBuffer src{bytes_wkb.data(), static_cast(bytes_wkb.size())}; MergeGeometryInternal(&src, /*record_wkb_type=*/true); if (src.size() != 0) { diff --git a/cpp/src/parquet/geospatial/util_internal.h b/cpp/src/parquet/geospatial/util_internal.h index 2de9e1d076f..362ea7ed55f 100644 --- a/cpp/src/parquet/geospatial/util_internal.h +++ b/cpp/src/parquet/geospatial/util_internal.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -94,19 +95,19 @@ struct PARQUET_EXPORT BoundingBox { BoundingBox& operator=(const BoundingBox&) = default; /// \brief Update the X and Y bounds to ensure these bounds contain coord - void UpdateXY(::arrow::util::span coord) { + void UpdateXY(std::span coord) { DCHECK_EQ(coord.size(), 2); UpdateInternal(coord); } /// \brief Update the X, Y, and Z bounds to ensure these bounds contain coord - void UpdateXYZ(::arrow::util::span coord) { + void UpdateXYZ(std::span coord) { DCHECK_EQ(coord.size(), 3); UpdateInternal(coord); } /// \brief Update the X, Y, and M bounds to ensure these bounds contain coord - void UpdateXYM(::arrow::util::span coord) { + void UpdateXYM(std::span coord) { DCHECK_EQ(coord.size(), 3); min[0] = std::min(min[0], coord[0]); min[1] = std::min(min[1], coord[1]); @@ -117,7 +118,7 @@ struct PARQUET_EXPORT BoundingBox { } /// \brief Update the X, Y, Z, and M bounds to ensure these bounds contain coord - void UpdateXYZM(::arrow::util::span coord) { + void UpdateXYZM(std::span coord) { DCHECK_EQ(coord.size(), 4); UpdateInternal(coord); } @@ -190,13 +191,13 @@ class PARQUET_EXPORT WKBGeometryBounder { /// the geometry is added to the internal geometry type list. void MergeGeometry(std::string_view bytes_wkb); - void MergeGeometry(::arrow::util::span bytes_wkb); + void MergeGeometry(std::span bytes_wkb); /// \brief Accumulate the bounds of a previously-calculated BoundingBox void MergeBox(const BoundingBox& box) { box_.Merge(box); } /// \brief Accumulate a previously-calculated list of geometry types - void MergeGeometryTypes(::arrow::util::span geospatial_types) { + void MergeGeometryTypes(std::span geospatial_types) { geospatial_types_.insert(geospatial_types.begin(), geospatial_types.end()); } diff --git a/cpp/src/parquet/metadata.cc b/cpp/src/parquet/metadata.cc index 42dd8e52ee9..a8e64ff8312 100644 --- a/cpp/src/parquet/metadata.cc +++ b/cpp/src/parquet/metadata.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -809,11 +810,11 @@ class FileMetaData::FileMetaDataImpl { uint32_t serialized_len = metadata_len_; ThriftSerializer serializer; serializer.SerializeToBuffer(metadata_.get(), &serialized_len, &serialized_data); - ::arrow::util::span serialized_data_span(serialized_data, + std::span serialized_data_span(serialized_data, serialized_len); // encrypt with nonce - ::arrow::util::span nonce(reinterpret_cast(signature), + std::span nonce(reinterpret_cast(signature), encryption::kNonceLength); auto tag = reinterpret_cast(signature) + encryption::kNonceLength; @@ -867,7 +868,7 @@ class FileMetaData::FileMetaDataImpl { uint8_t* serialized_data; uint32_t serialized_len; serializer.SerializeToBuffer(metadata_.get(), &serialized_len, &serialized_data); - ::arrow::util::span serialized_data_span(serialized_data, + std::span serialized_data_span(serialized_data, serialized_len); // encrypt the footer key @@ -1737,7 +1738,7 @@ class ColumnChunkMetaDataBuilder::ColumnChunkMetaDataBuilderImpl { serializer.SerializeToBuffer(&column_chunk_->meta_data, &serialized_len, &serialized_data); - ::arrow::util::span serialized_data_span(serialized_data, + std::span serialized_data_span(serialized_data, serialized_len); std::vector encrypted_data(encryptor->CiphertextLength(serialized_len)); diff --git a/cpp/src/parquet/size_statistics.cc b/cpp/src/parquet/size_statistics.cc index 0b30d7c8bbd..d12a07c3dca 100644 --- a/cpp/src/parquet/size_statistics.cc +++ b/cpp/src/parquet/size_statistics.cc @@ -32,8 +32,8 @@ namespace parquet { namespace { -void MergeLevelHistogram(::arrow::util::span histogram, - ::arrow::util::span other) { +void MergeLevelHistogram(std::span histogram, + std::span other) { ARROW_DCHECK_EQ(histogram.size(), other.size()); std::transform(histogram.begin(), histogram.end(), other.begin(), histogram.begin(), std::plus<>()); @@ -143,8 +143,8 @@ std::ostream& operator<<(std::ostream& os, const SizeStatistics& size_stats) { return os; } -void UpdateLevelHistogram(::arrow::util::span levels, - ::arrow::util::span histogram) { +void UpdateLevelHistogram(std::span levels, + std::span histogram) { const int64_t num_levels = static_cast(levels.size()); DCHECK_GE(histogram.size(), 1); const int16_t max_level = static_cast(histogram.size() - 1); diff --git a/cpp/src/parquet/size_statistics.h b/cpp/src/parquet/size_statistics.h index ec79b8c4f8b..9349672928e 100644 --- a/cpp/src/parquet/size_statistics.h +++ b/cpp/src/parquet/size_statistics.h @@ -22,7 +22,7 @@ #include #include -#include "arrow/util/span.h" +#include #include "parquet/platform.h" #include "parquet/type_fwd.h" @@ -96,7 +96,7 @@ PARQUET_EXPORT std::ostream& operator<<(std::ostream&, const SizeStatistics&); PARQUET_EXPORT -void UpdateLevelHistogram(::arrow::util::span levels, - ::arrow::util::span histogram); +void UpdateLevelHistogram(std::span levels, + std::span histogram); } // namespace parquet diff --git a/cpp/src/parquet/size_statistics_test.cc b/cpp/src/parquet/size_statistics_test.cc index 6e8cec9a130..ea88b70694e 100644 --- a/cpp/src/parquet/size_statistics_test.cc +++ b/cpp/src/parquet/size_statistics_test.cc @@ -25,7 +25,7 @@ #include "arrow/buffer.h" #include "arrow/table.h" #include "arrow/testing/gtest_util.h" -#include "arrow/util/span.h" +#include #include "parquet/arrow/reader.h" #include "parquet/arrow/schema.h" #include "parquet/arrow/writer.h" diff --git a/cpp/src/parquet/stream_writer.h b/cpp/src/parquet/stream_writer.h index 76265140222..fd8192102b9 100644 --- a/cpp/src/parquet/stream_writer.h +++ b/cpp/src/parquet/stream_writer.h @@ -26,7 +26,7 @@ #include #include -#include "arrow/util/span.h" +#include #include "parquet/column_writer.h" #include "parquet/file_writer.h" @@ -154,7 +154,7 @@ class PARQUET_EXPORT StreamWriter { StreamWriter& operator<<(::std::string_view v); /// \brief Helper class to write variable length raw data. - using RawDataView = ::arrow::util::span; + using RawDataView = std::span; /// \brief Output operators for variable length raw data. StreamWriter& operator<<(RawDataView v); diff --git a/cpp/src/parquet/thrift_internal.h b/cpp/src/parquet/thrift_internal.h index 1ffe99eb3c9..99dc1d6104e 100644 --- a/cpp/src/parquet/thrift_internal.h +++ b/cpp/src/parquet/thrift_internal.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -580,7 +581,7 @@ class ThriftDeserializer { // decrypt auto decrypted_buffer = AllocateBuffer( decryptor->pool(), decryptor->PlaintextLength(static_cast(clen))); - ::arrow::util::span cipher_buf(buf, clen); + std::span cipher_buf(buf, clen); uint32_t decrypted_buffer_len = decryptor->Decrypt(cipher_buf, decrypted_buffer->mutable_span_as()); if (decrypted_buffer_len <= 0) { @@ -690,7 +691,7 @@ class ThriftSerializer { uint32_t out_length, Encryptor* encryptor) { auto cipher_buffer = AllocateBuffer(encryptor->pool(), encryptor->CiphertextLength(out_length)); - ::arrow::util::span out_span(out_buffer, out_length); + std::span out_span(out_buffer, out_length); int32_t cipher_buffer_len = encryptor->Encrypt(out_span, cipher_buffer->mutable_span_as()); From ce3a066c14eba0141909bae213797debefc01843 Mon Sep 17 00:00:00 2001 From: Jackie Yan Date: Tue, 23 Dec 2025 23:00:12 +0800 Subject: [PATCH 2/4] refactor: replace arrow::util::span with std::span --- cpp/src/arrow/array/concatenate.cc | 2 +- cpp/src/arrow/array/data.cc | 6 +- cpp/src/arrow/array/data.h | 13 ++- cpp/src/arrow/array/util.cc | 6 +- cpp/src/arrow/array/validate.cc | 6 +- cpp/src/arrow/buffer.h | 10 +-- cpp/src/arrow/c/bridge.cc | 2 +- cpp/src/arrow/c/bridge_test.cc | 4 +- cpp/src/arrow/chunk_resolver.cc | 2 +- cpp/src/arrow/chunk_resolver.h | 4 +- .../arrow/compute/kernels/chunked_internal.cc | 2 +- .../arrow/compute/kernels/chunked_internal.h | 13 ++- .../arrow/compute/kernels/hash_aggregate.cc | 4 +- .../compute/kernels/hash_aggregate_numeric.cc | 3 +- cpp/src/arrow/compute/kernels/vector_sort.cc | 2 +- .../compute/kernels/vector_sort_internal.h | 2 +- cpp/src/arrow/integration/json_internal.cc | 8 +- cpp/src/arrow/util/binary_view_util.h | 2 +- cpp/src/arrow/util/bitmap.h | 9 +-- cpp/src/arrow/util/bitmap_builders.cc | 4 +- cpp/src/arrow/util/bitmap_builders.h | 5 +- cpp/src/arrow/util/float16_test.cc | 6 +- cpp/src/arrow/util/rle_encoding_test.cc | 6 +- cpp/src/arrow/util/secure_string.cc | 12 +-- cpp/src/arrow/util/span_test.cc | 80 +++++++++---------- cpp/src/parquet/encoding_test.cc | 7 +- .../parquet/encryption/encryption_internal.cc | 15 ++-- cpp/src/parquet/metadata.cc | 4 +- cpp/src/parquet/size_statistics_test.cc | 8 +- cpp/src/parquet/stream_writer.h | 3 +- cpp/src/parquet/thrift_internal.h | 4 +- 31 files changed, 107 insertions(+), 147 deletions(-) diff --git a/cpp/src/arrow/array/concatenate.cc b/cpp/src/arrow/array/concatenate.cc index 2b832b977f2..90ae952a2e8 100644 --- a/cpp/src/arrow/array/concatenate.cc +++ b/cpp/src/arrow/array/concatenate.cc @@ -424,7 +424,7 @@ class ConcatenateImpl { out_->buffers.resize(2); for (const auto& in_data : in_) { - for (const auto& buf : util::span(in_data->buffers).subspan(2)) { + for (const auto& buf : std::span(in_data->buffers).subspan(2)) { out_->buffers.push_back(buf); } } diff --git a/cpp/src/arrow/array/data.cc b/cpp/src/arrow/array/data.cc index 1c56a485062..51ba77863b1 100644 --- a/cpp/src/arrow/array/data.cc +++ b/cpp/src/arrow/array/data.cc @@ -102,7 +102,7 @@ bool DictionaryMayHaveLogicalNulls(const ArrayData& data) { namespace { -BufferSpan PackVariadicBuffers(util::span> buffers) { +BufferSpan PackVariadicBuffers(std::span> buffers) { return {const_cast(reinterpret_cast(buffers.data())), static_cast(buffers.size() * sizeof(std::shared_ptr))}; } @@ -322,7 +322,7 @@ void ArraySpan::SetMembers(const ArrayData& data) { if (type_id == Type::STRING_VIEW || type_id == Type::BINARY_VIEW) { // store the span of data buffers in the third buffer - this->buffers[2] = internal::PackVariadicBuffers(util::span(data.buffers).subspan(2)); + this->buffers[2] = internal::PackVariadicBuffers(std::span(data.buffers).subspan(2)); } if (type_id == Type::DICTIONARY) { @@ -679,7 +679,7 @@ std::shared_ptr ArraySpan::ToArrayData() const { return result; } -util::span> ArraySpan::GetVariadicBuffers() const { +std::span> ArraySpan::GetVariadicBuffers() const { DCHECK(HasVariadicBuffers()); return {buffers[2].data_as>(), static_cast(buffers[2].size) / sizeof(std::shared_ptr)}; diff --git a/cpp/src/arrow/array/data.h b/cpp/src/arrow/array/data.h index 9617e17b5ae..200d92a54c6 100644 --- a/cpp/src/arrow/array/data.h +++ b/cpp/src/arrow/array/data.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -31,9 +32,7 @@ #include "arrow/type_fwd.h" #include "arrow/util/bit_util.h" #include "arrow/util/macros.h" -#include #include "arrow/util/visibility.h" - namespace arrow { namespace internal { @@ -577,11 +576,11 @@ struct ARROW_EXPORT ArraySpan { /// this array type /// \return A span of the requested length template - util::span GetSpan(int i, int64_t length) const { + std::span GetSpan(int i, int64_t length) const { const int64_t buffer_length = buffers[i].size / static_cast(sizeof(T)); assert(i > 0 && length + offset <= buffer_length); ARROW_UNUSED(buffer_length); - return util::span(buffers[i].data_as() + this->offset, length); + return std::span(buffers[i].data_as() + this->offset, length); } /// \brief Access a buffer's data as a span @@ -593,11 +592,11 @@ struct ARROW_EXPORT ArraySpan { /// this array type /// \return A span of the requested length template - util::span GetSpan(int i, int64_t length) { + std::span GetSpan(int i, int64_t length) { const int64_t buffer_length = buffers[i].size / static_cast(sizeof(T)); assert(i > 0 && length + offset <= buffer_length); ARROW_UNUSED(buffer_length); - return util::span(buffers[i].mutable_data_as() + this->offset, length); + return std::span(buffers[i].mutable_data_as() + this->offset, length); } inline bool IsNull(int64_t i) const { return !IsValid(i); } @@ -709,7 +708,7 @@ struct ARROW_EXPORT ArraySpan { /// sizeof(shared_ptr). /// /// \see HasVariadicBuffers - util::span> GetVariadicBuffers() const; + std::span> GetVariadicBuffers() const; bool HasVariadicBuffers() const; private: diff --git a/cpp/src/arrow/array/util.cc b/cpp/src/arrow/array/util.cc index bc62033abcc..6e95198e88f 100644 --- a/cpp/src/arrow/array/util.cc +++ b/cpp/src/arrow/array/util.cc @@ -15,18 +15,18 @@ // specific language governing permissions and limitations // under the License. -#include "arrow/array/util.h" - #include #include #include #include #include #include +#include #include #include #include +#include "arrow/array/util.h" #include "arrow/array.h" #include "arrow/array/builder_base.h" #include "arrow/array/concatenate.h" @@ -44,10 +44,8 @@ #include "arrow/util/endian.h" #include "arrow/util/logging_internal.h" #include "arrow/util/sort_internal.h" -#include #include "arrow/visit_data_inline.h" #include "arrow/visit_type_inline.h" - namespace arrow { using internal::checked_cast; diff --git a/cpp/src/arrow/array/validate.cc b/cpp/src/arrow/array/validate.cc index bd0d00126d5..fe203539548 100644 --- a/cpp/src/arrow/array/validate.cc +++ b/cpp/src/arrow/array/validate.cc @@ -650,9 +650,9 @@ struct ValidateArrayImpl { HexEncode(data, BinaryViewType::kPrefixSize)); }; - util::span views(data.GetValues(1), + std::span views(data.GetValues(1), static_cast(data.length)); - util::span data_buffers(data.buffers.data() + 2, data.buffers.size() - 2); + std::span data_buffers(data.buffers.data() + 2, data.buffers.size() - 2); for (size_t i = 0; i < static_cast(data.length); ++i) { if (data.IsNull(i)) continue; @@ -663,7 +663,7 @@ struct ValidateArrayImpl { } if (views[i].is_inline()) { - auto padding_bytes = util::span(views[i].inlined.data).subspan(views[i].size()); + auto padding_bytes = std::span(views[i].inlined.data).subspan(views[i].size()); for (auto padding_byte : padding_bytes) { if (padding_byte != 0) { return Status::Invalid("View at slot ", i, " was inline with size ", diff --git a/cpp/src/arrow/buffer.h b/cpp/src/arrow/buffer.h index 69ab4512217..a2c84120827 100644 --- a/cpp/src/arrow/buffer.h +++ b/cpp/src/arrow/buffer.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "arrow/status.h" #include "arrow/type_fwd.h" #include "arrow/util/macros.h" -#include #include "arrow/util/visibility.h" namespace arrow { @@ -236,8 +236,8 @@ class ARROW_EXPORT Buffer { /// \brief Return the buffer's data as a span template - util::span span_as() const { - return util::span(data_as(), static_cast(size() / sizeof(T))); + std::span span_as() const { + return std::span(data_as(), static_cast(size() / sizeof(T))); } /// \brief Return a writable pointer to the buffer's data @@ -269,8 +269,8 @@ class ARROW_EXPORT Buffer { /// \brief Return the buffer's mutable data as a span template - util::span mutable_span_as() { - return util::span(mutable_data_as(), static_cast(size() / sizeof(T))); + std::span mutable_span_as() { + return std::span(mutable_data_as(), static_cast(size() / sizeof(T))); } /// \brief Return the device address of the buffer's data diff --git a/cpp/src/arrow/c/bridge.cc b/cpp/src/arrow/c/bridge.cc index dd25ed299dd..eef4ce0862e 100644 --- a/cpp/src/arrow/c/bridge.cc +++ b/cpp/src/arrow/c/bridge.cc @@ -603,7 +603,7 @@ struct ArrayExporter { }); if (need_variadic_buffer_sizes) { - auto variadic_buffers = util::span(data->buffers).subspan(2); + auto variadic_buffers = std::span(data->buffers).subspan(2); export_.variadic_buffer_sizes_.resize(variadic_buffers.size()); size_t i = 0; for (const auto& buf : variadic_buffers) { diff --git a/cpp/src/arrow/c/bridge_test.cc b/cpp/src/arrow/c/bridge_test.cc index c6a5e01e038..d56f1555d5d 100644 --- a/cpp/src/arrow/c/bridge_test.cc +++ b/cpp/src/arrow/c/bridge_test.cc @@ -592,8 +592,8 @@ struct ArrayExportChecker { ASSERT_EQ(c_export->buffers[i], expected_ptr); } if (has_variadic_buffer_sizes) { - auto variadic_buffers = util::span(expected_data.buffers).subspan(2); - auto variadic_buffer_sizes = util::span( + auto variadic_buffers = std::span(expected_data.buffers).subspan(2); + auto variadic_buffer_sizes = std::span( static_cast(c_export->buffers[c_export->n_buffers - 1]), variadic_buffers.size()); for (auto [buf, size] : Zip(variadic_buffers, variadic_buffer_sizes)) { diff --git a/cpp/src/arrow/chunk_resolver.cc b/cpp/src/arrow/chunk_resolver.cc index 7fc259f38c2..0886809daf8 100644 --- a/cpp/src/arrow/chunk_resolver.cc +++ b/cpp/src/arrow/chunk_resolver.cc @@ -28,7 +28,7 @@ namespace arrow { -using util::span; +using std::span; namespace { template diff --git a/cpp/src/arrow/chunk_resolver.h b/cpp/src/arrow/chunk_resolver.h index b76713b6652..fbf84876e3d 100644 --- a/cpp/src/arrow/chunk_resolver.h +++ b/cpp/src/arrow/chunk_resolver.h @@ -21,12 +21,12 @@ #include #include #include +#include #include #include #include "arrow/type_fwd.h" #include "arrow/util/macros.h" -#include namespace arrow { @@ -77,7 +77,7 @@ class ARROW_EXPORT ChunkResolver { public: explicit ChunkResolver(const ArrayVector& chunks) noexcept; - explicit ChunkResolver(util::span chunks) noexcept; + explicit ChunkResolver(std::span chunks) noexcept; explicit ChunkResolver(const RecordBatchVector& batches) noexcept; /// \brief Construct a ChunkResolver from a vector of chunks.size() + 1 offsets. diff --git a/cpp/src/arrow/compute/kernels/chunked_internal.cc b/cpp/src/arrow/compute/kernels/chunked_internal.cc index bf574fcafd0..b62dc1436c2 100644 --- a/cpp/src/arrow/compute/kernels/chunked_internal.cc +++ b/cpp/src/arrow/compute/kernels/chunked_internal.cc @@ -32,7 +32,7 @@ std::vector GetArrayPointers(const ArrayVector& arrays) { } std::vector ChunkedIndexMapper::GetChunkLengths( - util::span chunks) { + std::span chunks) { std::vector chunk_lengths(chunks.size()); for (int64_t i = 0; i < static_cast(chunks.size()); ++i) { chunk_lengths[i] = chunks[i]->length(); diff --git a/cpp/src/arrow/compute/kernels/chunked_internal.h b/cpp/src/arrow/compute/kernels/chunked_internal.h index 624238b2005..1c3105f6915 100644 --- a/cpp/src/arrow/compute/kernels/chunked_internal.h +++ b/cpp/src/arrow/compute/kernels/chunked_internal.h @@ -20,15 +20,14 @@ #include #include #include +#include #include #include #include "arrow/array.h" #include "arrow/chunk_resolver.h" #include "arrow/compute/kernels/codegen_internal.h" -#include #include "arrow/util/visibility.h" - namespace arrow::compute::internal { // The target chunk in a chunked array. @@ -92,13 +91,13 @@ static_assert(sizeof(uint64_t) == sizeof(CompressedChunkLocation)); class ChunkedArrayResolver { private: ChunkResolver resolver_; - util::span chunks_; + std::span chunks_; std::vector owned_chunks_; public: explicit ChunkedArrayResolver(std::vector&& chunks) : resolver_(chunks), chunks_(chunks), owned_chunks_(std::move(chunks)) {} - explicit ChunkedArrayResolver(util::span chunks) + explicit ChunkedArrayResolver(std::span chunks) : resolver_(chunks), chunks_(chunks) {} ARROW_DEFAULT_MOVE_AND_ASSIGN(ChunkedArrayResolver); @@ -129,8 +128,8 @@ class ARROW_EXPORT ChunkedIndexMapper { public: ChunkedIndexMapper(const std::vector& chunks, uint64_t* indices_begin, uint64_t* indices_end) - : ChunkedIndexMapper(util::span(chunks), indices_begin, indices_end) {} - ChunkedIndexMapper(util::span chunks, uint64_t* indices_begin, + : ChunkedIndexMapper(std::span(chunks), indices_begin, indices_end) {} + ChunkedIndexMapper(std::span chunks, uint64_t* indices_begin, uint64_t* indices_end) : chunk_lengths_(GetChunkLengths(chunks)), indices_begin_(indices_begin), @@ -154,7 +153,7 @@ class ARROW_EXPORT ChunkedIndexMapper { Status PhysicalToLogical(); private: - static std::vector GetChunkLengths(util::span chunks); + static std::vector GetChunkLengths(std::span chunks); static std::vector GetChunkLengths(const RecordBatchVector& chunks); std::vector chunk_lengths_; diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate.cc b/cpp/src/arrow/compute/kernels/hash_aggregate.cc index e203685c679..26460820b87 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include #include -#include #include "arrow/array/builder_nested.h" #include "arrow/array/builder_primitive.h" @@ -45,9 +45,7 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/int_util_overflow.h" #include "arrow/util/ree_util.h" -#include #include "arrow/visit_type_inline.h" - namespace arrow::compute::internal { using ::arrow::internal::checked_cast; diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc b/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc index 73319a23e99..652684dd48c 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate_numeric.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -32,10 +33,8 @@ #include "arrow/compute/row/grouper.h" #include "arrow/util/checked_cast.h" #include "arrow/util/int128_internal.h" -#include #include "arrow/util/tdigest_internal.h" #include "arrow/visit_type_inline.h" - namespace arrow::compute::internal { namespace { diff --git a/cpp/src/arrow/compute/kernels/vector_sort.cc b/cpp/src/arrow/compute/kernels/vector_sort.cc index 41cb0a357a4..25cf587aa6c 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort.cc @@ -26,7 +26,7 @@ namespace arrow { using internal::checked_cast; -using util::span; +using std::span; namespace compute { namespace internal { diff --git a/cpp/src/arrow/compute/kernels/vector_sort_internal.h b/cpp/src/arrow/compute/kernels/vector_sort_internal.h index 49704ff8069..8744a0a9182 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_internal.h +++ b/cpp/src/arrow/compute/kernels/vector_sort_internal.h @@ -272,7 +272,7 @@ NullPartitionResult PartitionNullsOnly(uint64_t* indices_begin, uint64_t* indice template ChunkedNullPartitionResult PartitionNullsOnly(CompressedChunkLocation* locations_begin, CompressedChunkLocation* locations_end, - util::span chunks, + std::span chunks, int64_t null_count, NullPlacement null_placement) { if (null_count == 0) { diff --git a/cpp/src/arrow/integration/json_internal.cc b/cpp/src/arrow/integration/json_internal.cc index 0c0c2b6a7f0..d0b8a5a55b8 100644 --- a/cpp/src/arrow/integration/json_internal.cc +++ b/cpp/src/arrow/integration/json_internal.cc @@ -15,18 +15,18 @@ // specific language governing permissions and limitations // under the License. -#include "arrow/integration/json_internal.h" - #include #include #include #include #include +#include #include #include #include #include +#include "arrow/integration/json_internal.h" #include "arrow/array.h" #include "arrow/array/builder_binary.h" #include "arrow/array/builder_decimal.h" @@ -48,12 +48,10 @@ #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging_internal.h" #include "arrow/util/range.h" -#include #include "arrow/util/string.h" #include "arrow/util/value_parsing.h" #include "arrow/visit_array_inline.h" #include "arrow/visit_type_inline.h" - using arrow::internal::checked_cast; using arrow::internal::Enumerate; using arrow::internal::ParseValue; @@ -1461,7 +1459,7 @@ class ArrayReader { GetMemberArray(obj_, "VARIADIC_DATA_BUFFERS")); using internal::Zip; - using util::span; + using std::span; BufferVector buffers; buffers.resize(json_variadic_bufs.Size() + 2); diff --git a/cpp/src/arrow/util/binary_view_util.h b/cpp/src/arrow/util/binary_view_util.h index 7891dac2d60..edd585d8a4b 100644 --- a/cpp/src/arrow/util/binary_view_util.h +++ b/cpp/src/arrow/util/binary_view_util.h @@ -17,11 +17,11 @@ #pragma once +#include #include #include #include "arrow/type.h" -#include namespace arrow::util { diff --git a/cpp/src/arrow/util/bitmap.h b/cpp/src/arrow/util/bitmap.h index d799954b2d8..af5c6ecb5a7 100644 --- a/cpp/src/arrow/util/bitmap.h +++ b/cpp/src/arrow/util/bitmap.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -36,10 +37,8 @@ #include "arrow/util/compare.h" #include "arrow/util/endian.h" #include "arrow/util/functional.h" -#include #include "arrow/util/string_util.h" #include "arrow/util/visibility.h" - namespace arrow { class BooleanArray; @@ -155,7 +154,7 @@ class ARROW_EXPORT Bitmap : public util::ToStringOstreamable, Bitmap bitmaps[N]; int64_t offsets[N]; int64_t bit_length = BitLength(bitmaps_arg, N); - util::span words[N]; + std::span words[N]; for (size_t i = 0; i < N; ++i) { bitmaps[i] = bitmaps_arg[i]; offsets[i] = bitmaps[i].template word_offset(); @@ -384,7 +383,7 @@ class ARROW_EXPORT Bitmap : public util::ToStringOstreamable, int64_t length() const { return length_; } /// span of all bytes which contain any bit in this Bitmap - util::span bytes() const { + std::span bytes() const { auto byte_offset = offset_ / 8; auto byte_count = bit_util::CeilDiv(offset_ + length_, 8) - byte_offset; return {data_ + byte_offset, static_cast(byte_count)}; @@ -404,7 +403,7 @@ class ARROW_EXPORT Bitmap : public util::ToStringOstreamable, /// \warning The words may contain bytes which lie outside the buffer or are /// uninitialized. template - util::span words() const { + std::span words() const { auto bytes_addr = reinterpret_cast(bytes().data()); auto words_addr = bytes_addr - bytes_addr % sizeof(Word); auto word_byte_count = diff --git a/cpp/src/arrow/util/bitmap_builders.cc b/cpp/src/arrow/util/bitmap_builders.cc index 000dda718d0..0014384d5ce 100644 --- a/cpp/src/arrow/util/bitmap_builders.cc +++ b/cpp/src/arrow/util/bitmap_builders.cc @@ -33,7 +33,7 @@ namespace internal { namespace { -void FillBitsFromBytes(util::span bytes, uint8_t* bits) { +void FillBitsFromBytes(std::span bytes, uint8_t* bits) { for (size_t i = 0; i < bytes.size(); ++i) { if (bytes[i] > 0) { bit_util::SetBit(bits, i); @@ -43,7 +43,7 @@ void FillBitsFromBytes(util::span bytes, uint8_t* bits) { } // namespace -Result> BytesToBits(util::span bytes, +Result> BytesToBits(std::span bytes, MemoryPool* pool) { int64_t bit_length = bit_util::BytesForBits(bytes.size()); diff --git a/cpp/src/arrow/util/bitmap_builders.h b/cpp/src/arrow/util/bitmap_builders.h index 1bb90866af2..b9f98f679d0 100644 --- a/cpp/src/arrow/util/bitmap_builders.h +++ b/cpp/src/arrow/util/bitmap_builders.h @@ -19,13 +19,12 @@ #include #include +#include #include #include "arrow/result.h" #include "arrow/type_fwd.h" -#include #include "arrow/util/visibility.h" - namespace arrow { namespace internal { @@ -37,7 +36,7 @@ Result> BitmapAllButOne(MemoryPool* pool, int64_t length /// \brief Convert vector of bytes to bitmap buffer ARROW_EXPORT -Result> BytesToBits(util::span bytes, +Result> BytesToBits(std::span bytes, MemoryPool* pool = default_memory_pool()); } // namespace internal diff --git a/cpp/src/arrow/util/float16_test.cc b/cpp/src/arrow/util/float16_test.cc index f0dc2a0f7cc..832bb61a585 100644 --- a/cpp/src/arrow/util/float16_test.cc +++ b/cpp/src/arrow/util/float16_test.cc @@ -17,16 +17,14 @@ #include #include -#include - #include +#include +#include #include "arrow/testing/gtest_util.h" #include "arrow/util/endian.h" #include "arrow/util/float16.h" -#include #include "arrow/util/ubsan.h" - namespace arrow::util { namespace { diff --git a/cpp/src/arrow/util/rle_encoding_test.cc b/cpp/src/arrow/util/rle_encoding_test.cc index 2314c1bab00..c6d041bc047 100644 --- a/cpp/src/arrow/util/rle_encoding_test.cc +++ b/cpp/src/arrow/util/rle_encoding_test.cc @@ -19,11 +19,11 @@ #include #include +#include #include +#include #include -#include - #include "arrow/array.h" #include "arrow/array/concatenate.h" #include "arrow/array/util.h" @@ -35,8 +35,6 @@ #include "arrow/util/bit_util.h" #include "arrow/util/io_util.h" #include "arrow/util/rle_encoding_internal.h" -#include - namespace arrow::util { const int MAX_WIDTH = 32; diff --git a/cpp/src/arrow/util/secure_string.cc b/cpp/src/arrow/util/secure_string.cc index a45ecce929c..1de7c2d99d6 100644 --- a/cpp/src/arrow/util/secure_string.cc +++ b/cpp/src/arrow/util/secure_string.cc @@ -18,23 +18,13 @@ // __STDC_WANT_LIB_EXT1__ and string.h are required by memset_s: // https://en.cppreference.com/w/c/string/byte/memset #define __STDC_WANT_LIB_EXT1__ 1 +#include #include #include -#if defined(ARROW_USE_OPENSSL) -# include -# include -#endif - #include "arrow/util/windows_compatibility.h" -#if defined(_WIN32) -# include -#endif - #include "arrow/util/logging.h" #include "arrow/util/secure_string.h" -#include - namespace arrow::util { /// Note: diff --git a/cpp/src/arrow/util/span_test.cc b/cpp/src/arrow/util/span_test.cc index 68320d06004..92ffffd8ae0 100644 --- a/cpp/src/arrow/util/span_test.cc +++ b/cpp/src/arrow/util/span_test.cc @@ -16,14 +16,12 @@ // under the License. #include -#include - #include +#include +#include #include "arrow/testing/gtest_util.h" #include "arrow/testing/matchers.h" -#include - using testing::ElementsAre; using testing::ElementsAreArray; using testing::PrintToString; @@ -73,26 +71,26 @@ TEST(Span, TemplateArgumentDeduction) { const int const_arr[] = {1, 2, 3}; std::vector vec; const std::vector const_vec; - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); } TEST(Span, Size) { int arr[] = {1, 2, 3}; - EXPECT_EQ(span(arr).size(), 3); - EXPECT_EQ(span(arr).size_bytes(), sizeof(int) * 3); + EXPECT_EQ(std::span(arr).size(), 3); + EXPECT_EQ(std::span(arr).size_bytes(), sizeof(int) * 3); std::vector vec; - EXPECT_TRUE(span(vec).empty()); - EXPECT_EQ(span(vec).size(), 0); - EXPECT_EQ(span(vec).size_bytes(), 0); + EXPECT_TRUE(std::span(vec).empty()); + EXPECT_EQ(std::span(vec).size(), 0); + EXPECT_EQ(std::span(vec).size_bytes(), 0); vec.resize(999); - EXPECT_FALSE(span(vec).empty()); - EXPECT_EQ(span(vec).size(), 999); - EXPECT_EQ(span(vec).size_bytes(), sizeof(int) * 999); + EXPECT_FALSE(std::span(vec).empty()); + EXPECT_EQ(std::span(vec).size(), 999); + EXPECT_EQ(std::span(vec).size_bytes(), sizeof(int) * 999); } TEST(Span, Equality) { @@ -112,49 +110,49 @@ TEST(Span, Equality) { check_eq(std::span(), std::span()); int arr[] = {1, 2, 3}; - check_eq(span(arr), span(arr)); - check_eq(span(arr).subspan(1), span(arr).subspan(1)); - check_ne(span(arr).subspan(1), span(arr).subspan(2)); + check_eq(std::span(arr), std::span(arr)); + check_eq(std::span(arr).subspan(1), std::span(arr).subspan(1)); + check_ne(std::span(arr).subspan(1), std::span(arr).subspan(2)); std::vector vec{1, 2, 3}; - check_eq(span(vec), span(arr)); - check_eq(span(vec).subspan(1), span(arr).subspan(1)); + check_eq(std::span(vec), std::span(arr)); + check_eq(std::span(vec).subspan(1), std::span(arr).subspan(1)); vec = {2, 3, 4}; - check_ne(span(vec), span(arr)); - check_eq(span(vec).subspan(0, 2), span(arr).subspan(1)); + check_ne(std::span(vec), std::span(arr)); + check_eq(std::span(vec).subspan(0, 2), std::span(arr).subspan(1)); // 0-sized vec = {}; - check_ne(span(vec), span(arr)); - check_eq(span(vec), span(arr).subspan(3)); + check_ne(std::span(vec), std::span(arr)); + check_eq(std::span(vec), std::span(arr).subspan(3)); } { // exercise non-integral branch with for loop check_eq(std::span(), std::span()); std::string arr[] = {"a", "b", "c"}; - check_eq(span(arr), span(arr)); - check_eq(span(arr).subspan(1), span(arr).subspan(1)); + check_eq(std::span(arr), std::span(arr)); + check_eq(std::span(arr).subspan(1), std::span(arr).subspan(1)); std::vector vec{"a", "b", "c"}; - check_eq(span(vec), span(arr)); - check_eq(span(vec).subspan(1), span(arr).subspan(1)); + check_eq(std::span(vec), std::span(arr)); + check_eq(std::span(vec).subspan(1), std::span(arr).subspan(1)); vec = {"b", "c", "d"}; - check_ne(span(vec), span(arr)); - check_eq(span(vec).subspan(0, 2), span(arr).subspan(1)); + check_ne(std::span(vec), std::span(arr)); + check_eq(std::span(vec).subspan(0, 2), std::span(arr).subspan(1)); // 0-sized vec = {}; - check_ne(span(vec), span(arr)); - check_eq(span(vec), span(arr).subspan(3)); + check_ne(std::span(vec), std::span(arr)); + check_eq(std::span(vec), std::span(arr).subspan(3)); } } TEST(Span, SubSpan) { int arr[] = {1, 2, 3}; - span s(arr); + std::span s(arr); auto ExpectIdentical = [](std::span l, std::span r) { EXPECT_EQ(l.data(), r.data()); @@ -165,7 +163,7 @@ TEST(Span, SubSpan) { ExpectIdentical(s.subspan(0, s.size()), s); for (size_t offset = 0; offset < s.size(); ++offset) { - span expected(arr + offset, s.size() - offset); + std::span expected(arr + offset, s.size() - offset); ExpectIdentical(s.subspan(offset), expected); ExpectIdentical(s.subspan(offset, s.size() * 3), expected); } @@ -173,17 +171,17 @@ TEST(Span, SubSpan) { EXPECT_TRUE(s.subspan(s.size() * 3).empty()); for (size_t length = 0; length < s.size(); ++length) { - span expected(arr, length); + std::span expected(arr, length); ExpectIdentical(s.subspan(0, length), expected); } - ExpectIdentical(s.subspan(1, 1), span(arr + 1, 1)); + ExpectIdentical(s.subspan(1, 1), std::span(arr + 1, 1)); } TEST(Span, Mutation) { size_t arr[] = {9, 9, 9, 9, 9}; - span s(arr); + std::span s(arr); for (size_t i = 0; i < s.size(); ++i) { s[i] = i * i; } @@ -195,9 +193,9 @@ TEST(Span, Mutation) { i = rhs; } }; - set(span(arr), 0); - set(span(arr).subspan(1), 1); - set(span(arr).subspan(2, 2), 23); + set(std::span(arr), 0); + set(std::span(arr).subspan(1), 1); + set(std::span(arr).subspan(2, 2), 23); EXPECT_THAT(arr, ElementsAre(0, 1, 23, 23, 1)); } diff --git a/cpp/src/parquet/encoding_test.cc b/cpp/src/parquet/encoding_test.cc index 1149cc7d024..0eab2b635c2 100644 --- a/cpp/src/parquet/encoding_test.cc +++ b/cpp/src/parquet/encoding_test.cc @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -#include - #include #include #include +#include #include +#include #include #include -#include #include "arrow/array.h" #include "arrow/array/builder_binary.h" @@ -40,14 +39,12 @@ #include "arrow/util/bitmap_writer.h" #include "arrow/util/checked_cast.h" #include "arrow/util/endian.h" -#include #include "arrow/util/string.h" #include "parquet/encoding.h" #include "parquet/platform.h" #include "parquet/schema.h" #include "parquet/test_util.h" #include "parquet/types.h" - using arrow::default_memory_pool; using arrow::MemoryPool; using arrow::internal::checked_cast; diff --git a/cpp/src/parquet/encryption/encryption_internal.cc b/cpp/src/parquet/encryption/encryption_internal.cc index 4e90ab95b10..09df3ba5f1b 100644 --- a/cpp/src/parquet/encryption/encryption_internal.cc +++ b/cpp/src/parquet/encryption/encryption_internal.cc @@ -15,25 +15,22 @@ // specific language governing permissions and limitations // under the License. -#include "parquet/encryption/encryption_internal.h" - -#include -#include -#include -#include - #include #include #include #include +#include +#include +#include +#include +#include #include #include #include -#include +#include "parquet/encryption/encryption_internal.h" #include "parquet/encryption/openssl_internal.h" #include "parquet/exception.h" - using std::span; using parquet::ParquetException; diff --git a/cpp/src/parquet/metadata.cc b/cpp/src/parquet/metadata.cc index a8e64ff8312..2afe70ea36a 100644 --- a/cpp/src/parquet/metadata.cc +++ b/cpp/src/parquet/metadata.cc @@ -15,8 +15,6 @@ // specific language governing permissions and limitations // under the License. -#include "parquet/metadata.h" - #include #include #include @@ -29,6 +27,7 @@ #include #include +#include "parquet/metadata.h" #include "arrow/io/memory.h" #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging_internal.h" @@ -41,7 +40,6 @@ #include "parquet/size_statistics.h" #include "parquet/statistics.h" #include "parquet/thrift_internal.h" - using ::arrow::util::SecureString; namespace parquet { diff --git a/cpp/src/parquet/size_statistics_test.cc b/cpp/src/parquet/size_statistics_test.cc index ea88b70694e..463d28a934b 100644 --- a/cpp/src/parquet/size_statistics_test.cc +++ b/cpp/src/parquet/size_statistics_test.cc @@ -15,17 +15,16 @@ // specific language governing permissions and limitations // under the License. -#include "gmock/gmock.h" -#include "gtest/gtest.h" - #include #include #include +#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "arrow/buffer.h" #include "arrow/table.h" #include "arrow/testing/gtest_util.h" -#include #include "parquet/arrow/reader.h" #include "parquet/arrow/schema.h" #include "parquet/arrow/writer.h" @@ -37,7 +36,6 @@ #include "parquet/test_util.h" #include "parquet/thrift_internal.h" #include "parquet/types.h" - namespace parquet { TEST(SizeStatistics, UpdateLevelHistogram) { diff --git a/cpp/src/parquet/stream_writer.h b/cpp/src/parquet/stream_writer.h index fd8192102b9..c4a3ccfe2fa 100644 --- a/cpp/src/parquet/stream_writer.h +++ b/cpp/src/parquet/stream_writer.h @@ -22,12 +22,11 @@ #include #include #include +#include #include #include #include -#include - #include "parquet/column_writer.h" #include "parquet/file_writer.h" diff --git a/cpp/src/parquet/thrift_internal.h b/cpp/src/parquet/thrift_internal.h index 99dc1d6104e..68eb61c9d15 100644 --- a/cpp/src/parquet/thrift_internal.h +++ b/cpp/src/parquet/thrift_internal.h @@ -17,11 +17,8 @@ #pragma once -#include "parquet/windows_compatibility.h" - #include #include - #include #include #include @@ -30,6 +27,7 @@ #include #include +#include "parquet/windows_compatibility.h" // TCompactProtocol requires some #defines to work right. #define SIGNED_RIGHT_SHIFT_IS 1 #define ARITHMETIC_RIGHT_SHIFT 1 From 1bd778b37453e09e75e0d78b793121a1cd2f884a Mon Sep 17 00:00:00 2001 From: Jackie Yan Date: Wed, 24 Dec 2025 09:10:20 +0800 Subject: [PATCH 3/4] refactor: replace arrow::util::span with std::span --- cpp/src/arrow/util/span_test.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cpp/src/arrow/util/span_test.cc b/cpp/src/arrow/util/span_test.cc index 92ffffd8ae0..0bea862a451 100644 --- a/cpp/src/arrow/util/span_test.cc +++ b/cpp/src/arrow/util/span_test.cc @@ -26,8 +26,6 @@ using testing::ElementsAre; using testing::ElementsAreArray; using testing::PrintToString; -namespace arrow_util_span_test { - template std::ostream& operator<<(std::ostream& os, const std::span& span) { // Inefficient but good enough for testing @@ -198,5 +196,3 @@ TEST(Span, Mutation) { set(std::span(arr).subspan(2, 2), 23); EXPECT_THAT(arr, ElementsAre(0, 1, 23, 23, 1)); } - -} // namespace arrow_util_span_test From 459cd5ee97acf722834b9f944261ec634e0d0ed1 Mon Sep 17 00:00:00 2001 From: Jackie Yan Date: Wed, 24 Dec 2025 21:16:00 +0800 Subject: [PATCH 4/4] refactor: remove useless test span_test.cc --- cpp/src/arrow/util/span_test.cc | 198 -------------------------------- 1 file changed, 198 deletions(-) delete mode 100644 cpp/src/arrow/util/span_test.cc diff --git a/cpp/src/arrow/util/span_test.cc b/cpp/src/arrow/util/span_test.cc deleted file mode 100644 index 0bea862a451..00000000000 --- a/cpp/src/arrow/util/span_test.cc +++ /dev/null @@ -1,198 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include -#include -#include -#include - -#include "arrow/testing/gtest_util.h" -#include "arrow/testing/matchers.h" -using testing::ElementsAre; -using testing::ElementsAreArray; -using testing::PrintToString; - -template -std::ostream& operator<<(std::ostream& os, const std::span& span) { - // Inefficient but good enough for testing - os << PrintToString(std::vector(span.begin(), span.end())); - return os; -} - -TEST(Span, Construction) { - // const spans may be constructed from mutable spans - static_assert(std::is_constructible_v, std::span>); - // ... but mutable spans may be constructed from const spans - static_assert(!std::is_constructible_v, std::span>); - - int arr[] = {1, 2, 3}; - constexpr int const_arr[] = {7, 8, 9}; - - static_assert(std::is_constructible_v, decltype(arr)&>); - static_assert(!std::is_constructible_v, decltype(const_arr)&>); - - static_assert(std::is_constructible_v, decltype(arr)&>); - static_assert(std::is_constructible_v, decltype(const_arr)&>); - - static_assert(std::is_constructible_v, std::vector&>); - static_assert(!std::is_constructible_v, const std::vector&>); - static_assert(!std::is_constructible_v, std::vector&&>); - - static_assert(std::is_constructible_v, std::vector&>); - static_assert(std::is_constructible_v, const std::vector&>); - // const spans may even be constructed from rvalue ranges - static_assert(std::is_constructible_v, std::vector&&>); - - EXPECT_THAT(std::span(const_arr), ElementsAreArray(const_arr)); - EXPECT_THAT(std::span(arr), ElementsAreArray(arr)); - - static_assert(!std::is_constructible_v, decltype(const_arr)&>); - static_assert(!std::is_constructible_v, decltype(const_arr)&>); -} - -TEST(Span, TemplateArgumentDeduction) { - int arr[3]; - const int const_arr[] = {1, 2, 3}; - std::vector vec; - const std::vector const_vec; - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); - static_assert(std::is_same_v>); -} - -TEST(Span, Size) { - int arr[] = {1, 2, 3}; - EXPECT_EQ(std::span(arr).size(), 3); - EXPECT_EQ(std::span(arr).size_bytes(), sizeof(int) * 3); - - std::vector vec; - EXPECT_TRUE(std::span(vec).empty()); - EXPECT_EQ(std::span(vec).size(), 0); - EXPECT_EQ(std::span(vec).size_bytes(), 0); - - vec.resize(999); - EXPECT_FALSE(std::span(vec).empty()); - EXPECT_EQ(std::span(vec).size(), 999); - EXPECT_EQ(std::span(vec).size_bytes(), sizeof(int) * 999); -} - -TEST(Span, Equality) { - auto check_eq = [](auto l, auto r) { - ARROW_SCOPED_TRACE("l = ", l, ", r = ", r); - EXPECT_TRUE(l == r); - EXPECT_FALSE(l != r); - }; - auto check_ne = [](auto l, auto r) { - ARROW_SCOPED_TRACE("l = ", l, ", r = ", r); - EXPECT_TRUE(l != r); - EXPECT_FALSE(l == r); - }; - - { - // exercise integral branch with memcmp - check_eq(std::span(), std::span()); - - int arr[] = {1, 2, 3}; - check_eq(std::span(arr), std::span(arr)); - check_eq(std::span(arr).subspan(1), std::span(arr).subspan(1)); - check_ne(std::span(arr).subspan(1), std::span(arr).subspan(2)); - - std::vector vec{1, 2, 3}; - check_eq(std::span(vec), std::span(arr)); - check_eq(std::span(vec).subspan(1), std::span(arr).subspan(1)); - - vec = {2, 3, 4}; - check_ne(std::span(vec), std::span(arr)); - check_eq(std::span(vec).subspan(0, 2), std::span(arr).subspan(1)); - - // 0-sized - vec = {}; - check_ne(std::span(vec), std::span(arr)); - check_eq(std::span(vec), std::span(arr).subspan(3)); - } - { - // exercise non-integral branch with for loop - check_eq(std::span(), std::span()); - - std::string arr[] = {"a", "b", "c"}; - check_eq(std::span(arr), std::span(arr)); - check_eq(std::span(arr).subspan(1), std::span(arr).subspan(1)); - - std::vector vec{"a", "b", "c"}; - check_eq(std::span(vec), std::span(arr)); - check_eq(std::span(vec).subspan(1), std::span(arr).subspan(1)); - - vec = {"b", "c", "d"}; - check_ne(std::span(vec), std::span(arr)); - check_eq(std::span(vec).subspan(0, 2), std::span(arr).subspan(1)); - - // 0-sized - vec = {}; - check_ne(std::span(vec), std::span(arr)); - check_eq(std::span(vec), std::span(arr).subspan(3)); - } -} - -TEST(Span, SubSpan) { - int arr[] = {1, 2, 3}; - std::span s(arr); - - auto ExpectIdentical = [](std::span l, std::span r) { - EXPECT_EQ(l.data(), r.data()); - EXPECT_EQ(l.size(), r.size()); - }; - - ExpectIdentical(s.subspan(0), s); - ExpectIdentical(s.subspan(0, s.size()), s); - - for (size_t offset = 0; offset < s.size(); ++offset) { - std::span expected(arr + offset, s.size() - offset); - ExpectIdentical(s.subspan(offset), expected); - ExpectIdentical(s.subspan(offset, s.size() * 3), expected); - } - EXPECT_TRUE(s.subspan(s.size()).empty()); - EXPECT_TRUE(s.subspan(s.size() * 3).empty()); - - for (size_t length = 0; length < s.size(); ++length) { - std::span expected(arr, length); - ExpectIdentical(s.subspan(0, length), expected); - } - - ExpectIdentical(s.subspan(1, 1), std::span(arr + 1, 1)); -} - -TEST(Span, Mutation) { - size_t arr[] = {9, 9, 9, 9, 9}; - - std::span s(arr); - for (size_t i = 0; i < s.size(); ++i) { - s[i] = i * i; - } - - EXPECT_THAT(arr, ElementsAre(0, 1, 4, 9, 16)); - - auto set = [](std::span lhs, size_t rhs) { - for (size_t& i : lhs) { - i = rhs; - } - }; - set(std::span(arr), 0); - set(std::span(arr).subspan(1), 1); - set(std::span(arr).subspan(2, 2), 23); - EXPECT_THAT(arr, ElementsAre(0, 1, 23, 23, 1)); -}