From 5e49174d69deb9d1cbbdf82bc8041b90098f560b Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 15 Sep 2022 12:37:21 +0200 Subject: [PATCH] ARROW-17694: [C++] Remove std::optional backport (#14105) Just use the C++17 standard library version. Authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- .github/workflows/cpp.yml | 9 +- LICENSE.txt | 28 - c_glib/arrow-glib/compute.cpp | 8 +- ci/scripts/python_wheel_macos_build.sh | 2 +- ci/vcpkg/universal2-osx-static-debug.cmake | 2 +- ci/vcpkg/universal2-osx-static-release.cmake | 2 +- .../arrow/compute_register_example.cc | 2 +- .../execution_plan_documentation_examples.cc | 32 +- cpp/examples/arrow/join_example.cc | 2 +- cpp/examples/minimal_build/run_static.sh | 2 +- cpp/gdb_arrow.py | 24 - cpp/src/arrow/array/array_binary.h | 4 +- cpp/src/arrow/array/array_primitive.h | 8 +- cpp/src/arrow/array/array_test.cc | 4 +- .../arrow/compute/exec/asof_join_benchmark.cc | 2 +- cpp/src/arrow/compute/exec/asof_join_node.cc | 26 +- .../arrow/compute/exec/asof_join_node_test.cc | 4 +- cpp/src/arrow/compute/exec/benchmark_util.cc | 4 +- cpp/src/arrow/compute/exec/exec_plan.cc | 18 +- cpp/src/arrow/compute/exec/exec_plan.h | 6 +- cpp/src/arrow/compute/exec/expression.cc | 52 +- cpp/src/arrow/compute/exec/expression_test.cc | 6 +- .../arrow/compute/exec/hash_join_node_test.cc | 18 +- cpp/src/arrow/compute/exec/options.h | 16 +- cpp/src/arrow/compute/exec/plan_test.cc | 72 +- cpp/src/arrow/compute/exec/sink_node.cc | 14 +- cpp/src/arrow/compute/exec/source_node.cc | 14 +- cpp/src/arrow/compute/exec/subtree_internal.h | 6 +- cpp/src/arrow/compute/exec/subtree_test.cc | 16 +- cpp/src/arrow/compute/exec/test_util.cc | 6 +- cpp/src/arrow/compute/exec/test_util.h | 10 +- cpp/src/arrow/compute/exec/tpch_benchmark.cc | 4 +- cpp/src/arrow/compute/exec/tpch_node.cc | 26 +- cpp/src/arrow/compute/exec/tpch_node.h | 4 +- cpp/src/arrow/compute/exec/tpch_node_test.cc | 6 +- cpp/src/arrow/compute/exec/union_node_test.cc | 2 +- cpp/src/arrow/compute/exec/util.h | 4 +- .../arrow/compute/kernels/codegen_internal.h | 2 +- .../arrow/compute/kernels/hash_aggregate.cc | 36 +- .../compute/kernels/hash_aggregate_test.cc | 4 +- .../compute/kernels/scalar_cast_string.cc | 2 +- .../arrow/compute/kernels/scalar_compare.cc | 8 +- .../arrow/compute/kernels/scalar_if_else.cc | 4 +- .../compute/kernels/vector_replace_test.cc | 4 +- cpp/src/arrow/compute/kernels/vector_sort.cc | 2 +- cpp/src/arrow/config.cc | 4 +- cpp/src/arrow/config.h | 6 +- cpp/src/arrow/csv/reader.cc | 8 +- cpp/src/arrow/csv/writer_test.cc | 6 +- cpp/src/arrow/dataset/dataset.cc | 12 +- cpp/src/arrow/dataset/dataset.h | 6 +- cpp/src/arrow/dataset/dataset_test.cc | 7 +- cpp/src/arrow/dataset/dataset_writer_test.cc | 16 +- cpp/src/arrow/dataset/file_base.cc | 10 +- cpp/src/arrow/dataset/file_base.h | 8 +- cpp/src/arrow/dataset/file_csv.cc | 6 +- cpp/src/arrow/dataset/file_csv.h | 2 +- cpp/src/arrow/dataset/file_ipc.cc | 6 +- cpp/src/arrow/dataset/file_ipc.h | 2 +- cpp/src/arrow/dataset/file_orc.cc | 6 +- cpp/src/arrow/dataset/file_orc.h | 2 +- cpp/src/arrow/dataset/file_parquet.cc | 24 +- cpp/src/arrow/dataset/file_parquet.h | 12 +- cpp/src/arrow/dataset/file_parquet_test.cc | 14 +- cpp/src/arrow/dataset/file_test.cc | 8 +- cpp/src/arrow/dataset/partition.cc | 12 +- cpp/src/arrow/dataset/partition.h | 8 +- cpp/src/arrow/dataset/scanner.cc | 26 +- cpp/src/arrow/dataset/scanner_benchmark.cc | 2 +- cpp/src/arrow/dataset/scanner_test.cc | 34 +- cpp/src/arrow/dataset/test_util.h | 10 +- .../engine/simple_extension_type_internal.h | 6 +- .../engine/substrait/expression_internal.cc | 6 +- .../arrow/engine/substrait/extension_set.cc | 39 +- .../arrow/engine/substrait/extension_set.h | 20 +- .../arrow/engine/substrait/extension_types.cc | 8 +- .../arrow/engine/substrait/extension_types.h | 6 +- cpp/src/arrow/engine/substrait/serde_test.cc | 4 +- cpp/src/arrow/engine/substrait/util.cc | 6 +- cpp/src/arrow/engine/substrait/util.h | 3 +- cpp/src/arrow/filesystem/gcsfs.h | 4 +- cpp/src/arrow/filesystem/path_util.cc | 6 +- cpp/src/arrow/filesystem/path_util.h | 6 +- cpp/src/arrow/filesystem/s3fs.cc | 8 +- cpp/src/arrow/flight/cookie_internal.cc | 4 +- cpp/src/arrow/flight/cookie_internal.h | 4 +- cpp/src/arrow/flight/flight_internals_test.cc | 26 +- cpp/src/arrow/flight/sql/client_test.cc | 14 +- cpp/src/arrow/flight/sql/server.cc | 2 +- cpp/src/arrow/flight/sql/server.h | 14 +- cpp/src/arrow/flight/sql/server_test.cc | 10 +- cpp/src/arrow/flight/sql/test_app_cli.cc | 14 +- cpp/src/arrow/flight/sql/types.h | 6 +- cpp/src/arrow/flight/transport.cc | 6 +- cpp/src/arrow/flight/transport.h | 8 +- .../flight/transport/grpc/util_internal.cc | 20 +- .../flight/transport/ucx/ucx_internal.cc | 2 +- cpp/src/arrow/memory_pool.cc | 6 +- cpp/src/arrow/public_api_test.cc | 4 +- cpp/src/arrow/stl_iterator.h | 6 +- cpp/src/arrow/stl_iterator_test.cc | 4 +- cpp/src/arrow/stl_test.cc | 15 +- cpp/src/arrow/testing/gtest_util.cc | 6 +- cpp/src/arrow/testing/gtest_util.h | 21 +- cpp/src/arrow/testing/matchers.h | 14 +- cpp/src/arrow/testing/util.cc | 8 +- cpp/src/arrow/testing/util.h | 4 +- cpp/src/arrow/util/async_generator.h | 12 +- cpp/src/arrow/util/async_generator_test.cc | 4 +- cpp/src/arrow/util/async_util.cc | 8 +- cpp/src/arrow/util/async_util.h | 2 +- cpp/src/arrow/util/async_util_test.cc | 4 +- cpp/src/arrow/util/cancel_test.cc | 12 +- cpp/src/arrow/util/cpu_info.cc | 6 +- cpp/src/arrow/util/future.h | 10 +- cpp/src/arrow/util/io_util_test.cc | 2 +- cpp/src/arrow/util/iterator.h | 18 +- cpp/src/arrow/util/optional.h | 35 - cpp/src/arrow/util/reflection_test.cc | 32 +- cpp/src/arrow/util/string.cc | 6 +- cpp/src/arrow/util/string.h | 6 +- cpp/src/arrow/util/task_group.cc | 2 +- cpp/src/arrow/vendored/optional.hpp | 1553 ----------------- cpp/src/gandiva/cache.h | 4 +- cpp/src/gandiva/lru_cache.h | 7 +- cpp/src/gandiva/lru_cache_test.cc | 2 +- cpp/src/parquet/level_conversion.cc | 4 +- cpp/src/parquet/statistics.cc | 12 +- cpp/src/parquet/stream_reader.h | 8 +- cpp/src/parquet/stream_reader_test.cc | 2 +- cpp/src/parquet/stream_writer.h | 8 +- dev/release/verify-release-candidate.sh | 2 +- .../autobrew/apache-arrow.rb | 1 + dev/tasks/tasks.yml | 6 +- docs/source/cpp/datatypes.rst | 6 +- docs/source/cpp/gdb.rst | 3 +- docs/source/cpp/streaming_execution.rst | 6 +- python/CMakeLists.txt | 2 +- python/pyarrow/includes/common.pxd | 9 + python/pyarrow/includes/libarrow.pxd | 7 - python/pyarrow/includes/libarrow_fs.pxd | 2 +- python/pyarrow/src/gdb.cc | 5 - python/pyarrow/src/python_test.cc | 4 +- python/pyarrow/tests/test_gdb.py | 7 - r/configure.win | 7 +- r/src/Makevars.ucrt | 3 + r/src/compute-exec.cpp | 6 +- r/src/config.cpp | 5 +- 148 files changed, 653 insertions(+), 2311 deletions(-) delete mode 100644 cpp/src/arrow/util/optional.h delete mode 100644 cpp/src/arrow/vendored/optional.hpp diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index d4c5c4c89799f..8f4702dacb6b3 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -257,7 +257,7 @@ jobs: - name: Install ccache shell: bash run: | - ci/scripts/install_ccache.sh 4.6.2 /usr + ci/scripts/install_ccache.sh 4.6.3 /usr - name: Setup ccache shell: bash run: | @@ -271,8 +271,11 @@ jobs: uses: actions/cache@v2 with: path: ${{ steps.ccache-info.outputs.cache-dir }} - key: cpp-ccache-windows-${{ hashFiles('cpp/**') }} - restore-keys: cpp-ccache-windows- + key: cpp-ccache-windows-${{ env.CACHE_VERSION }}-${{ hashFiles('cpp/**') }} + restore-keys: cpp-ccache-windows-${{ env.CACHE_VERSION }}- + env: + # We can invalidate the current cache by updating this. + CACHE_VERSION: "2022-09-13" - name: Build shell: cmd run: | diff --git a/LICENSE.txt b/LICENSE.txt index a82c22aeceaaa..6532b8790c332 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -2059,34 +2059,6 @@ René Nyffenegger rene.nyffenegger@adp-gmbh.ch -------------------------------------------------------------------------------- -The file cpp/src/arrow/vendored/optional.hpp has the following license - -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - --------------------------------------------------------------------------------- - This project includes code from Folly. * cpp/src/arrow/vendored/ProducerConsumerQueue.h diff --git a/c_glib/arrow-glib/compute.cpp b/c_glib/arrow-glib/compute.cpp index f3a29be5e43b7..3404af794ded8 100644 --- a/c_glib/arrow-glib/compute.cpp +++ b/c_glib/arrow-glib/compute.cpp @@ -938,7 +938,7 @@ garrow_source_node_options_new_record_batch_reader( arrow_reader->schema(), [arrow_reader]() { using ExecBatch = arrow::compute::ExecBatch; - using ExecBatchOptional = arrow::util::optional; + using ExecBatchOptional = std::optional; auto arrow_record_batch_result = arrow_reader->Next(); if (!arrow_record_batch_result.ok()) { return arrow::AsyncGeneratorEnd(); @@ -979,7 +979,7 @@ garrow_source_node_options_new_record_batch(GArrowRecordBatch *record_batch) state->record_batch->schema(), [state]() { using ExecBatch = arrow::compute::ExecBatch; - using ExecBatchOptional = arrow::util::optional; + using ExecBatchOptional = std::optional; if (!state->generated) { state->generated = true; return arrow::Future::MakeFinished( @@ -1296,7 +1296,7 @@ garrow_aggregate_node_options_new(GList *aggregations, typedef struct GArrowSinkNodeOptionsPrivate_ { - arrow::AsyncGenerator> generator; + arrow::AsyncGenerator> generator; GArrowRecordBatchReader *reader; } GArrowSinkNodeOptionsPrivate; @@ -1333,7 +1333,7 @@ garrow_sink_node_options_init(GArrowSinkNodeOptions *object) { auto priv = GARROW_SINK_NODE_OPTIONS_GET_PRIVATE(object); new(&(priv->generator)) - arrow::AsyncGenerator>(); + arrow::AsyncGenerator>(); } static void diff --git a/ci/scripts/python_wheel_macos_build.sh b/ci/scripts/python_wheel_macos_build.sh index 92494fb4b7632..cdd2bd3a400fa 100755 --- a/ci/scripts/python_wheel_macos_build.sh +++ b/ci/scripts/python_wheel_macos_build.sh @@ -34,7 +34,7 @@ rm -rf ${source_dir}/python/pyarrow/*.so.* echo "=== (${PYTHON_VERSION}) Set SDK, C++ and Wheel flags ===" export _PYTHON_HOST_PLATFORM="macosx-${MACOSX_DEPLOYMENT_TARGET}-${arch}" -export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-10.13} +export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-10.14} export SDKROOT=${SDKROOT:-$(xcrun --sdk macosx --show-sdk-path)} if [ $arch = "arm64" ]; then diff --git a/ci/vcpkg/universal2-osx-static-debug.cmake b/ci/vcpkg/universal2-osx-static-debug.cmake index 29e4b0e63c565..580b4604d522f 100644 --- a/ci/vcpkg/universal2-osx-static-debug.cmake +++ b/ci/vcpkg/universal2-osx-static-debug.cmake @@ -21,6 +21,6 @@ set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Darwin) set(VCPKG_OSX_ARCHITECTURES "x86_64;arm64") -set(VCPKG_OSX_DEPLOYMENT_TARGET "10.13") +set(VCPKG_OSX_DEPLOYMENT_TARGET "10.14") set(VCPKG_BUILD_TYPE debug) diff --git a/ci/vcpkg/universal2-osx-static-release.cmake b/ci/vcpkg/universal2-osx-static-release.cmake index 8111169fab269..7247d0af351c5 100644 --- a/ci/vcpkg/universal2-osx-static-release.cmake +++ b/ci/vcpkg/universal2-osx-static-release.cmake @@ -21,6 +21,6 @@ set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Darwin) set(VCPKG_OSX_ARCHITECTURES "x86_64;arm64") -set(VCPKG_OSX_DEPLOYMENT_TARGET "10.13") +set(VCPKG_OSX_DEPLOYMENT_TARGET "10.14") set(VCPKG_BUILD_TYPE release) diff --git a/cpp/examples/arrow/compute_register_example.cc b/cpp/examples/arrow/compute_register_example.cc index 2a76e8595b69b..d8debd9c3e11a 100644 --- a/cpp/examples/arrow/compute_register_example.cc +++ b/cpp/examples/arrow/compute_register_example.cc @@ -149,7 +149,7 @@ arrow::Status RunComputeRegister(int argc, char** argv) { ARROW_RETURN_NOT_OK(maybe_plan.status()); ARROW_ASSIGN_OR_RAISE(auto plan, maybe_plan); - arrow::AsyncGenerator> source_gen, sink_gen; + arrow::AsyncGenerator> source_gen, sink_gen; ARROW_RETURN_NOT_OK( cp::Declaration::Sequence( { diff --git a/cpp/examples/arrow/execution_plan_documentation_examples.cc b/cpp/examples/arrow/execution_plan_documentation_examples.cc index b7c690bb278e1..9a2d682bbae23 100644 --- a/cpp/examples/arrow/execution_plan_documentation_examples.cc +++ b/cpp/examples/arrow/execution_plan_documentation_examples.cc @@ -157,11 +157,11 @@ struct BatchesWithSchema { std::shared_ptr schema; // This method uses internal arrow utilities to // convert a vector of record batches to an AsyncGenerator of optional batches - arrow::AsyncGenerator> gen() const { + arrow::AsyncGenerator> gen() const { auto opt_batches = ::arrow::internal::MapVector( - [](cp::ExecBatch batch) { return arrow::util::make_optional(std::move(batch)); }, + [](cp::ExecBatch batch) { return std::make_optional(std::move(batch)); }, batches); - arrow::AsyncGenerator> gen; + arrow::AsyncGenerator> gen; gen = arrow::MakeVectorGenerator(std::move(opt_batches)); return gen; } @@ -259,7 +259,7 @@ arrow::Result MakeGroupableBatches(int multiplicity = 1) { arrow::Status ExecutePlanAndCollectAsTable( cp::ExecContext& exec_context, std::shared_ptr plan, std::shared_ptr schema, - arrow::AsyncGenerator> sink_gen) { + arrow::AsyncGenerator> sink_gen) { // translate sink_gen (async) to sink_reader (sync) std::shared_ptr sink_reader = cp::MakeGeneratorReader(schema, std::move(sink_gen), exec_context.memory_pool()); @@ -312,7 +312,7 @@ arrow::Status ScanSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(scan, cp::MakeExecNode("scan", plan.get(), {}, scan_node_options)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; ARROW_RETURN_NOT_OK( cp::MakeExecNode("sink", plan.get(), {scan}, cp::SinkNodeOptions{&sink_gen})); @@ -337,7 +337,7 @@ arrow::Status SourceSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(auto basic_data, MakeBasicBatches()); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()}; @@ -367,7 +367,7 @@ arrow::Status TableSourceSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(auto table, GetTable()); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; int max_batch_size = 2; auto table_source_options = cp::TableSourceNodeOptions{table, max_batch_size}; @@ -427,7 +427,7 @@ arrow::Status ScanFilterSinkExample(cp::ExecContext& exec_context) { cp::FilterNodeOptions{filter_opt})); // finally, pipe the filter node into a sink node - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; ARROW_RETURN_NOT_OK( cp::MakeExecNode("sink", plan.get(), {filter}, cp::SinkNodeOptions{&sink_gen})); @@ -470,7 +470,7 @@ arrow::Status ScanProjectSinkExample(cp::ExecContext& exec_context) { std::cout << "Schema after projection : \n" << project->output_schema()->ToString() << std::endl; - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; ARROW_RETURN_NOT_OK( cp::MakeExecNode("sink", plan.get(), {project}, cp::SinkNodeOptions{&sink_gen})); auto schema = arrow::schema({arrow::field("a * 2", arrow::int32())}); @@ -496,7 +496,7 @@ arrow::Status SourceScalarAggregateSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(auto basic_data, MakeBasicBatches()); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()}; @@ -532,7 +532,7 @@ arrow::Status SourceGroupAggregateSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(auto basic_data, MakeBasicBatches()); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()}; @@ -640,7 +640,7 @@ arrow::Status SourceOrderBySinkExample(cp::ExecContext& exec_context) { std::cout << "basic data created" << std::endl; - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()}; ARROW_ASSIGN_OR_RAISE(cp::ExecNode * source, @@ -670,7 +670,7 @@ arrow::Status SourceHashJoinSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, cp::ExecPlan::Make(&exec_context)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; cp::ExecNode* left_source; cp::ExecNode* right_source; @@ -714,7 +714,7 @@ arrow::Status SourceKSelectExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(auto input, MakeGroupableBatches()); ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, cp::ExecPlan::Make(&exec_context)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; ARROW_ASSIGN_OR_RAISE( cp::ExecNode * source, @@ -761,7 +761,7 @@ arrow::Status ScanFilterWriteExample(cp::ExecContext& exec_context, ARROW_ASSIGN_OR_RAISE(scan, cp::MakeExecNode("scan", plan.get(), {}, scan_node_options)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; std::string root_path = ""; std::string uri = "file://" + file_path; @@ -820,7 +820,7 @@ arrow::Status SourceUnionSinkExample(cp::ExecContext& exec_context) { ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, cp::ExecPlan::Make(&exec_context)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; cp::Declaration union_node{"union", cp::ExecNodeOptions{}}; cp::Declaration lhs{"source", diff --git a/cpp/examples/arrow/join_example.cc b/cpp/examples/arrow/join_example.cc index e531bfbfbf962..7bea588e3ad7e 100644 --- a/cpp/examples/arrow/join_example.cc +++ b/cpp/examples/arrow/join_example.cc @@ -89,7 +89,7 @@ arrow::Status DoHashJoin() { ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, cp::ExecPlan::Make(&exec_context)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; cp::ExecNode* left_source; cp::ExecNode* right_source; diff --git a/cpp/examples/minimal_build/run_static.sh b/cpp/examples/minimal_build/run_static.sh index cf2a9912f50f6..619811d09ac33 100755 --- a/cpp/examples/minimal_build/run_static.sh +++ b/cpp/examples/minimal_build/run_static.sh @@ -102,7 +102,7 @@ echo rm -rf $EXAMPLE_BUILD_DIR mkdir -p $EXAMPLE_BUILD_DIR -${CXX:-c++} \ +${CXX:-c++} -std=c++17 \ -o $EXAMPLE_BUILD_DIR/arrow-example \ $EXAMPLE_DIR/example.cc \ $(PKG_CONFIG_PATH=$ARROW_BUILD_DIR/lib/pkgconfig \ diff --git a/cpp/gdb_arrow.py b/cpp/gdb_arrow.py index af3dad9c087ca..5421b4ffb15d8 100644 --- a/cpp/gdb_arrow.py +++ b/cpp/gdb_arrow.py @@ -2175,28 +2175,6 @@ def to_string(self): return f"arrow::util::string_view of size {size}, {data}" -class OptionalPrinter: - """ - Pretty-printer for arrow::util::optional. - """ - - def __init__(self, name, val): - self.val = val - - def to_string(self): - data_type = self.val.type.template_argument(0) - # XXX We rely on internal details of our vendored optional - # implementation, as inlined methods may not be callable from gdb. - if not self.val['has_value_']: - inner = "nullopt" - else: - data_ptr = self.val['contained']['data'].address - assert data_ptr - inner = data_ptr.reinterpret_cast( - data_type.pointer()).dereference() - return f"arrow::util::optional<{data_type}>({inner})" - - class VariantPrinter: """ Pretty-printer for arrow::util::Variant. @@ -2436,10 +2414,8 @@ def to_string(self): "arrow::SimpleTable": TablePrinter, "arrow::Status": StatusPrinter, "arrow::Table": TablePrinter, - "arrow::util::optional": OptionalPrinter, "arrow::util::string_view": StringViewPrinter, "arrow::util::Variant": VariantPrinter, - "nonstd::optional_lite::optional": OptionalPrinter, "nonstd::sv_lite::basic_string_view": StringViewPrinter, } diff --git a/cpp/src/arrow/array/array_binary.h b/cpp/src/arrow/array/array_binary.h index 04ee804987f89..cc04d792002b4 100644 --- a/cpp/src/arrow/array/array_binary.h +++ b/cpp/src/arrow/array/array_binary.h @@ -75,7 +75,7 @@ class BaseBinaryArray : public FlatArray { raw_value_offsets_[i + 1] - pos); } - util::optional operator[](int64_t i) const { + std::optional operator[](int64_t i) const { return *IteratorType(*this, i); } @@ -240,7 +240,7 @@ class ARROW_EXPORT FixedSizeBinaryArray : public PrimitiveArray { return util::string_view(reinterpret_cast(GetValue(i)), byte_width()); } - util::optional operator[](int64_t i) const { + std::optional operator[](int64_t i) const { return *IteratorType(*this, i); } diff --git a/cpp/src/arrow/array/array_primitive.h b/cpp/src/arrow/array/array_primitive.h index 740a4806a4dbc..e6df92e3b788c 100644 --- a/cpp/src/arrow/array/array_primitive.h +++ b/cpp/src/arrow/array/array_primitive.h @@ -54,7 +54,7 @@ class ARROW_EXPORT BooleanArray : public PrimitiveArray { bool GetView(int64_t i) const { return Value(i); } - util::optional operator[](int64_t i) const { return *IteratorType(*this, i); } + std::optional operator[](int64_t i) const { return *IteratorType(*this, i); } /// \brief Return the number of false (0) values among the valid /// values. Result is not cached. @@ -111,7 +111,7 @@ class NumericArray : public PrimitiveArray { // For API compatibility with BinaryArray etc. value_type GetView(int64_t i) const { return Value(i); } - util::optional operator[](int64_t i) const { + std::optional operator[](int64_t i) const { return *IteratorType(*this, i); } @@ -152,7 +152,7 @@ class ARROW_EXPORT DayTimeIntervalArray : public PrimitiveArray { IteratorType end() const { return IteratorType(*this, length()); } - util::optional operator[](int64_t i) const { + std::optional operator[](int64_t i) const { return *IteratorType(*this, i); } @@ -188,7 +188,7 @@ class ARROW_EXPORT MonthDayNanoIntervalArray : public PrimitiveArray { IteratorType end() const { return IteratorType(*this, length()); } - util::optional operator[](int64_t i) const { + std::optional operator[](int64_t i) const { return *IteratorType(*this, i); } diff --git a/cpp/src/arrow/array/array_test.cc b/cpp/src/arrow/array/array_test.cc index d438557a33083..9256d4ad0b7f2 100644 --- a/cpp/src/arrow/array/array_test.cc +++ b/cpp/src/arrow/array/array_test.cc @@ -2290,7 +2290,7 @@ TEST_F(TestFWBinaryArray, ArrayIndexOperator) { auto fsba = checked_pointer_cast(arr); ASSERT_EQ("abc", (*fsba)[0].value()); - ASSERT_EQ(util::nullopt, (*fsba)[1]); + ASSERT_EQ(std::nullopt, (*fsba)[1]); ASSERT_EQ("def", (*fsba)[2].value()); } @@ -3538,7 +3538,7 @@ TYPED_TEST(TestPrimitiveArray, IndexOperator) { ASSERT_EQ(this->values_[i], res.value()); } else { ASSERT_FALSE(res.has_value()); - ASSERT_EQ(res, util::nullopt); + ASSERT_EQ(res, std::nullopt); } } } diff --git a/cpp/src/arrow/compute/exec/asof_join_benchmark.cc b/cpp/src/arrow/compute/exec/asof_join_benchmark.cc index 7d8abc0ba4c14..a0362eb1ba8a9 100644 --- a/cpp/src/arrow/compute/exec/asof_join_benchmark.cc +++ b/cpp/src/arrow/compute/exec/asof_join_benchmark.cc @@ -88,7 +88,7 @@ static void TableJoinOverhead(benchmark::State& state, } ASSERT_OK_AND_ASSIGN(arrow::compute::ExecNode * join_node, MakeExecNode(factory_name, plan.get(), input_nodes, options)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(MakeExecNode("sink", plan.get(), {join_node}, SinkNodeOptions{&sink_gen})); state.ResumeTiming(); ASSERT_FINISHES_OK(StartAndCollect(plan.get(), sink_gen)); diff --git a/cpp/src/arrow/compute/exec/asof_join_node.cc b/cpp/src/arrow/compute/exec/asof_join_node.cc index 869456a577531..35e7b1c6cc6cc 100644 --- a/cpp/src/arrow/compute/exec/asof_join_node.cc +++ b/cpp/src/arrow/compute/exec/asof_join_node.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,6 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/future.h" #include "arrow/util/make_unique.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" namespace arrow { @@ -99,11 +99,11 @@ class ConcurrentQueue { queue_ = std::queue(); } - util::optional TryPop() { + std::optional TryPop() { // Try to pop the oldest value from the queue (or return nullopt if none) std::unique_lock lock(mutex_); if (queue_.empty()) { - return util::nullopt; + return std::nullopt; } else { auto item = queue_.front(); queue_.pop(); @@ -156,10 +156,10 @@ struct MemoStore { e.time = time; } - util::optional GetEntryForKey(ByType key) const { + std::optional GetEntryForKey(ByType key) const { auto e = entries_.find(key); - if (entries_.end() == e) return util::nullopt; - return util::optional(&e->second); + if (entries_.end() == e) return std::nullopt; + return std::optional(&e->second); } void RemoveEntriesWithLesserTime(OnType ts) { @@ -263,7 +263,7 @@ class InputState { return dst_offset; } - const util::optional& MapSrcToDst(col_index_t src) const { + const std::optional& MapSrcToDst(col_index_t src) const { return src_to_dst_[src]; } @@ -436,16 +436,16 @@ class InputState { return Status::OK(); } - util::optional GetMemoEntryForKey(ByType key) { + std::optional GetMemoEntryForKey(ByType key) { return memo_.GetEntryForKey(key); } - util::optional GetMemoTimeForKey(ByType key) { + std::optional GetMemoTimeForKey(ByType key) { auto r = GetMemoEntryForKey(key); if (r.has_value()) { return (*r)->time; } else { - return util::nullopt; + return std::nullopt; } } @@ -492,7 +492,7 @@ class InputState { // Stores latest known values for the various keys MemoStore memo_; // Mapping of source columns to destination columns - std::vector> src_to_dst_; + std::vector> src_to_dst_; }; template @@ -555,7 +555,7 @@ class CompositeReferenceTable { // Get the state for that key from all on the RHS -- assumes it's up to date // (the RHS state comes from the memoized row references) for (size_t i = 1; i < in.size(); ++i) { - util::optional opt_entry = in[i]->GetMemoEntryForKey(key); + std::optional opt_entry = in[i]->GetMemoEntryForKey(key); if (opt_entry.has_value()) { DCHECK(*opt_entry); if ((*opt_entry)->time + tolerance >= lhs_latest_time) { @@ -588,7 +588,7 @@ class CompositeReferenceTable { int n_src_cols = state.at(i_table)->get_schema()->num_fields(); { for (col_index_t i_src_col = 0; i_src_col < n_src_cols; ++i_src_col) { - util::optional i_dst_col_opt = + std::optional i_dst_col_opt = state[i_table]->MapSrcToDst(i_src_col); if (!i_dst_col_opt) continue; col_index_t i_dst_col = *i_dst_col_opt; diff --git a/cpp/src/arrow/compute/exec/asof_join_node_test.cc b/cpp/src/arrow/compute/exec/asof_join_node_test.cc index 48d1ae6410b15..2e4bb06176a00 100644 --- a/cpp/src/arrow/compute/exec/asof_join_node_test.cc +++ b/cpp/src/arrow/compute/exec/asof_join_node_test.cc @@ -222,7 +222,7 @@ void CheckRunOutput(const BatchesWithSchema& l_batches, join.inputs.emplace_back(Declaration{ "source", SourceNodeOptions{r1_batches.schema, r1_batches.gen(false, false)}}); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence({join, {"sink", SinkNodeOptions{&sink_gen}}}) .AddToPlan(plan.get())); @@ -267,7 +267,7 @@ void DoInvalidPlanTest(const BatchesWithSchema& l_batches, "source", SourceNodeOptions{r_batches.schema, r_batches.gen(false, false)}}); if (fail_on_plan_creation) { - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence({join, {"sink", SinkNodeOptions{&sink_gen}}}) .AddToPlan(plan.get())); EXPECT_FINISHES_AND_RAISES_WITH_MESSAGE_THAT(Invalid, diff --git a/cpp/src/arrow/compute/exec/benchmark_util.cc b/cpp/src/arrow/compute/exec/benchmark_util.cc index 5bac508854f7c..d4e14540a54ae 100644 --- a/cpp/src/arrow/compute/exec/benchmark_util.cc +++ b/cpp/src/arrow/compute/exec/benchmark_util.cc @@ -42,7 +42,7 @@ Status BenchmarkIsolatedNodeOverhead(benchmark::State& state, arrow::compute::ExecNodeOptions& options) { for (auto _ : state) { state.PauseTiming(); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, arrow::compute::ExecPlan::Make(&ctx)); @@ -119,7 +119,7 @@ Status BenchmarkNodeOverhead( state.PauseTiming(); ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, arrow::compute::ExecPlan::Make(&ctx)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; arrow::compute::Declaration source = arrow::compute::Declaration( {"source", arrow::compute::SourceNodeOptions{data.schema, diff --git a/cpp/src/arrow/compute/exec/exec_plan.cc b/cpp/src/arrow/compute/exec/exec_plan.cc index 00415495aa8fd..322b5f5e456c6 100644 --- a/cpp/src/arrow/compute/exec/exec_plan.cc +++ b/cpp/src/arrow/compute/exec/exec_plan.cc @@ -17,6 +17,7 @@ #include "arrow/compute/exec/exec_plan.h" +#include #include #include #include @@ -33,7 +34,6 @@ #include "arrow/util/async_generator.h" #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/tracing_internal.h" namespace arrow { @@ -339,12 +339,12 @@ const ExecPlanImpl* ToDerived(const ExecPlan* ptr) { return checked_cast(ptr); } -util::optional GetNodeIndex(const std::vector& nodes, - const ExecNode* node) { +std::optional GetNodeIndex(const std::vector& nodes, + const ExecNode* node) { for (int i = 0; i < static_cast(nodes.size()); ++i) { if (nodes[i] == node) return i; } - return util::nullopt; + return std::nullopt; } } // namespace @@ -569,8 +569,8 @@ void MapNode::Finish(Status finish_st /*= Status::OK()*/) { } std::shared_ptr MakeGeneratorReader( - std::shared_ptr schema, - std::function>()> gen, MemoryPool* pool) { + std::shared_ptr schema, std::function>()> gen, + MemoryPool* pool) { struct Impl : RecordBatchReader { std::shared_ptr schema() const override { return schema_; } @@ -596,7 +596,7 @@ std::shared_ptr MakeGeneratorReader( MemoryPool* pool_; std::shared_ptr schema_; - Iterator> iterator_; + Iterator> iterator_; }; auto out = std::make_shared(); @@ -703,12 +703,12 @@ ExecFactoryRegistry* default_exec_factory_registry() { return &instance; } -Result>()>> MakeReaderGenerator( +Result>()>> MakeReaderGenerator( std::shared_ptr reader, ::arrow::internal::Executor* io_executor, int max_q, int q_restart) { auto batch_it = MakeMapIterator( [](std::shared_ptr batch) { - return util::make_optional(ExecBatch(*batch)); + return std::make_optional(ExecBatch(*batch)); }, MakeIteratorFromReader(reader)); diff --git a/cpp/src/arrow/compute/exec/exec_plan.h b/cpp/src/arrow/compute/exec/exec_plan.h index a9481e21a6e6f..93d0655124114 100644 --- a/cpp/src/arrow/compute/exec/exec_plan.h +++ b/cpp/src/arrow/compute/exec/exec_plan.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -30,7 +31,6 @@ #include "arrow/util/cancel.h" #include "arrow/util/key_value_metadata.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" #include "arrow/util/tracing.h" #include "arrow/util/visibility.h" @@ -530,7 +530,7 @@ struct ARROW_EXPORT Declaration { /// The RecordBatchReader does not impose any ordering on emitted batches. ARROW_EXPORT std::shared_ptr MakeGeneratorReader( - std::shared_ptr, std::function>()>, + std::shared_ptr, std::function>()>, MemoryPool*); constexpr int kDefaultBackgroundMaxQ = 32; @@ -540,7 +540,7 @@ constexpr int kDefaultBackgroundQRestart = 16; /// /// Useful as a source node for an Exec plan ARROW_EXPORT -Result>()>> MakeReaderGenerator( +Result>()>> MakeReaderGenerator( std::shared_ptr reader, arrow::internal::Executor* io_executor, int max_q = kDefaultBackgroundMaxQ, int q_restart = kDefaultBackgroundQRestart); diff --git a/cpp/src/arrow/compute/exec/expression.cc b/cpp/src/arrow/compute/exec/expression.cc index 06f36c7f5adc1..16942a0f80f11 100644 --- a/cpp/src/arrow/compute/exec/expression.cc +++ b/cpp/src/arrow/compute/exec/expression.cc @@ -17,6 +17,7 @@ #include "arrow/compute/exec/expression.h" +#include #include #include @@ -31,7 +32,6 @@ #include "arrow/util/hash_util.h" #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/string.h" #include "arrow/util/value_parsing.h" #include "arrow/util/vector.h" @@ -309,13 +309,12 @@ bool Expression::IsNullLiteral() const { } namespace { -util::optional GetNullHandling( - const Expression::Call& call) { +std::optional GetNullHandling(const Expression::Call& call) { DCHECK_NE(call.function, nullptr); if (call.function->kind() == compute::Function::SCALAR) { return static_cast(call.kernel)->null_handling; } - return util::nullopt; + return std::nullopt; } } // namespace @@ -616,8 +615,8 @@ ArgumentsAndFlippedArguments(const Expression::Call& call) { template ::value_type> -util::optional FoldLeft(It begin, It end, const BinOp& bin_op) { - if (begin == end) return util::nullopt; +std::optional FoldLeft(It begin, It end, const BinOp& bin_op) { + if (begin == end) return std::nullopt; Out folded = std::move(*begin++); while (begin != end) { @@ -738,18 +737,18 @@ std::vector GuaranteeConjunctionMembers( /// Recognizes expressions of the form: /// equal(a, 2) /// is_null(a) -util::optional> ExtractOneFieldValue( +std::optional> ExtractOneFieldValue( const Expression& guarantee) { auto call = guarantee.call(); - if (!call) return util::nullopt; + if (!call) return std::nullopt; // search for an equality conditions between a field and a literal if (call->function_name == "equal") { auto ref = call->arguments[0].field_ref(); - if (!ref) return util::nullopt; + if (!ref) return std::nullopt; auto lit = call->arguments[1].literal(); - if (!lit) return util::nullopt; + if (!lit) return std::nullopt; return std::make_pair(*ref, *lit); } @@ -757,12 +756,12 @@ util::optional> ExtractOneFieldValue( // ... or a known null field if (call->function_name == "is_null") { auto ref = call->arguments[0].field_ref(); - if (!ref) return util::nullopt; + if (!ref) return std::nullopt; return std::make_pair(*ref, Datum(std::make_shared())); } - return util::nullopt; + return std::nullopt; } // Conjunction members which are represented in known_values are erased from @@ -953,24 +952,24 @@ struct Inequality { // possibly disjuncted with an "is_null" Expression. // cmp(a, 2) // cmp(a, 2) or is_null(a) - static util::optional ExtractOne(const Expression& guarantee) { + static std::optional ExtractOne(const Expression& guarantee) { auto call = guarantee.call(); - if (!call) return util::nullopt; + if (!call) return std::nullopt; if (call->function_name == "or_kleene") { // expect the LHS to be a usable field inequality auto out = ExtractOneFromComparison(call->arguments[0]); - if (!out) return util::nullopt; + if (!out) return std::nullopt; // expect the RHS to be an is_null expression auto call_rhs = call->arguments[1].call(); - if (!call_rhs) return util::nullopt; - if (call_rhs->function_name != "is_null") return util::nullopt; + if (!call_rhs) return std::nullopt; + if (call_rhs->function_name != "is_null") return std::nullopt; // ... and that it references the same target auto target = call_rhs->arguments[0].field_ref(); - if (!target) return util::nullopt; - if (*target != out->target) return util::nullopt; + if (!target) return std::nullopt; + if (*target != out->target) return std::nullopt; out->nullable = true; return out; @@ -980,26 +979,25 @@ struct Inequality { return ExtractOneFromComparison(guarantee); } - static util::optional ExtractOneFromComparison( - const Expression& guarantee) { + static std::optional ExtractOneFromComparison(const Expression& guarantee) { auto call = guarantee.call(); - if (!call) return util::nullopt; + if (!call) return std::nullopt; if (auto cmp = Comparison::Get(call->function_name)) { // not_equal comparisons are not very usable as guarantees - if (*cmp == Comparison::NOT_EQUAL) return util::nullopt; + if (*cmp == Comparison::NOT_EQUAL) return std::nullopt; auto target = call->arguments[0].field_ref(); - if (!target) return util::nullopt; + if (!target) return std::nullopt; auto bound = call->arguments[1].literal(); - if (!bound) return util::nullopt; - if (!bound->is_scalar()) return util::nullopt; + if (!bound) return std::nullopt; + if (!bound->is_scalar()) return std::nullopt; return Inequality{*cmp, /*target=*/*target, *bound, /*nullable=*/false}; } - return util::nullopt; + return std::nullopt; } /// The given expression simplifies to `value` if the inequality diff --git a/cpp/src/arrow/compute/exec/expression_test.cc b/cpp/src/arrow/compute/exec/expression_test.cc index b4466d827eb9c..4cb4c272485d2 100644 --- a/cpp/src/arrow/compute/exec/expression_test.cc +++ b/cpp/src/arrow/compute/exec/expression_test.cc @@ -86,7 +86,7 @@ void ExpectResultsEqual(Actual&& actual, Expected&& expected) { } } -const auto no_change = util::nullopt; +const auto no_change = std::nullopt; TEST(ExpressionUtils, Comparison) { auto Expect = [](Result expected, Datum l, Datum r) { @@ -122,7 +122,7 @@ TEST(ExpressionUtils, Comparison) { } TEST(ExpressionUtils, StripOrderPreservingCasts) { - auto Expect = [](Expression expr, util::optional expected_stripped) { + auto Expect = [](Expression expr, std::optional expected_stripped) { ASSERT_OK_AND_ASSIGN(expr, expr.Bind(*kBoringSchema)); if (!expected_stripped) { expected_stripped = expr; @@ -499,7 +499,7 @@ TEST(Expression, BindLiteral) { } } -void ExpectBindsTo(Expression expr, util::optional expected, +void ExpectBindsTo(Expression expr, std::optional expected, Expression* bound_out = nullptr, const Schema& schema = *kBoringSchema) { if (!expected) { 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 3bb778b82ae93..b45af65445083 100644 --- a/cpp/src/arrow/compute/exec/hash_join_node_test.cc +++ b/cpp/src/arrow/compute/exec/hash_join_node_test.cc @@ -85,7 +85,7 @@ void CheckRunOutput(JoinType type, const BatchesWithSchema& l_batches, join.inputs.emplace_back(Declaration{ "source", SourceNodeOptions{r_batches.schema, r_batches.gen(parallel, /*slow=*/false)}}); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence({join, {"sink", SinkNodeOptions{&sink_gen}}}) .AddToPlan(plan.get())); @@ -915,7 +915,7 @@ Result> HashJoinWithExecPlan( ExecNode * join, MakeExecNode("hashjoin", plan.get(), {l_source, r_source}, join_options)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ARROW_ASSIGN_OR_RAISE( std::ignore, MakeExecNode("sink", plan.get(), {join}, SinkNodeOptions{&sink_gen})); @@ -964,7 +964,7 @@ TEST(HashJoin, Suffix) { ExecContext exec_ctx; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(&exec_ctx)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ExecNode* left_source; ExecNode* right_source; @@ -1335,7 +1335,7 @@ void TestHashJoinDictionaryHelper( {(swap_sides ? r_source : l_source), (swap_sides ? l_source : r_source)}, join_options)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN( std::ignore, MakeExecNode("sink", plan.get(), {join}, SinkNodeOptions{&sink_gen})); ASSERT_FINISHES_OK_AND_ASSIGN(auto res, StartAndCollect(plan.get(), sink_gen)); @@ -1756,7 +1756,7 @@ TEST(HashJoin, DictNegative) { ASSERT_OK_AND_ASSIGN( ExecNode * join, MakeExecNode("hashjoin", plan.get(), {l_source, r_source}, join_options)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(std::ignore, MakeExecNode("sink", plan.get(), {join}, SinkNodeOptions{&sink_gen})); @@ -1806,7 +1806,7 @@ void TestSimpleJoinHelper(BatchesWithSchema input_left, BatchesWithSchema input_ BatchesWithSchema expected) { ExecContext exec_ctx; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(&exec_ctx)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ExecNode* left_source; ExecNode* right_source; @@ -2001,7 +2001,7 @@ TEST(HashJoin, ResidualFilter) { default_memory_pool(), parallel ? arrow::internal::GetCpuThreadPool() : nullptr); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(exec_ctx.get())); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ExecNode* left_source; ExecNode* right_source; @@ -2079,7 +2079,7 @@ TEST(HashJoin, TrivialResidualFilter) { parallel ? arrow::internal::GetCpuThreadPool() : nullptr); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(exec_ctx.get())); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ExecNode* left_source; ExecNode* right_source; @@ -2242,7 +2242,7 @@ void TestSingleChainOfHashJoins(Random64Bit& rng) { ASSERT_OK_AND_ASSIGN(joins[i], MakeExecNode("hashjoin", plan.get(), inputs, opts[i])); } - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK( MakeExecNode("sink", plan.get(), {joins.back()}, SinkNodeOptions{&sink_gen})); ASSERT_FINISHES_OK_AND_ASSIGN(auto result, StartAndCollect(plan.get(), sink_gen)); diff --git a/cpp/src/arrow/compute/exec/options.h b/cpp/src/arrow/compute/exec/options.h index e0172bff7f762..c5edc0610c5ee 100644 --- a/cpp/src/arrow/compute/exec/options.h +++ b/cpp/src/arrow/compute/exec/options.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -29,13 +30,12 @@ #include "arrow/result.h" #include "arrow/util/async_generator.h" #include "arrow/util/async_util.h" -#include "arrow/util/optional.h" #include "arrow/util/visibility.h" namespace arrow { namespace compute { -using AsyncExecBatchGenerator = AsyncGenerator>; +using AsyncExecBatchGenerator = AsyncGenerator>; /// \addtogroup execnode-options /// @{ @@ -51,14 +51,14 @@ class ARROW_EXPORT ExecNodeOptions { class ARROW_EXPORT SourceNodeOptions : public ExecNodeOptions { public: SourceNodeOptions(std::shared_ptr output_schema, - std::function>()> generator) + std::function>()> generator) : output_schema(std::move(output_schema)), generator(std::move(generator)) {} static Result> FromTable(const Table& table, arrow::internal::Executor*); std::shared_ptr output_schema; - std::function>()> generator; + std::function>()> generator; }; /// \brief An extended Source node which accepts a table @@ -166,7 +166,7 @@ struct ARROW_EXPORT BackpressureOptions { /// Emitted batches will not be ordered. class ARROW_EXPORT SinkNodeOptions : public ExecNodeOptions { public: - explicit SinkNodeOptions(std::function>()>* generator, + explicit SinkNodeOptions(std::function>()>* generator, BackpressureOptions backpressure = {}, BackpressureMonitor** backpressure_monitor = NULLPTR) : generator(generator), @@ -178,7 +178,7 @@ class ARROW_EXPORT SinkNodeOptions : public ExecNodeOptions { /// This will be set when the node is added to the plan and should be used to consume /// data from the plan. If this function is not called frequently enough then the sink /// node will start to accumulate data and may apply backpressure. - std::function>()>* generator; + std::function>()>* generator; /// \brief Options to control when to apply backpressure /// /// This is optional, the default is to never apply backpressure. If the plan is not @@ -250,7 +250,7 @@ class ARROW_EXPORT OrderBySinkNodeOptions : public SinkNodeOptions { public: explicit OrderBySinkNodeOptions( SortOptions sort_options, - std::function>()>* generator) + std::function>()>* generator) : SinkNodeOptions(generator), sort_options(std::move(sort_options)) {} SortOptions sort_options; @@ -427,7 +427,7 @@ class ARROW_EXPORT SelectKSinkNodeOptions : public SinkNodeOptions { public: explicit SelectKSinkNodeOptions( SelectKOptions select_k_options, - std::function>()>* generator) + std::function>()>* generator) : SinkNodeOptions(generator), select_k_options(std::move(select_k_options)) {} /// SelectK options diff --git a/cpp/src/arrow/compute/exec/plan_test.cc b/cpp/src/arrow/compute/exec/plan_test.cc index e06c41c74896d..1dd071975eec1 100644 --- a/cpp/src/arrow/compute/exec/plan_test.cc +++ b/cpp/src/arrow/compute/exec/plan_test.cc @@ -220,7 +220,7 @@ TEST(ExecPlanExecution, SourceSink) { SCOPED_TRACE(parallel ? "parallel" : "single threaded"); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto basic_data = MakeBasicBatches(); @@ -239,7 +239,7 @@ TEST(ExecPlanExecution, SourceSink) { } TEST(ExecPlanExecution, UseSinkAfterExecution) { - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); auto basic_data = MakeBasicBatches(); @@ -260,7 +260,7 @@ TEST(ExecPlanExecution, UseSinkAfterExecution) { TEST(ExecPlanExecution, TableSourceSink) { for (int batch_size : {1, 4}) { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto exp_batches = MakeBasicBatches(); ASSERT_OK_AND_ASSIGN(auto table, @@ -281,7 +281,7 @@ TEST(ExecPlanExecution, TableSourceSink) { TEST(ExecPlanExecution, TableSourceSinkError) { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto exp_batches = MakeBasicBatches(); ASSERT_OK_AND_ASSIGN(auto table, @@ -297,7 +297,7 @@ TEST(ExecPlanExecution, TableSourceSinkError) { } TEST(ExecPlanExecution, SinkNodeBackpressure) { - util::optional batch = + std::optional batch = ExecBatchFromJSON({int32(), boolean()}, "[[4, false], [5, null], [6, false], [7, false], [null, true]]"); constexpr uint32_t kPauseIfAbove = 4; @@ -307,8 +307,8 @@ TEST(ExecPlanExecution, SinkNodeBackpressure) { uint32_t resume_if_below_bytes = kResumeIfBelow * static_cast(batch->TotalBufferSize()); EXPECT_OK_AND_ASSIGN(std::shared_ptr plan, ExecPlan::Make()); - PushGenerator> batch_producer; - AsyncGenerator> sink_gen; + PushGenerator> batch_producer; + AsyncGenerator> sink_gen; BackpressureMonitor* backpressure_monitor; BackpressureOptions backpressure_options(resume_if_below_bytes, pause_if_above_bytes); std::shared_ptr schema_ = schema({field("data", uint32())}); @@ -349,14 +349,14 @@ TEST(ExecPlanExecution, SinkNodeBackpressure) { ASSERT_FALSE(backpressure_monitor->is_paused()); // Cleanup - batch_producer.producer().Push(IterationEnd>()); + batch_producer.producer().Push(IterationEnd>()); plan->StopProducing(); ASSERT_FINISHES_OK(plan->finished()); } TEST(ExecPlan, ToString) { auto basic_data = MakeBasicBatches(); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); ASSERT_OK(Declaration::Sequence( @@ -462,7 +462,7 @@ TEST(ExecPlanExecution, SourceOrderBy) { SCOPED_TRACE(parallel ? "parallel" : "single threaded"); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto basic_data = MakeBasicBatches(); @@ -483,16 +483,16 @@ TEST(ExecPlanExecution, SourceOrderBy) { TEST(ExecPlanExecution, SourceSinkError) { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto basic_data = MakeBasicBatches(); auto it = basic_data.batches.begin(); - AsyncGenerator> error_source_gen = - [&]() -> Result> { + AsyncGenerator> error_source_gen = + [&]() -> Result> { if (it == basic_data.batches.end()) { return Status::Invalid("Artificial error"); } - return util::make_optional(*it++); + return std::make_optional(*it++); }; ASSERT_OK(Declaration::Sequence( @@ -693,7 +693,7 @@ TEST(ExecPlanExecution, StressSourceSink) { int num_batches = (slow && !parallel) ? 30 : 300; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto random_data = MakeRandomBatches( schema({field("a", int32()), field("b", boolean())}), num_batches); @@ -723,7 +723,7 @@ TEST(ExecPlanExecution, StressSourceOrderBy) { int num_batches = (slow && !parallel) ? 30 : 300; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto random_data = MakeRandomBatches(input_schema, num_batches); @@ -760,7 +760,7 @@ TEST(ExecPlanExecution, StressSourceGroupedSumStop) { int num_batches = (slow && !parallel) ? 30 : 300; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto random_data = MakeRandomBatches(input_schema, num_batches); @@ -795,7 +795,7 @@ TEST(ExecPlanExecution, StressSourceSinkStopped) { int num_batches = (slow && !parallel) ? 30 : 300; ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto random_data = MakeRandomBatches( schema({field("a", int32()), field("b", boolean())}), num_batches); @@ -823,7 +823,7 @@ TEST(ExecPlanExecution, SourceFilterSink) { auto basic_data = MakeBasicBatches(); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence( { @@ -845,7 +845,7 @@ TEST(ExecPlanExecution, SourceProjectSink) { auto basic_data = MakeBasicBatches(); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence( { @@ -911,7 +911,7 @@ TEST(ExecPlanExecution, SourceGroupedSum) { auto input = MakeGroupableBatches(/*multiplicity=*/parallel ? 100 : 1); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK( Declaration::Sequence( @@ -945,7 +945,7 @@ TEST(ExecPlanExecution, SourceMinMaxScalar) { R"({"min": -8, "max": 12})")}); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; // NOTE: Test `ScalarAggregateNode` by omitting `keys` attribute ASSERT_OK(Declaration::Sequence( @@ -976,7 +976,7 @@ TEST(ExecPlanExecution, NestedSourceFilter) { ])"); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence( { @@ -1005,7 +1005,7 @@ TEST(ExecPlanExecution, NestedSourceProjectGroupedSum) { ])"); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK( Declaration::Sequence( @@ -1037,7 +1037,7 @@ TEST(ExecPlanExecution, SourceFilterProjectGroupedSumFilter) { auto input = MakeGroupableBatches(/*multiplicity=*/batch_multiplicity); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK( Declaration::Sequence( @@ -1076,7 +1076,7 @@ TEST(ExecPlanExecution, SourceFilterProjectGroupedSumOrderBy) { auto input = MakeGroupableBatches(/*multiplicity=*/batch_multiplicity); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; SortOptions options({SortKey("str", SortOrder::Descending)}); ASSERT_OK( @@ -1116,7 +1116,7 @@ TEST(ExecPlanExecution, SourceFilterProjectGroupedSumTopK) { auto input = MakeGroupableBatches(/*multiplicity=*/batch_multiplicity); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; SelectKOptions options = SelectKOptions::TopKDefault(/*k=*/1, {"str"}); ASSERT_OK(Declaration::Sequence( @@ -1145,7 +1145,7 @@ TEST(ExecPlanExecution, SourceFilterProjectGroupedSumTopK) { TEST(ExecPlanExecution, SourceScalarAggSink) { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto basic_data = MakeBasicBatches(); @@ -1175,7 +1175,7 @@ TEST(ExecPlanExecution, AggregationPreservesOptions) { // and need to keep a copy/strong reference to function options { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto basic_data = MakeBasicBatches(); @@ -1202,7 +1202,7 @@ TEST(ExecPlanExecution, AggregationPreservesOptions) { } { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto data = MakeGroupableBatches(/*multiplicity=*/100); @@ -1234,7 +1234,7 @@ TEST(ExecPlanExecution, ScalarSourceScalarAggSink) { // ARROW-9056: scalar aggregation can be done over scalars, taking // into account batch.length > 1 (e.g. a partition column) ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; BatchesWithSchema scalar_data; scalar_data.batches = { @@ -1280,7 +1280,7 @@ TEST(ExecPlanExecution, ScalarSourceScalarAggSink) { TEST(ExecPlanExecution, ScalarSourceGroupedSum) { // ARROW-14630: ensure grouped aggregation with a scalar key/array input doesn't error ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; BatchesWithSchema scalar_data; scalar_data.batches = { @@ -1321,7 +1321,7 @@ TEST(ExecPlanExecution, SelfInnerHashJoinSink) { default_memory_pool(), parallel ? arrow::internal::GetCpuThreadPool() : nullptr); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(exec_ctx.get())); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ExecNode* left_source; ExecNode* right_source; @@ -1378,7 +1378,7 @@ TEST(ExecPlanExecution, SelfOuterHashJoinSink) { default_memory_pool(), parallel ? arrow::internal::GetCpuThreadPool() : nullptr); ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make(exec_ctx.get())); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ExecNode* left_source; ExecNode* right_source; @@ -1428,7 +1428,7 @@ TEST(ExecPlanExecution, SelfOuterHashJoinSink) { TEST(ExecPlan, RecordBatchReaderSourceSink) { ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make()); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; // set up a RecordBatchReader: auto input = MakeBasicBatches(); @@ -1464,7 +1464,7 @@ TEST(ExecPlan, SourceEnforcesBatchLimit) { schema({field("a", int32()), field("b", boolean())}), /*num_batches=*/3, /*batch_size=*/static_cast(std::floor(ExecPlan::kMaxBatchSize * 3.5))); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK(Declaration::Sequence( { diff --git a/cpp/src/arrow/compute/exec/sink_node.cc b/cpp/src/arrow/compute/exec/sink_node.cc index 8af4e8e996cce..96a34bff43766 100644 --- a/cpp/src/arrow/compute/exec/sink_node.cc +++ b/cpp/src/arrow/compute/exec/sink_node.cc @@ -17,6 +17,7 @@ // under the License. #include +#include #include "arrow/compute/api_vector.h" #include "arrow/compute/exec.h" @@ -34,7 +35,6 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/future.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/thread_pool.h" #include "arrow/util/tracing_internal.h" #include "arrow/util/unreachable.h" @@ -89,7 +89,7 @@ class BackpressureReservoir : public BackpressureMonitor { class SinkNode : public ExecNode { public: SinkNode(ExecPlan* plan, std::vector inputs, - AsyncGenerator>* generator, + AsyncGenerator>* generator, BackpressureOptions backpressure, BackpressureMonitor** backpressure_monitor_out) : ExecNode(plan, std::move(inputs), {"collected"}, {}, @@ -102,12 +102,12 @@ class SinkNode : public ExecNode { *backpressure_monitor_out = &backpressure_queue_; } auto node_destroyed_capture = node_destroyed_; - *generator = [this, node_destroyed_capture]() -> Future> { + *generator = [this, node_destroyed_capture]() -> Future> { if (*node_destroyed_capture) { return Status::Invalid( "Attempt to consume data after the plan has been destroyed"); } - return push_gen_().Then([this](const util::optional& batch) { + return push_gen_().Then([this](const std::optional& batch) { if (batch) { RecordBackpressureBytesFreed(*batch); } @@ -247,8 +247,8 @@ class SinkNode : public ExecNode { // Needs to be a shared_ptr as the push generator can technically outlive the node BackpressureReservoir backpressure_queue_; - PushGenerator> push_gen_; - PushGenerator>::Producer producer_; + PushGenerator> push_gen_; + PushGenerator>::Producer producer_; std::shared_ptr node_destroyed_; }; @@ -404,7 +404,7 @@ static Result MakeTableConsumingSinkNode( struct OrderBySinkNode final : public SinkNode { OrderBySinkNode(ExecPlan* plan, std::vector inputs, std::unique_ptr impl, - AsyncGenerator>* generator) + AsyncGenerator>* generator) : SinkNode(plan, std::move(inputs), generator, /*backpressure=*/{}, /*backpressure_monitor_out=*/nullptr), impl_(std::move(impl)) {} diff --git a/cpp/src/arrow/compute/exec/source_node.cc b/cpp/src/arrow/compute/exec/source_node.cc index a640cf737efa7..1d51a5c1d2844 100644 --- a/cpp/src/arrow/compute/exec/source_node.cc +++ b/cpp/src/arrow/compute/exec/source_node.cc @@ -16,6 +16,7 @@ // under the License. #include +#include #include "arrow/compute/exec.h" #include "arrow/compute/exec/exec_plan.h" @@ -31,7 +32,6 @@ #include "arrow/util/checked_cast.h" #include "arrow/util/future.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/thread_pool.h" #include "arrow/util/tracing_internal.h" #include "arrow/util/unreachable.h" @@ -47,7 +47,7 @@ namespace { struct SourceNode : ExecNode { SourceNode(ExecPlan* plan, std::shared_ptr output_schema, - AsyncGenerator> generator) + AsyncGenerator> generator) : ExecNode(plan, {}, {}, std::move(output_schema), /*num_outputs=*/1), generator_(std::move(generator)) {} @@ -112,7 +112,7 @@ struct SourceNode : ExecNode { lock.unlock(); return generator_().Then( - [=](const util::optional& maybe_morsel) + [=](const std::optional& maybe_morsel) -> Future> { std::unique_lock lock(mutex_); if (IsIterationEnd(maybe_morsel) || stop_requested_) { @@ -221,7 +221,7 @@ struct SourceNode : ExecNode { bool stop_requested_{false}; bool started_ = false; int batch_count_{0}; - AsyncGenerator> generator_; + AsyncGenerator> generator_; }; struct TableSourceNode : public SourceNode { @@ -257,13 +257,13 @@ struct TableSourceNode : public SourceNode { return Status::OK(); } - static arrow::AsyncGenerator> TableGenerator( + static arrow::AsyncGenerator> TableGenerator( const Table& table, const int64_t batch_size) { auto batches = ConvertTableToExecBatches(table, batch_size); auto opt_batches = - MapVector([](ExecBatch batch) { return util::make_optional(std::move(batch)); }, + MapVector([](ExecBatch batch) { return std::make_optional(std::move(batch)); }, std::move(batches)); - AsyncGenerator> gen; + AsyncGenerator> gen; gen = MakeVectorGenerator(std::move(opt_batches)); return gen; } diff --git a/cpp/src/arrow/compute/exec/subtree_internal.h b/cpp/src/arrow/compute/exec/subtree_internal.h index 72d419df2259a..9e55af6068f3e 100644 --- a/cpp/src/arrow/compute/exec/subtree_internal.h +++ b/cpp/src/arrow/compute/exec/subtree_internal.h @@ -18,13 +18,13 @@ #pragma once #include +#include #include #include #include #include #include "arrow/compute/exec/expression.h" -#include "arrow/util/optional.h" namespace arrow { namespace compute { @@ -64,7 +64,7 @@ struct SubtreeImpl { struct Encoded { // An external index identifying the corresponding object (e.g. a Fragment) of the // guarantee. - util::optional index; + std::optional index; // An encoded expression representing a guarantee. expression_codes guarantee; }; @@ -112,7 +112,7 @@ struct SubtreeImpl { void GenerateSubtrees(expression_codes guarantee, std::vector* encoded) { while (!guarantee.empty()) { if (subtree_exprs_.insert(guarantee).second) { - Encoded encoded_subtree{/*index=*/util::nullopt, guarantee}; + Encoded encoded_subtree{/*index=*/std::nullopt, guarantee}; encoded->push_back(std::move(encoded_subtree)); } guarantee.resize(guarantee.size() - 1); diff --git a/cpp/src/arrow/compute/exec/subtree_test.cc b/cpp/src/arrow/compute/exec/subtree_test.cc index 9721310445445..9e6e86dbd4fcf 100644 --- a/cpp/src/arrow/compute/exec/subtree_test.cc +++ b/cpp/src/arrow/compute/exec/subtree_test.cc @@ -327,9 +327,9 @@ TEST(Subtree, GetSubtreeExpression) { const auto code_a = tree.GetOrInsert(expr_a); const auto code_b = tree.GetOrInsert(expr_b); ASSERT_EQ(expr_a, - tree.GetSubtreeExpression(SubtreeImpl::Encoded{util::nullopt, {code_a}})); + tree.GetSubtreeExpression(SubtreeImpl::Encoded{std::nullopt, {code_a}})); ASSERT_EQ(expr_b, tree.GetSubtreeExpression( - SubtreeImpl::Encoded{util::nullopt, {code_a, code_b}})); + SubtreeImpl::Encoded{std::nullopt, {code_a, code_b}})); } class FakeFragment { @@ -363,14 +363,14 @@ TEST(Subtree, EncodeFragments) { EXPECT_THAT( encoded, testing::UnorderedElementsAreArray({ - SubtreeImpl::Encoded{util::make_optional(0), + SubtreeImpl::Encoded{std::make_optional(0), SubtreeImpl::expression_codes({0, 1})}, - SubtreeImpl::Encoded{util::make_optional(1), + SubtreeImpl::Encoded{std::make_optional(1), SubtreeImpl::expression_codes({2, 3})}, - SubtreeImpl::Encoded{util::nullopt, SubtreeImpl::expression_codes({0})}, - SubtreeImpl::Encoded{util::nullopt, SubtreeImpl::expression_codes({2})}, - SubtreeImpl::Encoded{util::nullopt, SubtreeImpl::expression_codes({0, 1})}, - SubtreeImpl::Encoded{util::nullopt, SubtreeImpl::expression_codes({2, 3})}, + SubtreeImpl::Encoded{std::nullopt, SubtreeImpl::expression_codes({0})}, + SubtreeImpl::Encoded{std::nullopt, SubtreeImpl::expression_codes({2})}, + SubtreeImpl::Encoded{std::nullopt, SubtreeImpl::expression_codes({0, 1})}, + SubtreeImpl::Encoded{std::nullopt, SubtreeImpl::expression_codes({2, 3})}, })); } } // namespace compute diff --git a/cpp/src/arrow/compute/exec/test_util.cc b/cpp/src/arrow/compute/exec/test_util.cc index cc26143179a36..8c8c3f6b3b2f6 100644 --- a/cpp/src/arrow/compute/exec/test_util.cc +++ b/cpp/src/arrow/compute/exec/test_util.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #include "arrow/util/async_generator.h" #include "arrow/util/iterator.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/unreachable.h" #include "arrow/util/vector.h" @@ -180,7 +180,7 @@ Future<> StartAndFinish(ExecPlan* plan) { } Future> StartAndCollect( - ExecPlan* plan, AsyncGenerator> gen) { + ExecPlan* plan, AsyncGenerator> gen) { RETURN_NOT_OK(plan->Validate()); RETURN_NOT_OK(plan->StartProducing()); @@ -190,7 +190,7 @@ Future> StartAndCollect( .Then([collected_fut]() -> Result> { ARROW_ASSIGN_OR_RAISE(auto collected, collected_fut.result()); return ::arrow::internal::MapVector( - [](util::optional batch) { return std::move(*batch); }, + [](std::optional batch) { return std::move(*batch); }, std::move(collected)); }); } diff --git a/cpp/src/arrow/compute/exec/test_util.h b/cpp/src/arrow/compute/exec/test_util.h index ac9a4ae4ced52..5b6e8226b7e84 100644 --- a/cpp/src/arrow/compute/exec/test_util.h +++ b/cpp/src/arrow/compute/exec/test_util.h @@ -60,11 +60,11 @@ struct BatchesWithSchema { std::vector batches; std::shared_ptr schema; - AsyncGenerator> gen(bool parallel, bool slow) const { + AsyncGenerator> gen(bool parallel, bool slow) const { auto opt_batches = ::arrow::internal::MapVector( - [](ExecBatch batch) { return util::make_optional(std::move(batch)); }, batches); + [](ExecBatch batch) { return std::make_optional(std::move(batch)); }, batches); - AsyncGenerator> gen; + AsyncGenerator> gen; if (parallel) { // emulate batches completing initial decode-after-scan on a cpu thread @@ -81,7 +81,7 @@ struct BatchesWithSchema { if (slow) { gen = - MakeMappedGenerator(std::move(gen), [](const util::optional& batch) { + MakeMappedGenerator(std::move(gen), [](const std::optional& batch) { SleepABit(); return batch; }); @@ -96,7 +96,7 @@ Future<> StartAndFinish(ExecPlan* plan); ARROW_TESTING_EXPORT Future> StartAndCollect( - ExecPlan* plan, AsyncGenerator> gen); + ExecPlan* plan, AsyncGenerator> gen); ARROW_TESTING_EXPORT BatchesWithSchema MakeBasicBatches(); diff --git a/cpp/src/arrow/compute/exec/tpch_benchmark.cc b/cpp/src/arrow/compute/exec/tpch_benchmark.cc index 54ac7cbdbf514..5aad5370b738c 100644 --- a/cpp/src/arrow/compute/exec/tpch_benchmark.cc +++ b/cpp/src/arrow/compute/exec/tpch_benchmark.cc @@ -28,7 +28,7 @@ namespace arrow { namespace compute { namespace internal { -std::shared_ptr Plan_Q1(AsyncGenerator>* sink_gen, +std::shared_ptr Plan_Q1(AsyncGenerator>* sink_gen, int scale_factor) { ExecContext* ctx = default_exec_context(); *ctx = ExecContext(default_memory_pool(), arrow::internal::GetCpuThreadPool()); @@ -109,7 +109,7 @@ std::shared_ptr Plan_Q1(AsyncGenerator>* sin static void BM_Tpch_Q1(benchmark::State& st) { for (auto _ : st) { st.PauseTiming(); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; std::shared_ptr plan = Plan_Q1(&sink_gen, static_cast(st.range(0))); st.ResumeTiming(); auto fut = StartAndCollect(plan.get(), sink_gen); diff --git a/cpp/src/arrow/compute/exec/tpch_node.cc b/cpp/src/arrow/compute/exec/tpch_node.cc index 978a8fb1ff728..40d44dccccf1e 100644 --- a/cpp/src/arrow/compute/exec/tpch_node.cc +++ b/cpp/src/arrow/compute/exec/tpch_node.cc @@ -664,7 +664,7 @@ class PartAndPartSupplierGenerator { return SetOutputColumns(cols, kPartsuppTypes, kPartsuppNameMap, partsupp_cols_); } - Result> NextPartBatch(size_t thread_index) { + Result> NextPartBatch(size_t thread_index) { ThreadLocalData& tld = thread_local_data_[thread_index]; { std::lock_guard lock(part_output_queue_mutex_); @@ -673,7 +673,7 @@ class PartAndPartSupplierGenerator { part_output_queue_.pop(); return std::move(batch); } else if (part_rows_generated_ == part_rows_to_generate_) { - return util::nullopt; + return std::nullopt; } else { tld.partkey_start = part_rows_generated_; tld.part_to_generate = @@ -719,7 +719,7 @@ class PartAndPartSupplierGenerator { return ExecBatch::Make(std::move(part_result)); } - Result> NextPartSuppBatch(size_t thread_index) { + Result> NextPartSuppBatch(size_t thread_index) { ThreadLocalData& tld = thread_local_data_[thread_index]; { std::lock_guard lock(partsupp_output_queue_mutex_); @@ -732,7 +732,7 @@ class PartAndPartSupplierGenerator { { std::lock_guard lock(part_output_queue_mutex_); if (part_rows_generated_ == part_rows_to_generate_) { - return util::nullopt; + return std::nullopt; } else { tld.partkey_start = part_rows_generated_; tld.part_to_generate = @@ -1324,7 +1324,7 @@ class OrdersAndLineItemGenerator { return SetOutputColumns(cols, kLineitemTypes, kLineitemNameMap, lineitem_cols_); } - Result> NextOrdersBatch(size_t thread_index) { + Result> NextOrdersBatch(size_t thread_index) { ThreadLocalData& tld = thread_local_data_[thread_index]; { std::lock_guard lock(orders_output_queue_mutex_); @@ -1333,7 +1333,7 @@ class OrdersAndLineItemGenerator { orders_output_queue_.pop(); return std::move(batch); } else if (orders_rows_generated_ == orders_rows_to_generate_) { - return util::nullopt; + return std::nullopt; } else { tld.orderkey_start = orders_rows_generated_; tld.orders_to_generate = @@ -1379,7 +1379,7 @@ class OrdersAndLineItemGenerator { return ExecBatch::Make(std::move(orders_result)); } - Result> NextLineItemBatch(size_t thread_index) { + Result> NextLineItemBatch(size_t thread_index) { ThreadLocalData& tld = thread_local_data_[thread_index]; ExecBatch queued; bool from_queue = false; @@ -1401,7 +1401,7 @@ class OrdersAndLineItemGenerator { std::lock_guard lock(orders_output_queue_mutex_); if (orders_rows_generated_ == orders_rows_to_generate_) { if (from_queue) return std::move(queued); - return util::nullopt; + return std::nullopt; } tld.orderkey_start = orders_rows_generated_; @@ -2709,7 +2709,7 @@ class PartGenerator : public TpchTableGenerator { private: Status ProduceCallback(size_t thread_index) { if (done_.load()) return Status::OK(); - ARROW_ASSIGN_OR_RAISE(util::optional maybe_batch, + ARROW_ASSIGN_OR_RAISE(std::optional maybe_batch, gen_->NextPartBatch(thread_index)); if (!maybe_batch.has_value()) { int64_t batches_generated = gen_->part_batches_generated(); @@ -2771,7 +2771,7 @@ class PartSuppGenerator : public TpchTableGenerator { private: Status ProduceCallback(size_t thread_index) { if (done_.load()) return Status::OK(); - ARROW_ASSIGN_OR_RAISE(util::optional maybe_batch, + ARROW_ASSIGN_OR_RAISE(std::optional maybe_batch, gen_->NextPartSuppBatch(thread_index)); if (!maybe_batch.has_value()) { int64_t batches_generated = gen_->partsupp_batches_generated(); @@ -3090,7 +3090,7 @@ class OrdersGenerator : public TpchTableGenerator { private: Status ProduceCallback(size_t thread_index) { if (done_.load()) return Status::OK(); - ARROW_ASSIGN_OR_RAISE(util::optional maybe_batch, + ARROW_ASSIGN_OR_RAISE(std::optional maybe_batch, gen_->NextOrdersBatch(thread_index)); if (!maybe_batch.has_value()) { int64_t batches_generated = gen_->orders_batches_generated(); @@ -3152,7 +3152,7 @@ class LineitemGenerator : public TpchTableGenerator { private: Status ProduceCallback(size_t thread_index) { if (done_.load()) return Status::OK(); - ARROW_ASSIGN_OR_RAISE(util::optional maybe_batch, + ARROW_ASSIGN_OR_RAISE(std::optional maybe_batch, gen_->NextLineItemBatch(thread_index)); if (!maybe_batch.has_value()) { int64_t batches_generated = gen_->lineitem_batches_generated(); @@ -3541,7 +3541,7 @@ Result TpchGenImpl::Region(std::vector columns) { Result> TpchGen::Make(ExecPlan* plan, double scale_factor, int64_t batch_size, - util::optional seed) { + std::optional seed) { if (!seed.has_value()) seed = GetRandomSeed(); return std::unique_ptr(new TpchGenImpl(plan, scale_factor, batch_size, *seed)); } diff --git a/cpp/src/arrow/compute/exec/tpch_node.h b/cpp/src/arrow/compute/exec/tpch_node.h index fb9376982b1b0..061b66ca43616 100644 --- a/cpp/src/arrow/compute/exec/tpch_node.h +++ b/cpp/src/arrow/compute/exec/tpch_node.h @@ -18,13 +18,13 @@ #pragma once #include +#include #include #include #include "arrow/compute/type_fwd.h" #include "arrow/result.h" #include "arrow/status.h" -#include "arrow/util/optional.h" namespace arrow { namespace compute { @@ -44,7 +44,7 @@ class ARROW_EXPORT TpchGen { */ static Result> Make( ExecPlan* plan, double scale_factor = 1.0, int64_t batch_size = 4096, - util::optional seed = util::nullopt); + std::optional seed = std::nullopt); // The below methods will create and add an ExecNode to the plan that generates // data for the desired table. If columns is empty, all columns will be generated. diff --git a/cpp/src/arrow/compute/exec/tpch_node_test.cc b/cpp/src/arrow/compute/exec/tpch_node_test.cc index fc26ce90c2e2e..133dbfdf43c4a 100644 --- a/cpp/src/arrow/compute/exec/tpch_node_test.cc +++ b/cpp/src/arrow/compute/exec/tpch_node_test.cc @@ -50,7 +50,7 @@ using TableNodeFn = Result (TpchGen::*)(std::vector); constexpr double kDefaultScaleFactor = 0.1; Status AddTableAndSinkToPlan(ExecPlan& plan, TpchGen& gen, - AsyncGenerator>& sink_gen, + AsyncGenerator>& sink_gen, TableNodeFn table) { ARROW_ASSIGN_OR_RAISE(ExecNode * table_node, ((gen.*table)({}))); Declaration sink("sink", {Declaration::Input(table_node)}, SinkNodeOptions{&sink_gen}); @@ -64,7 +64,7 @@ Result> GenerateTable(TableNodeFn table, ARROW_ASSIGN_OR_RAISE(std::shared_ptr plan, ExecPlan::Make(&ctx)); ARROW_ASSIGN_OR_RAISE(std::unique_ptr gen, TpchGen::Make(plan.get(), scale_factor)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ARROW_RETURN_NOT_OK(AddTableAndSinkToPlan(*plan, *gen, sink_gen, table)); auto fut = StartAndCollect(plan.get(), sink_gen); return fut.MoveResult(); @@ -618,7 +618,7 @@ TEST(TpchNode, AllTables) { &VerifyOrders, &VerifyLineitem, &VerifyNation, &VerifyRegion, }; - std::array>, kNumTables> gens; + std::array>, kNumTables> gens; ExecContext ctx(default_memory_pool(), arrow::internal::GetCpuThreadPool()); ASSERT_OK_AND_ASSIGN(std::shared_ptr plan, ExecPlan::Make(&ctx)); ASSERT_OK_AND_ASSIGN(std::unique_ptr gen, diff --git a/cpp/src/arrow/compute/exec/union_node_test.cc b/cpp/src/arrow/compute/exec/union_node_test.cc index 41aaac26d2bfe..d14bfe16e5fef 100644 --- a/cpp/src/arrow/compute/exec/union_node_test.cc +++ b/cpp/src/arrow/compute/exec/union_node_test.cc @@ -90,7 +90,7 @@ struct TestUnionNode : public ::testing::Test { "source", SourceNodeOptions{batch.schema, batch.gen(parallel, /*slow=*/false)}}); } - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; // Test UnionNode::Make with zero inputs if (batches.size() == 0) { diff --git a/cpp/src/arrow/compute/exec/util.h b/cpp/src/arrow/compute/exec/util.h index 7e716808fa008..e1797771fe00b 100644 --- a/cpp/src/arrow/compute/exec/util.h +++ b/cpp/src/arrow/compute/exec/util.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,6 @@ #include "arrow/util/cpu_info.h" #include "arrow/util/logging.h" #include "arrow/util/mutex.h" -#include "arrow/util/optional.h" #include "arrow/util/thread_pool.h" #if defined(__clang__) || defined(__GNUC__) @@ -246,7 +246,7 @@ class ARROW_EXPORT AtomicCounter { int count() const { return count_.load(); } - util::optional total() const { + std::optional total() const { int total = total_.load(); if (total == -1) return {}; return total; diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index a6ede14176c7e..a20b4ce147609 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #include "arrow/util/logging.h" #include "arrow/util/macros.h" #include "arrow/util/make_unique.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" #include "arrow/visit_data_inline.h" diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate.cc b/cpp/src/arrow/compute/kernels/hash_aggregate.cc index 4537c32eb38fe..068fcab95e40e 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate.cc @@ -1435,7 +1435,7 @@ struct GroupedMinMaxImpl enable_if_base_binary MakeOffsetsValues( - ArrayData* array, const std::vector>& values) { + ArrayData* array, const std::vector>& values) { using offset_type = typename T::offset_type; ARROW_ASSIGN_OR_RAISE( auto raw_offsets, @@ -1447,7 +1447,7 @@ struct GroupedMinMaxImpl& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); if (value->size() > static_cast(std::numeric_limits::max()) || @@ -1463,7 +1463,7 @@ struct GroupedMinMaxImpl& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); std::memcpy(data->mutable_data() + offset, value->data(), value->size()); offset += value->size(); @@ -1476,7 +1476,7 @@ struct GroupedMinMaxImpl enable_if_same MakeOffsetsValues( - ArrayData* array, const std::vector>& values) { + ArrayData* array, const std::vector>& values) { const uint8_t* null_bitmap = array->buffers[0]->data(); const int32_t slot_width = checked_cast(*array->type).byte_width(); @@ -1485,7 +1485,7 @@ struct GroupedMinMaxImpl& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); std::memcpy(data->mutable_data() + offset, value->data(), slot_width); } else { @@ -1504,7 +1504,7 @@ struct GroupedMinMaxImpl> mins_, maxes_; + std::vector> mins_, maxes_; TypedBufferBuilder has_values_, has_nulls_; std::shared_ptr type_; ScalarAggregateOptions options_; @@ -2128,7 +2128,7 @@ struct GroupedOneImpl::value || template enable_if_base_binary MakeOffsetsValues( - ArrayData* array, const std::vector>& values) { + ArrayData* array, const std::vector>& values) { using offset_type = typename T::offset_type; ARROW_ASSIGN_OR_RAISE( auto raw_offsets, @@ -2140,7 +2140,7 @@ struct GroupedOneImpl::value || offset_type total_length = 0; for (size_t i = 0; i < values.size(); i++) { if (bit_util::GetBit(null_bitmap, i)) { - const util::optional& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); if (value->size() > static_cast(std::numeric_limits::max()) || @@ -2156,7 +2156,7 @@ struct GroupedOneImpl::value || int64_t offset = 0; for (size_t i = 0; i < values.size(); i++) { if (bit_util::GetBit(null_bitmap, i)) { - const util::optional& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); std::memcpy(data->mutable_data() + offset, value->data(), value->size()); offset += value->size(); @@ -2169,7 +2169,7 @@ struct GroupedOneImpl::value || template enable_if_same MakeOffsetsValues( - ArrayData* array, const std::vector>& values) { + ArrayData* array, const std::vector>& values) { const uint8_t* null_bitmap = array->buffers[0]->data(); const int32_t slot_width = checked_cast(*array->type).byte_width(); @@ -2178,7 +2178,7 @@ struct GroupedOneImpl::value || int64_t offset = 0; for (size_t i = 0; i < values.size(); i++) { if (bit_util::GetBit(null_bitmap, i)) { - const util::optional& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); std::memcpy(data->mutable_data() + offset, value->data(), slot_width); } else { @@ -2195,7 +2195,7 @@ struct GroupedOneImpl::value || ExecContext* ctx_; Allocator allocator_; int64_t num_groups_; - std::vector> ones_; + std::vector> ones_; TypedBufferBuilder has_one_; std::shared_ptr out_type_; }; @@ -2467,7 +2467,7 @@ struct GroupedListImpl::value || template enable_if_base_binary MakeOffsetsValues( - ArrayData* array, const std::vector>& values) { + ArrayData* array, const std::vector>& values) { using offset_type = typename T::offset_type; ARROW_ASSIGN_OR_RAISE( auto raw_offsets, @@ -2479,7 +2479,7 @@ struct GroupedListImpl::value || offset_type total_length = 0; for (size_t i = 0; i < values.size(); i++) { if (bit_util::GetBit(null_bitmap, i)) { - const util::optional& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); if (value->size() > static_cast(std::numeric_limits::max()) || @@ -2495,7 +2495,7 @@ struct GroupedListImpl::value || int64_t offset = 0; for (size_t i = 0; i < values.size(); i++) { if (bit_util::GetBit(null_bitmap, i)) { - const util::optional& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); std::memcpy(data->mutable_data() + offset, value->data(), value->size()); offset += value->size(); @@ -2508,7 +2508,7 @@ struct GroupedListImpl::value || template enable_if_same MakeOffsetsValues( - ArrayData* array, const std::vector>& values) { + ArrayData* array, const std::vector>& values) { const uint8_t* null_bitmap = array->buffers[0]->data(); const int32_t slot_width = checked_cast(*array->type).byte_width(); @@ -2517,7 +2517,7 @@ struct GroupedListImpl::value || int64_t offset = 0; for (size_t i = 0; i < values.size(); i++) { if (bit_util::GetBit(null_bitmap, i)) { - const util::optional& value = values[i]; + const std::optional& value = values[i]; DCHECK(value.has_value()); std::memcpy(data->mutable_data() + offset, value->data(), slot_width); } else { @@ -2534,7 +2534,7 @@ struct GroupedListImpl::value || ExecContext* ctx_; Allocator allocator_; int64_t num_groups_, num_args_ = 0; - std::vector> values_; + std::vector> values_; TypedBufferBuilder groups_; TypedBufferBuilder values_bitmap_; std::shared_ptr out_type_; diff --git a/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc b/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc index f599f9abb60d5..f4dc74b7c8930 100644 --- a/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc +++ b/cpp/src/arrow/compute/kernels/hash_aggregate_test.cc @@ -131,7 +131,7 @@ Result GroupByUsingExecPlan(const BatchesWithSchema& input, } ARROW_ASSIGN_OR_RAISE(auto plan, ExecPlan::Make(ctx)); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; RETURN_NOT_OK( Declaration::Sequence( { @@ -152,7 +152,7 @@ Result GroupByUsingExecPlan(const BatchesWithSchema& input, .Then([collected_fut]() -> Result> { ARROW_ASSIGN_OR_RAISE(auto collected, collected_fut.result()); return ::arrow::internal::MapVector( - [](util::optional batch) { return std::move(*batch); }, + [](std::optional batch) { return std::move(*batch); }, std::move(collected)); }); diff --git a/cpp/src/arrow/compute/kernels/scalar_cast_string.cc b/cpp/src/arrow/compute/kernels/scalar_cast_string.cc index 6b21a53239242..7a77b63e37a73 100644 --- a/cpp/src/arrow/compute/kernels/scalar_cast_string.cc +++ b/cpp/src/arrow/compute/kernels/scalar_cast_string.cc @@ -16,6 +16,7 @@ // under the License. #include +#include #include "arrow/array/array_base.h" #include "arrow/array/builder_binary.h" @@ -26,7 +27,6 @@ #include "arrow/result.h" #include "arrow/util/formatting.h" #include "arrow/util/int_util.h" -#include "arrow/util/optional.h" #include "arrow/util/utf8_internal.h" #include "arrow/visit_data_inline.h" diff --git a/cpp/src/arrow/compute/kernels/scalar_compare.cc b/cpp/src/arrow/compute/kernels/scalar_compare.cc index cfe108553147c..290a0e5df66a8 100644 --- a/cpp/src/arrow/compute/kernels/scalar_compare.cc +++ b/cpp/src/arrow/compute/kernels/scalar_compare.cc @@ -18,12 +18,12 @@ #include #include #include +#include #include "arrow/compute/api_scalar.h" #include "arrow/compute/kernels/common.h" #include "arrow/util/bit_util.h" #include "arrow/util/bitmap_ops.h" -#include "arrow/util/optional.h" namespace arrow { @@ -640,7 +640,7 @@ struct BinaryScalarMinMax { RETURN_NOT_OK(builder.ReserveData(estimated_final_size)); for (int64_t row = 0; row < batch.length; row++) { - util::optional result; + std::optional result; auto visit_value = [&](string_view value) { result = !result ? value : Op::Call(*result, value); }; @@ -651,7 +651,7 @@ struct BinaryScalarMinMax { if (scalar.is_valid) { visit_value(UnboxScalar::Unbox(scalar)); } else if (!options.skip_nulls) { - result = util::nullopt; + result = std::nullopt; break; } } else { @@ -664,7 +664,7 @@ struct BinaryScalarMinMax { visit_value( string_view(reinterpret_cast(data + offsets[row]), length)); } else if (!options.skip_nulls) { - result = util::nullopt; + result = std::nullopt; break; } } diff --git a/cpp/src/arrow/compute/kernels/scalar_if_else.cc b/cpp/src/arrow/compute/kernels/scalar_if_else.cc index 672a8b2797766..8c941934a1eae 100644 --- a/cpp/src/arrow/compute/kernels/scalar_if_else.cc +++ b/cpp/src/arrow/compute/kernels/scalar_if_else.cc @@ -67,7 +67,7 @@ Status CheckIdenticalTypes(const ExecValue* begin, int count) { constexpr uint64_t kAllNull = 0; constexpr uint64_t kAllValid = ~kAllNull; -util::optional GetConstantValidityWord(const ExecValue& data) { +std::optional GetConstantValidityWord(const ExecValue& data) { if (data.is_scalar()) { return data.scalar->is_valid ? kAllValid : kAllNull; } @@ -91,7 +91,7 @@ struct IfElseNullPromoter { enum { COND_CONST = 1, LEFT_CONST = 2, RIGHT_CONST = 4 }; int64_t constant_validity_flag; - util::optional cond_const, left_const, right_const; + std::optional cond_const, left_const, right_const; Bitmap cond_data, cond_valid, left_valid, right_valid; IfElseNullPromoter(KernelContext* ctx, const ExecValue& cond_d, const ExecValue& left_d, diff --git a/cpp/src/arrow/compute/kernels/vector_replace_test.cc b/cpp/src/arrow/compute/kernels/vector_replace_test.cc index 589952ba700b6..b83b6973313c9 100644 --- a/cpp/src/arrow/compute/kernels/vector_replace_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_replace_test.cc @@ -419,7 +419,7 @@ TYPED_TEST(TestReplaceNumeric, ReplaceWithMaskRandom) { rand.ArrayOf(boolean(), length, /*null_probability=*/0.01)); const int64_t num_replacements = std::count_if( mask->begin(), mask->end(), - [](util::optional value) { return value.has_value() && *value; }); + [](std::optional value) { return value.has_value() && *value; }); auto replacements = checked_pointer_cast( rand.ArrayOf(*field("a", ty, options), num_replacements)); auto expected = this->NaiveImpl(*array, *mask, *replacements); @@ -1045,7 +1045,7 @@ TYPED_TEST(TestReplaceBinary, ReplaceWithMaskRandom) { rand.ArrayOf(boolean(), length, /*null_probability=*/0.01)); const int64_t num_replacements = std::count_if( mask->begin(), mask->end(), - [](util::optional value) { return value.has_value() && *value; }); + [](std::optional value) { return value.has_value() && *value; }); auto replacements = checked_pointer_cast( rand.ArrayOf(*field("a", ty, options), num_replacements)); auto expected = this->NaiveImpl(*array, *mask, *replacements); diff --git a/cpp/src/arrow/compute/kernels/vector_sort.cc b/cpp/src/arrow/compute/kernels/vector_sort.cc index 28307ecca37a7..94c80b9f80ddd 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,6 @@ #include "arrow/table.h" #include "arrow/type_traits.h" #include "arrow/util/checked_cast.h" -#include "arrow/util/optional.h" #include "arrow/visit_type_inline.h" #include "arrow/visitor.h" diff --git a/cpp/src/arrow/config.cc b/cpp/src/arrow/config.cc index a93a8feae1d16..9e32e5437325f 100644 --- a/cpp/src/arrow/config.cc +++ b/cpp/src/arrow/config.cc @@ -63,7 +63,7 @@ std::string MakeSimdLevelString(QueryFlagFunction&& query_flag) { } } -util::optional timezone_db_path; +std::optional timezone_db_path; }; // namespace @@ -80,7 +80,7 @@ RuntimeInfo GetRuntimeInfo() { #if !USE_OS_TZDB info.timezone_db_path = timezone_db_path; #else - info.timezone_db_path = util::optional(); + info.timezone_db_path = std::optional(); #endif return info; } diff --git a/cpp/src/arrow/config.h b/cpp/src/arrow/config.h index 87e31cc456ad6..617d6c268b55e 100644 --- a/cpp/src/arrow/config.h +++ b/cpp/src/arrow/config.h @@ -17,11 +17,11 @@ #pragma once +#include #include #include "arrow/status.h" #include "arrow/util/config.h" // IWYU pragma: export -#include "arrow/util/optional.h" #include "arrow/util/visibility.h" namespace arrow { @@ -70,7 +70,7 @@ struct RuntimeInfo { bool using_os_timezone_db; /// The path to the timezone database; by default None. - util::optional timezone_db_path; + std::optional timezone_db_path; }; /// \brief Get runtime build info. @@ -89,7 +89,7 @@ RuntimeInfo GetRuntimeInfo(); struct GlobalOptions { /// Path to text timezone database. This is only configurable on Windows, /// which does not have a compatible OS timezone database. - util::optional timezone_db_path; + std::optional timezone_db_path; }; ARROW_EXPORT diff --git a/cpp/src/arrow/csv/reader.cc b/cpp/src/arrow/csv/reader.cc index ba754399b75d7..d770fa734f561 100644 --- a/cpp/src/arrow/csv/reader.cc +++ b/cpp/src/arrow/csv/reader.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #include "arrow/util/iterator.h" #include "arrow/util/logging.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" #include "arrow/util/task_group.h" #include "arrow/util/thread_pool.h" #include "arrow/util/utf8_internal.h" @@ -166,7 +166,7 @@ namespace { // This is a callable that can be used to transform an iterator. The source iterator // will contain buffers of data and the output iterator will contain delimited CSV -// blocks. util::optional is used so that there is an end token (required by the +// blocks. std::optional is used so that there is an end token (required by the // iterator APIs (e.g. Visit)) even though an empty optional is never used in this code. class BlockReader { public: @@ -1212,8 +1212,8 @@ class CSVRowCounter : public ReaderMixin, // count_cb must return a value instead of Status/Future<> to work with // MakeMappedGenerator, and it must use a type with a valid end value to work with // IterationEnd. - std::function>(const CSVBlock&)> count_cb = - [self](const CSVBlock& maybe_block) -> Result> { + std::function>(const CSVBlock&)> count_cb = + [self](const CSVBlock& maybe_block) -> Result> { ARROW_ASSIGN_OR_RAISE( auto parser, self->Parse(maybe_block.partial, maybe_block.completion, maybe_block.buffer, diff --git a/cpp/src/arrow/csv/writer_test.cc b/cpp/src/arrow/csv/writer_test.cc index c7f9433688cd2..d8f13bdbbe661 100644 --- a/cpp/src/arrow/csv/writer_test.cc +++ b/cpp/src/arrow/csv/writer_test.cc @@ -18,6 +18,7 @@ #include "gtest/gtest.h" #include +#include #include #include @@ -31,14 +32,13 @@ #include "arrow/testing/matchers.h" #include "arrow/type.h" #include "arrow/type_fwd.h" -#include "arrow/util/optional.h" namespace arrow { namespace csv { struct WriterTestParams { WriterTestParams(std::shared_ptr schema, std::string batch_data, - WriteOptions options, util::optional expected_output, + WriteOptions options, std::optional expected_output, Status expected_status = Status::OK()) : schema(std::move(schema)), batch_data(std::move(batch_data)), @@ -48,7 +48,7 @@ struct WriterTestParams { std::shared_ptr schema; std::string batch_data; WriteOptions options; - util::optional expected_output; + std::optional expected_output; Status expected_status; }; diff --git a/cpp/src/arrow/dataset/dataset.cc b/cpp/src/arrow/dataset/dataset.cc index 1e4c9b7f719bb..6faaa953bb3fb 100644 --- a/cpp/src/arrow/dataset/dataset.cc +++ b/cpp/src/arrow/dataset/dataset.cc @@ -55,9 +55,9 @@ Result> Fragment::ReadPhysicalSchema() { return physical_schema_; } -Future> Fragment::CountRows(compute::Expression, - const std::shared_ptr&) { - return Future>::MakeFinished(util::nullopt); +Future> Fragment::CountRows(compute::Expression, + const std::shared_ptr&) { + return Future>::MakeFinished(std::nullopt); } Result> InMemoryFragment::ReadPhysicalSchemaImpl() { @@ -129,16 +129,16 @@ Result InMemoryFragment::ScanBatchesAsync( options->batch_size); } -Future> InMemoryFragment::CountRows( +Future> InMemoryFragment::CountRows( compute::Expression predicate, const std::shared_ptr& options) { if (ExpressionHasFieldRefs(predicate)) { - return Future>::MakeFinished(util::nullopt); + return Future>::MakeFinished(std::nullopt); } int64_t total = 0; for (const auto& batch : record_batches_) { total += batch->num_rows(); } - return Future>::MakeFinished(total); + return Future>::MakeFinished(total); } Dataset::Dataset(std::shared_ptr schema, compute::Expression partition_expression) diff --git a/cpp/src/arrow/dataset/dataset.h b/cpp/src/arrow/dataset/dataset.h index 9f4fee52154a9..62181b60ba423 100644 --- a/cpp/src/arrow/dataset/dataset.h +++ b/cpp/src/arrow/dataset/dataset.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "arrow/dataset/visibility.h" #include "arrow/util/macros.h" #include "arrow/util/mutex.h" -#include "arrow/util/optional.h" namespace arrow { namespace dataset { @@ -64,7 +64,7 @@ class ARROW_DS_EXPORT Fragment : public std::enable_shared_from_this { /// /// If this is not possible, resolve with an empty optional. The fragment can perform /// I/O (e.g. to read metadata) before it deciding whether it can satisfy the request. - virtual Future> CountRows( + virtual Future> CountRows( compute::Expression predicate, const std::shared_ptr& options); virtual std::string type_name() const = 0; @@ -120,7 +120,7 @@ class ARROW_DS_EXPORT InMemoryFragment : public Fragment { Result ScanBatchesAsync( const std::shared_ptr& options) override; - Future> CountRows( + Future> CountRows( compute::Expression predicate, const std::shared_ptr& options) override; diff --git a/cpp/src/arrow/dataset/dataset_test.cc b/cpp/src/arrow/dataset/dataset_test.cc index 35b6e8129e2aa..cb155d7b962fd 100644 --- a/cpp/src/arrow/dataset/dataset_test.cc +++ b/cpp/src/arrow/dataset/dataset_test.cc @@ -17,6 +17,8 @@ #include "arrow/dataset/dataset.h" +#include + #include "arrow/dataset/dataset_internal.h" #include "arrow/dataset/discovery.h" #include "arrow/dataset/partition.h" @@ -24,7 +26,6 @@ #include "arrow/filesystem/mockfs.h" #include "arrow/stl.h" #include "arrow/testing/generator.h" -#include "arrow/util/optional.h" namespace arrow { namespace dataset { @@ -485,7 +486,7 @@ inline std::shared_ptr SchemaFromNames(const std::vector na class TestSchemaUnification : public TestUnionDataset { public: - using i32 = util::optional; + using i32 = std::optional; using PathAndContent = std::vector>; void SetUp() override { @@ -595,7 +596,7 @@ class TestSchemaUnification : public TestUnionDataset { std::shared_ptr dataset_; }; -using util::nullopt; +using std::nullopt; TEST_F(TestSchemaUnification, SelectStar) { // This is a `SELECT * FROM dataset` where it ensures: diff --git a/cpp/src/arrow/dataset/dataset_writer_test.cc b/cpp/src/arrow/dataset/dataset_writer_test.cc index f4e7344cdb2f1..edc9bc8bbc13d 100644 --- a/cpp/src/arrow/dataset/dataset_writer_test.cc +++ b/cpp/src/arrow/dataset/dataset_writer_test.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "arrow/array/builder_primitive.h" @@ -30,7 +31,6 @@ #include "arrow/table.h" #include "arrow/testing/future_util.h" #include "arrow/testing/gtest_util.h" -#include "arrow/util/optional.h" #include "gtest/gtest.h" namespace arrow { @@ -114,13 +114,13 @@ class DatasetWriterTestFixture : public testing::Test { return batch; } - util::optional FindFile(const std::string& filename) { + std::optional FindFile(const std::string& filename) { for (const auto& mock_file : filesystem_->AllFiles()) { if (mock_file.full_path == filename) { return mock_file; } } - return util::nullopt; + return std::nullopt; } void AssertVisited(const std::vector& actual_paths, @@ -150,7 +150,7 @@ class DatasetWriterTestFixture : public testing::Test { return batch; } - void AssertFileCreated(const util::optional& maybe_file, + void AssertFileCreated(const std::optional& maybe_file, const std::string& expected_filename) { ASSERT_TRUE(maybe_file.has_value()) << "The file " << expected_filename << " was not created"; @@ -167,7 +167,7 @@ class DatasetWriterTestFixture : public testing::Test { void AssertCreatedData(const std::vector& expected_files) { counter_ = 0; for (const auto& expected_file : expected_files) { - util::optional written_file = FindFile(expected_file.filename); + std::optional written_file = FindFile(expected_file.filename); AssertFileCreated(written_file, expected_file.filename); int num_batches = 0; AssertBatchesEqual(*MakeBatch(expected_file.start, expected_file.num_rows), @@ -178,21 +178,21 @@ class DatasetWriterTestFixture : public testing::Test { void AssertFilesCreated(const std::vector& expected_files) { for (const std::string& expected_file : expected_files) { - util::optional written_file = FindFile(expected_file); + std::optional written_file = FindFile(expected_file); AssertFileCreated(written_file, expected_file); } } void AssertNotFiles(const std::vector& expected_non_files) { for (const auto& expected_non_file : expected_non_files) { - util::optional file = FindFile(expected_non_file); + std::optional file = FindFile(expected_non_file); ASSERT_FALSE(file.has_value()); } } void AssertEmptyFiles(const std::vector& expected_empty_files) { for (const auto& expected_empty_file : expected_empty_files) { - util::optional file = FindFile(expected_empty_file); + std::optional file = FindFile(expected_empty_file); ASSERT_TRUE(file.has_value()); ASSERT_EQ("", file->data); } diff --git a/cpp/src/arrow/dataset/file_base.cc b/cpp/src/arrow/dataset/file_base.cc index 81bf10abe3039..64daf08fd0317 100644 --- a/cpp/src/arrow/dataset/file_base.cc +++ b/cpp/src/arrow/dataset/file_base.cc @@ -65,7 +65,7 @@ Result> FileSource::Open() const { } Result> FileSource::OpenCompressed( - util::optional compression) const { + std::optional compression) const { ARROW_ASSIGN_OR_RAISE(auto file, Open()); auto actual_compression = Compression::type::UNCOMPRESSED; if (!compression.has_value()) { @@ -100,10 +100,10 @@ bool FileSource::Equals(const FileSource& other) const { compression_ == other.compression_; } -Future> FileFormat::CountRows( +Future> FileFormat::CountRows( const std::shared_ptr&, compute::Expression, const std::shared_ptr&) { - return Future>::MakeFinished(util::nullopt); + return Future>::MakeFinished(std::nullopt); } Result> FileFormat::MakeFragment( @@ -135,12 +135,12 @@ Result FileFragment::ScanBatchesAsync( return format_->ScanBatchesAsync(options, self); } -Future> FileFragment::CountRows( +Future> FileFragment::CountRows( compute::Expression predicate, const std::shared_ptr& options) { ARROW_ASSIGN_OR_RAISE(predicate, compute::SimplifyWithGuarantee(std::move(predicate), partition_expression_)); if (!predicate.IsSatisfiable()) { - return Future>::MakeFinished(0); + return Future>::MakeFinished(0); } auto self = checked_pointer_cast(shared_from_this()); return format()->CountRows(self, std::move(predicate), options); diff --git a/cpp/src/arrow/dataset/file_base.h b/cpp/src/arrow/dataset/file_base.h index 7b0f5ffcf2eaa..586c58b3f521c 100644 --- a/cpp/src/arrow/dataset/file_base.h +++ b/cpp/src/arrow/dataset/file_base.h @@ -112,7 +112,7 @@ class ARROW_DS_EXPORT FileSource : public util::EqualityComparable { /// \param[in] compression If nullopt, guess the compression scheme from the /// filename, else decompress with the given codec Result> OpenCompressed( - util::optional compression = util::nullopt) const; + std::optional compression = std::nullopt) const; /// \brief equality comparison with another FileSource bool Equals(const FileSource& other) const; @@ -154,7 +154,7 @@ class ARROW_DS_EXPORT FileFormat : public std::enable_shared_from_this& options, const std::shared_ptr& file) const = 0; - virtual Future> CountRows( + virtual Future> CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options); @@ -187,7 +187,7 @@ class ARROW_DS_EXPORT FileFragment : public Fragment, public: Result ScanBatchesAsync( const std::shared_ptr& options) override; - Future> CountRows( + Future> CountRows( compute::Expression predicate, const std::shared_ptr& options) override; @@ -344,7 +344,7 @@ class ARROW_DS_EXPORT FileWriter { std::shared_ptr options_; std::shared_ptr destination_; fs::FileLocator destination_locator_; - util::optional bytes_written_; + std::optional bytes_written_; }; /// \brief Options for writing a dataset. diff --git a/cpp/src/arrow/dataset/file_csv.cc b/cpp/src/arrow/dataset/file_csv.cc index 4cb331b0afc2a..bfc710105ed4a 100644 --- a/cpp/src/arrow/dataset/file_csv.cc +++ b/cpp/src/arrow/dataset/file_csv.cc @@ -290,11 +290,11 @@ Result CsvFileFormat::ScanBatchesAsync( return generator; } -Future> CsvFileFormat::CountRows( +Future> CsvFileFormat::CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) { if (ExpressionHasFieldRefs(predicate)) { - return Future>::MakeFinished(util::nullopt); + return Future>::MakeFinished(std::nullopt); } auto self = checked_pointer_cast(shared_from_this()); ARROW_ASSIGN_OR_RAISE( @@ -309,7 +309,7 @@ Future> CsvFileFormat::CountRows( return csv::CountRowsAsync(options->io_context, std::move(input), ::arrow::internal::GetCpuThreadPool(), read_options, self->parse_options) - .Then([](int64_t count) { return util::make_optional(count); }); + .Then([](int64_t count) { return std::make_optional(count); }); } // diff --git a/cpp/src/arrow/dataset/file_csv.h b/cpp/src/arrow/dataset/file_csv.h index e58ed87b42720..a3d214ef49406 100644 --- a/cpp/src/arrow/dataset/file_csv.h +++ b/cpp/src/arrow/dataset/file_csv.h @@ -57,7 +57,7 @@ class ARROW_DS_EXPORT CsvFileFormat : public FileFormat { const std::shared_ptr& scan_options, const std::shared_ptr& file) const override; - Future> CountRows( + Future> CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) override; diff --git a/cpp/src/arrow/dataset/file_ipc.cc b/cpp/src/arrow/dataset/file_ipc.cc index 7c45a5d705692..2650db499ceff 100644 --- a/cpp/src/arrow/dataset/file_ipc.cc +++ b/cpp/src/arrow/dataset/file_ipc.cc @@ -175,15 +175,15 @@ Result IpcFileFormat::ScanBatchesAsync( return MakeFromFuture(open_reader.Then(reopen_reader).Then(open_generator)); } -Future> IpcFileFormat::CountRows( +Future> IpcFileFormat::CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) { if (ExpressionHasFieldRefs(predicate)) { - return Future>::MakeFinished(util::nullopt); + return Future>::MakeFinished(std::nullopt); } auto self = checked_pointer_cast(shared_from_this()); return DeferNotOk(options->io_context.executor()->Submit( - [self, file]() -> Result> { + [self, file]() -> Result> { ARROW_ASSIGN_OR_RAISE(auto reader, OpenReader(file->source())); return reader->CountRows(); })); diff --git a/cpp/src/arrow/dataset/file_ipc.h b/cpp/src/arrow/dataset/file_ipc.h index 6dc40da1faca4..8b97046271bfd 100644 --- a/cpp/src/arrow/dataset/file_ipc.h +++ b/cpp/src/arrow/dataset/file_ipc.h @@ -56,7 +56,7 @@ class ARROW_DS_EXPORT IpcFileFormat : public FileFormat { const std::shared_ptr& options, const std::shared_ptr& file) const override; - Future> CountRows( + Future> CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) override; diff --git a/cpp/src/arrow/dataset/file_orc.cc b/cpp/src/arrow/dataset/file_orc.cc index 49102f3deae73..cf04e5e74844b 100644 --- a/cpp/src/arrow/dataset/file_orc.cc +++ b/cpp/src/arrow/dataset/file_orc.cc @@ -196,15 +196,15 @@ Result OrcFileFormat::ScanBatchesAsync( return iter_to_gen; } -Future> OrcFileFormat::CountRows( +Future> OrcFileFormat::CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) { if (ExpressionHasFieldRefs(predicate)) { - return Future>::MakeFinished(util::nullopt); + return Future>::MakeFinished(std::nullopt); } auto self = checked_pointer_cast(shared_from_this()); return DeferNotOk(options->io_context.executor()->Submit( - [self, file]() -> Result> { + [self, file]() -> Result> { ARROW_ASSIGN_OR_RAISE(auto reader, OpenORCReader(file->source())); return reader->NumberOfRows(); })); diff --git a/cpp/src/arrow/dataset/file_orc.h b/cpp/src/arrow/dataset/file_orc.h index 5bbe4df24ad0b..cbfb83670cb2f 100644 --- a/cpp/src/arrow/dataset/file_orc.h +++ b/cpp/src/arrow/dataset/file_orc.h @@ -55,7 +55,7 @@ class ARROW_DS_EXPORT OrcFileFormat : public FileFormat { const std::shared_ptr& options, const std::shared_ptr& file) const override; - Future> CountRows( + Future> CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) override; diff --git a/cpp/src/arrow/dataset/file_parquet.cc b/cpp/src/arrow/dataset/file_parquet.cc index 0d95e18171b79..f07254e1115e4 100644 --- a/cpp/src/arrow/dataset/file_parquet.cc +++ b/cpp/src/arrow/dataset/file_parquet.cc @@ -98,7 +98,7 @@ Result> GetSchemaManifest( return manifest; } -util::optional ColumnChunkStatisticsAsExpression( +std::optional ColumnChunkStatisticsAsExpression( const SchemaField& schema_field, const parquet::RowGroupMetaData& metadata) { // For the remaining of this function, failure to extract/parse statistics // are ignored by returning nullptr. The goal is two fold. First @@ -107,13 +107,13 @@ util::optional ColumnChunkStatisticsAsExpression( // For now, only leaf (primitive) types are supported. if (!schema_field.is_leaf()) { - return util::nullopt; + return std::nullopt; } auto column_metadata = metadata.ColumnChunk(schema_field.column_index); auto statistics = column_metadata->statistics(); if (statistics == nullptr) { - return util::nullopt; + return std::nullopt; } const auto& field = schema_field.field; @@ -126,7 +126,7 @@ util::optional ColumnChunkStatisticsAsExpression( std::shared_ptr min, max; if (!StatisticsAsScalars(*statistics, &min, &max).ok()) { - return util::nullopt; + return std::nullopt; } auto maybe_min = min->CastTo(field->type()); @@ -155,7 +155,7 @@ util::optional ColumnChunkStatisticsAsExpression( return in_range; } - return util::nullopt; + return std::nullopt; } void AddColumnIndices(const SchemaField& schema_field, @@ -482,17 +482,17 @@ Result ParquetFileFormat::ScanBatchesAsync( return generator; } -Future> ParquetFileFormat::CountRows( +Future> ParquetFileFormat::CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) { auto parquet_file = checked_pointer_cast(file); if (parquet_file->metadata()) { ARROW_ASSIGN_OR_RAISE(auto maybe_count, parquet_file->TryCountRows(std::move(predicate))); - return Future>::MakeFinished(maybe_count); + return Future>::MakeFinished(maybe_count); } else { return DeferNotOk(options->io_context.executor()->Submit( - [parquet_file, predicate]() -> Result> { + [parquet_file, predicate]() -> Result> { RETURN_NOT_OK(parquet_file->EnsureCompleteMetadata()); return parquet_file->TryCountRows(predicate); })); @@ -512,7 +512,7 @@ Result> ParquetFileFormat::MakeFragment( std::shared_ptr physical_schema) { return std::shared_ptr(new ParquetFileFragment( std::move(source), shared_from_this(), std::move(partition_expression), - std::move(physical_schema), util::nullopt)); + std::move(physical_schema), std::nullopt)); } // @@ -573,7 +573,7 @@ ParquetFileFragment::ParquetFileFragment(FileSource source, std::shared_ptr format, compute::Expression partition_expression, std::shared_ptr physical_schema, - util::optional> row_groups) + std::optional> row_groups) : FileFragment(std::move(source), std::move(format), std::move(partition_expression), std::move(physical_schema)), parquet_format_(checked_cast(*format_)), @@ -738,7 +738,7 @@ Result> ParquetFileFragment::TestRowGroups( return row_groups; } -Result> ParquetFileFragment::TryCountRows( +Result> ParquetFileFragment::TryCountRows( compute::Expression predicate) { DCHECK_NE(metadata_, nullptr); if (ExpressionHasFieldRefs(predicate)) { @@ -757,7 +757,7 @@ Result> ParquetFileFragment::TryCountRows( // If the row group is entirely excluded, exclude it from the row count if (!expressions[i].IsSatisfiable()) continue; // Unless the row group is entirely included, bail out of fast path - if (expressions[i] != compute::literal(true)) return util::nullopt; + if (expressions[i] != compute::literal(true)) return std::nullopt; BEGIN_PARQUET_CATCH_EXCEPTIONS rows += metadata()->RowGroup((*row_groups_)[i])->num_rows(); END_PARQUET_CATCH_EXCEPTIONS diff --git a/cpp/src/arrow/dataset/file_parquet.h b/cpp/src/arrow/dataset/file_parquet.h index 6167c2894f65a..05c02940d3555 100644 --- a/cpp/src/arrow/dataset/file_parquet.h +++ b/cpp/src/arrow/dataset/file_parquet.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "arrow/dataset/type_fwd.h" #include "arrow/dataset/visibility.h" #include "arrow/io/caching.h" -#include "arrow/util/optional.h" namespace parquet { class ParquetFileReader; @@ -99,7 +99,7 @@ class ARROW_DS_EXPORT ParquetFileFormat : public FileFormat { const std::shared_ptr& options, const std::shared_ptr& file) const override; - Future> CountRows( + Future> CountRows( const std::shared_ptr& file, compute::Expression predicate, const std::shared_ptr& options) override; @@ -167,7 +167,7 @@ class ARROW_DS_EXPORT ParquetFileFragment : public FileFragment { ParquetFileFragment(FileSource source, std::shared_ptr format, compute::Expression partition_expression, std::shared_ptr physical_schema, - util::optional> row_groups); + std::optional> row_groups); Status SetMetadata(std::shared_ptr metadata, std::shared_ptr manifest); @@ -185,13 +185,13 @@ class ARROW_DS_EXPORT ParquetFileFragment : public FileFragment { /// Try to count rows matching the predicate using metadata. Expects /// metadata to be present, and expects the predicate to have been /// simplified against the partition expression already. - Result> TryCountRows(compute::Expression predicate); + Result> TryCountRows(compute::Expression predicate); ParquetFileFormat& parquet_format_; /// Indices of row groups selected by this fragment, - /// or util::nullopt if all row groups are selected. - util::optional> row_groups_; + /// or std::nullopt if all row groups are selected. + std::optional> row_groups_; std::vector statistics_expressions_; std::vector statistics_expressions_complete_; diff --git a/cpp/src/arrow/dataset/file_parquet_test.cc b/cpp/src/arrow/dataset/file_parquet_test.cc index de048855cf21a..a2a15762a58d6 100644 --- a/cpp/src/arrow/dataset/file_parquet_test.cc +++ b/cpp/src/arrow/dataset/file_parquet_test.cc @@ -231,7 +231,7 @@ TEST_F(TestParquetFileFormat, CountRowsPredicatePushdown) { auto fragment = MakeFragment(*source); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(kTotalNumRows), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(kTotalNumRows), fragment->CountRows(literal(true), options)); for (int i = 1; i <= kNumRowGroups; i++) { @@ -240,18 +240,18 @@ TEST_F(TestParquetFileFormat, CountRowsPredicatePushdown) { auto predicate = less_equal(field_ref("i64"), literal(i)); ASSERT_OK_AND_ASSIGN(predicate, predicate.Bind(*reader->schema())); auto expected = i * (i + 1) / 2; - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(expected), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(expected), fragment->CountRows(predicate, options)); predicate = and_(less_equal(field_ref("i64"), literal(i)), greater_equal(field_ref("i64"), literal(i))); ASSERT_OK_AND_ASSIGN(predicate, predicate.Bind(*reader->schema())); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(i), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(i), fragment->CountRows(predicate, options)); predicate = equal(field_ref("i64"), literal(i)); ASSERT_OK_AND_ASSIGN(predicate, predicate.Bind(*reader->schema())); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(i), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(i), fragment->CountRows(predicate, options)); } @@ -278,15 +278,15 @@ TEST_F(TestParquetFileFormat, CountRowsPredicatePushdown) { ASSERT_OK_AND_ASSIGN( auto predicate, greater_equal(field_ref("i64"), literal(1)).Bind(*dataset_schema)); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(4), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(4), fragment->CountRows(predicate, options)); ASSERT_OK_AND_ASSIGN(predicate, is_null(field_ref("i64")).Bind(*dataset_schema)); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(3), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(3), fragment->CountRows(predicate, options)); ASSERT_OK_AND_ASSIGN(predicate, is_valid(field_ref("i64")).Bind(*dataset_schema)); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(4), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(4), fragment->CountRows(predicate, options)); } } diff --git a/cpp/src/arrow/dataset/file_test.cc b/cpp/src/arrow/dataset/file_test.cc index 4dfc6bc584d13..6d866c196b392 100644 --- a/cpp/src/arrow/dataset/file_test.cc +++ b/cpp/src/arrow/dataset/file_test.cc @@ -351,7 +351,7 @@ TEST_F(TestFileSystemDataset, WriteProjected) { class FileSystemWriteTest : public testing::TestWithParam> { using PlanFactory = std::function( const FileSystemDatasetWriteOptions&, - std::function>()>*)>; + std::function>()>*)>; protected: bool IsParallel() { return std::get<0>(GetParam()); } @@ -379,7 +379,7 @@ class FileSystemWriteTest : public testing::TestWithParam "[[5, null], [6, false], [7, false]]")}; source_data.schema = schema({field("i32", int32()), field("bool", boolean())}); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(auto plan, cp::ExecPlan::Make()); auto source_decl = cp::Declaration::Sequence( @@ -422,7 +422,7 @@ class FileSystemWriteTest : public testing::TestWithParam TEST_P(FileSystemWriteTest, Write) { auto plan_factory = [](const FileSystemDatasetWriteOptions& write_options, - std::function>()>* sink_gen) { + std::function>()>* sink_gen) { return std::vector{{"write", WriteNodeOptions{write_options}}}; }; TestDatasetWriteRoundTrip(plan_factory, /*has_output=*/false); @@ -431,7 +431,7 @@ TEST_P(FileSystemWriteTest, Write) { TEST_P(FileSystemWriteTest, TeeWrite) { auto plan_factory = [](const FileSystemDatasetWriteOptions& write_options, - std::function>()>* sink_gen) { + std::function>()>* sink_gen) { return std::vector{ {"tee", WriteNodeOptions{write_options}}, {"sink", cp::SinkNodeOptions{sink_gen}}, diff --git a/cpp/src/arrow/dataset/partition.cc b/cpp/src/arrow/dataset/partition.cc index 26abc10e6b81a..a9744d0aabf04 100644 --- a/cpp/src/arrow/dataset/partition.cc +++ b/cpp/src/arrow/dataset/partition.cc @@ -330,12 +330,12 @@ Result KeyValuePartitioning::Format( return FormatValues(values); } -inline util::optional NextValid(const ScalarVector& values, int first_null) { +inline std::optional NextValid(const ScalarVector& values, int first_null) { auto it = std::find_if(values.begin() + first_null + 1, values.end(), [](const std::shared_ptr& v) { return v != nullptr; }); if (it == values.end()) { - return util::nullopt; + return std::nullopt; } return static_cast(it - values.begin()); @@ -473,7 +473,7 @@ class KeyValuePartitioningFactory : public PartitioningFactory { return it_inserted.first->second; } - Status InsertRepr(const std::string& name, util::optional repr) { + Status InsertRepr(const std::string& name, std::optional repr) { auto field_index = GetOrInsertField(name); if (repr.has_value()) { return InsertRepr(field_index, *repr); @@ -715,12 +715,12 @@ bool FilenamePartitioning::Equals(const Partitioning& other) const { return KeyValuePartitioning::Equals(other); } -Result> HivePartitioning::ParseKey( +Result> HivePartitioning::ParseKey( const std::string& segment, const HivePartitioningOptions& options) { auto name_end = string_view(segment).find_first_of('='); // Not round-trippable if (name_end == string_view::npos) { - return util::nullopt; + return std::nullopt; } // Static method, so we have no better place for it @@ -750,7 +750,7 @@ Result> HivePartitioning::ParseKey( } if (value == options.null_fallback) { - return Key{std::move(name), util::nullopt}; + return Key{std::move(name), std::nullopt}; } return Key{std::move(name), std::move(value)}; } diff --git a/cpp/src/arrow/dataset/partition.h b/cpp/src/arrow/dataset/partition.h index 2d8c8bb274687..faee0c676e24d 100644 --- a/cpp/src/arrow/dataset/partition.h +++ b/cpp/src/arrow/dataset/partition.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include "arrow/dataset/type_fwd.h" #include "arrow/dataset/visibility.h" #include "arrow/util/compare.h" -#include "arrow/util/optional.h" namespace arrow { @@ -174,7 +174,7 @@ class ARROW_DS_EXPORT KeyValuePartitioning : public Partitioning { /// of a scalar value struct Key { std::string name; - util::optional value; + std::optional value; }; Result Partition( @@ -289,8 +289,8 @@ class ARROW_DS_EXPORT HivePartitioning : public KeyValuePartitioning { std::string null_fallback() const { return hive_options_.null_fallback; } const HivePartitioningOptions& options() const { return hive_options_; } - static Result> ParseKey(const std::string& segment, - const HivePartitioningOptions& options); + static Result> ParseKey(const std::string& segment, + const HivePartitioningOptions& options); bool Equals(const Partitioning& other) const override; diff --git a/cpp/src/arrow/dataset/scanner.cc b/cpp/src/arrow/dataset/scanner.cc index badd18bf31867..eb09a986c97f4 100644 --- a/cpp/src/arrow/dataset/scanner.cc +++ b/cpp/src/arrow/dataset/scanner.cc @@ -334,7 +334,7 @@ Result AsyncScanner::ScanBatchesUnorderedAsync( } Result ToEnumeratedRecordBatch( - const util::optional& batch, const ScanOptions& options, + const std::optional& batch, const ScanOptions& options, const FragmentVector& fragments) { int num_fields = options.projected_schema->num_fields(); @@ -363,7 +363,7 @@ Result AsyncScanner::ScanBatchesUnorderedAsync( ARROW_ASSIGN_OR_RAISE(auto plan, compute::ExecPlan::Make(exec_context.get())); plan->SetUseLegacyBatching(use_legacy_batching); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; auto exprs = scan_options_->projection.call()->arguments; auto names = checked_cast( @@ -402,7 +402,7 @@ Result AsyncScanner::ScanBatchesUnorderedAsync( return MakeMappedGenerator( std::move(sink_gen), [sink_gen, options, stop_producing, - shared_fragments](const util::optional& batch) + shared_fragments](const std::optional& batch) -> Future { return ToEnumeratedRecordBatch(batch, *options, *shared_fragments); }); @@ -655,7 +655,7 @@ Result AsyncScanner::CountRows() { fragment_gen = MakeMappedGenerator( std::move(fragment_gen), [&](const std::shared_ptr& fragment) { return fragment->CountRows(options->filter, options) - .Then([&, fragment](util::optional fast_count) mutable + .Then([&, fragment](std::optional fast_count) mutable -> std::shared_ptr { if (fast_count) { // fast path: got row count directly; skip scanning this fragment @@ -669,7 +669,7 @@ Result AsyncScanner::CountRows() { }); }); - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; RETURN_NOT_OK( compute::Declaration::Sequence( @@ -912,7 +912,7 @@ Result MakeScanNode(compute::ExecPlan* plan, auto gen = MakeMappedGenerator( std::move(batch_gen), [scan_options](const EnumeratedRecordBatch& partial) - -> Result> { + -> Result> { // TODO(ARROW-13263) fragments may be able to attach more guarantees to batches // than this, for example parquet's row group stats. Failing to do this leaves // perf on the table because row group stats could be used to skip kernel execs in @@ -924,7 +924,7 @@ Result MakeScanNode(compute::ExecPlan* plan, auto guarantee = partial.fragment.value->partition_expression(); ARROW_ASSIGN_OR_RAISE( - util::optional batch, + std::optional batch, compute::MakeExecBatch(*scan_options->dataset_schema, partial.record_batch.value, guarantee)); @@ -978,7 +978,7 @@ Result MakeOrderedSinkNode(compute::ExecPlan* plan, } auto input = inputs[0]; - AsyncGenerator> unordered; + AsyncGenerator> unordered; ARROW_ASSIGN_OR_RAISE(auto node, compute::MakeExecNode("sink", plan, std::move(inputs), compute::SinkNodeOptions{&unordered})); @@ -1009,8 +1009,8 @@ Result MakeOrderedSinkNode(compute::ExecPlan* plan, return fragment_index(batch) < 0; }; - auto left_after_right = [=](const util::optional& left, - const util::optional& right) { + auto left_after_right = [=](const std::optional& left, + const std::optional& right) { // Before any comes first if (is_before_any(*left)) { return false; @@ -1026,8 +1026,8 @@ Result MakeOrderedSinkNode(compute::ExecPlan* plan, return fragment_index(*left) > fragment_index(*right); }; - auto is_next = [=](const util::optional& prev, - const util::optional& next) { + auto is_next = [=](const std::optional& prev, + const std::optional& next) { // Only true if next is the first batch if (is_before_any(*prev)) { return fragment_index(*next) == 0 && batch_index(*next) == 0; @@ -1044,7 +1044,7 @@ Result MakeOrderedSinkNode(compute::ExecPlan* plan, const auto& sink_options = checked_cast(options); *sink_options.generator = MakeSequencingGenerator(std::move(unordered), left_after_right, is_next, - util::make_optional(std::move(before_any))); + std::make_optional(std::move(before_any))); return node; } diff --git a/cpp/src/arrow/dataset/scanner_benchmark.cc b/cpp/src/arrow/dataset/scanner_benchmark.cc index 6d314d9d9a63a..b0254089a954d 100644 --- a/cpp/src/arrow/dataset/scanner_benchmark.cc +++ b/cpp/src/arrow/dataset/scanner_benchmark.cc @@ -149,7 +149,7 @@ void MinimalEndToEndScan(size_t num_batches, size_t batch_size, bool async_mode) compute::ProjectNodeOptions{{a_times_2}, {}, async_mode})); // finally, pipe the project node into a sink node - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(compute::ExecNode * sink, compute::MakeExecNode("sink", plan.get(), {project}, compute::SinkNodeOptions{&sink_gen})); diff --git a/cpp/src/arrow/dataset/scanner_test.cc b/cpp/src/arrow/dataset/scanner_test.cc index 804e82b57db59..0768014b8626f 100644 --- a/cpp/src/arrow/dataset/scanner_test.cc +++ b/cpp/src/arrow/dataset/scanner_test.cc @@ -481,16 +481,16 @@ class CountRowsOnlyFragment : public InMemoryFragment { public: using InMemoryFragment::InMemoryFragment; - Future> CountRows( - compute::Expression predicate, const std::shared_ptr&) override { + Future> CountRows(compute::Expression predicate, + const std::shared_ptr&) override { if (compute::FieldsInExpression(predicate).size() > 0) { - return Future>::MakeFinished(util::nullopt); + return Future>::MakeFinished(std::nullopt); } int64_t sum = 0; for (const auto& batch : record_batches_) { sum += batch->num_rows(); } - return Future>::MakeFinished(sum); + return Future>::MakeFinished(sum); } Result ScanBatchesAsync( const std::shared_ptr&) override { @@ -502,9 +502,9 @@ class ScanOnlyFragment : public InMemoryFragment { public: using InMemoryFragment::InMemoryFragment; - Future> CountRows( - compute::Expression predicate, const std::shared_ptr&) override { - return Future>::MakeFinished(util::nullopt); + Future> CountRows(compute::Expression predicate, + const std::shared_ptr&) override { + return Future>::MakeFinished(std::nullopt); } Result ScanBatchesAsync( const std::shared_ptr&) override { @@ -532,14 +532,14 @@ class CountFailFragment : public InMemoryFragment { public: explicit CountFailFragment(RecordBatchVector record_batches) : InMemoryFragment(std::move(record_batches)), - count(Future>::Make()) {} + count(Future>::Make()) {} - Future> CountRows( - compute::Expression, const std::shared_ptr&) override { + Future> CountRows(compute::Expression, + const std::shared_ptr&) override { return count; } - Future> count; + Future> count; }; TEST_P(TestScanner, CountRowsFailure) { SetSchema({field("i32", int32()), field("f64", float64())}); @@ -557,7 +557,7 @@ TEST_P(TestScanner, CountRowsFailure) { ASSERT_RAISES(Invalid, scanner->CountRows()); // Fragment 2 doesn't complete until after the count stops - should not break anything // under ASan, etc. - fragment2->count.MarkFinished(util::nullopt); + fragment2->count.MarkFinished(std::nullopt); } TEST_P(TestScanner, CountRowsWithMetadata) { @@ -1358,7 +1358,7 @@ struct TestPlan { .Then([collected_fut]() -> Result> { ARROW_ASSIGN_OR_RAISE(auto collected, collected_fut.result()); return ::arrow::internal::MapVector( - [](util::optional batch) { return std::move(*batch); }, + [](std::optional batch) { return std::move(*batch); }, std::move(collected)); }); } @@ -1366,7 +1366,7 @@ struct TestPlan { compute::ExecPlan* get() { return plan.get(); } std::shared_ptr plan; - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; }; struct DatasetAndBatches { @@ -1763,7 +1763,7 @@ TEST(ScanNode, MinimalEndToEnd) { compute::ProjectNodeOptions{{a_times_2}})); // finally, pipe the project node into a sink node - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(compute::ExecNode * sink, compute::MakeExecNode("ordered_sink", plan.get(), {project}, compute::SinkNodeOptions{&sink_gen})); @@ -1863,7 +1863,7 @@ TEST(ScanNode, MinimalScalarAggEndToEnd) { "sum", nullptr, "a * 2", "sum(a * 2)"}}})); // finally, pipe the aggregate node into a sink node - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(compute::ExecNode * sink, compute::MakeExecNode("sink", plan.get(), {aggregate}, compute::SinkNodeOptions{&sink_gen})); @@ -1953,7 +1953,7 @@ TEST(ScanNode, MinimalGroupedAggEndToEnd) { /*keys=*/{"b"}})); // finally, pipe the aggregate node into a sink node - AsyncGenerator> sink_gen; + AsyncGenerator> sink_gen; ASSERT_OK_AND_ASSIGN(compute::ExecNode * sink, compute::MakeExecNode("sink", plan.get(), {aggregate}, compute::SinkNodeOptions{&sink_gen})); diff --git a/cpp/src/arrow/dataset/test_util.h b/cpp/src/arrow/dataset/test_util.h index 094097451590f..05a9869389604 100644 --- a/cpp/src/arrow/dataset/test_util.h +++ b/cpp/src/arrow/dataset/test_util.h @@ -534,26 +534,26 @@ class FileFormatFixtureMixin : public ::testing::Test { auto source = this->GetFileSource(reader.get()); auto fragment = this->MakeFragment(*source); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(expected_rows()), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(expected_rows()), fragment->CountRows(literal(true), options)); fragment = this->MakeFragment(*source, equal(field_ref("part"), literal(2))); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(expected_rows()), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(expected_rows()), fragment->CountRows(literal(true), options)); auto predicate = equal(field_ref("part"), literal(1)); ASSERT_OK_AND_ASSIGN(predicate, predicate.Bind(*full_schema)); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(0), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(0), fragment->CountRows(predicate, options)); predicate = equal(field_ref("part"), literal(2)); ASSERT_OK_AND_ASSIGN(predicate, predicate.Bind(*full_schema)); - ASSERT_FINISHES_OK_AND_EQ(util::make_optional(expected_rows()), + ASSERT_FINISHES_OK_AND_EQ(std::make_optional(expected_rows()), fragment->CountRows(predicate, options)); predicate = equal(call("add", {field_ref("f64"), literal(3)}), literal(2)); ASSERT_OK_AND_ASSIGN(predicate, predicate.Bind(*full_schema)); - ASSERT_FINISHES_OK_AND_EQ(util::nullopt, fragment->CountRows(predicate, options)); + ASSERT_FINISHES_OK_AND_EQ(std::nullopt, fragment->CountRows(predicate, options)); } void TestFragmentEquals() { auto options = std::make_shared(); diff --git a/cpp/src/arrow/engine/simple_extension_type_internal.h b/cpp/src/arrow/engine/simple_extension_type_internal.h index b177425a9a94a..66d86088a76c6 100644 --- a/cpp/src/arrow/engine/simple_extension_type_internal.h +++ b/cpp/src/arrow/engine/simple_extension_type_internal.h @@ -18,13 +18,13 @@ #pragma once #include +#include #include #include #include #include "arrow/extension_type.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/reflection_internal.h" #include "arrow/util/string.h" @@ -106,7 +106,7 @@ class SimpleExtensionType : public ExtensionType { kProperties->ForEach(*this); } - void Fail() { params_ = util::nullopt; } + void Fail() { params_ = std::nullopt; } void Init(util::string_view class_name, util::string_view repr, size_t num_properties) { @@ -144,7 +144,7 @@ class SimpleExtensionType : public ExtensionType { prop.set(&*params_, std::move(value)); } - util::optional params_; + std::optional params_; std::vector members_; }; Result> Deserialize( diff --git a/cpp/src/arrow/engine/substrait/expression_internal.cc b/cpp/src/arrow/engine/substrait/expression_internal.cc index 9b364741a3571..1f9d234bff7e3 100644 --- a/cpp/src/arrow/engine/substrait/expression_internal.cc +++ b/cpp/src/arrow/engine/substrait/expression_internal.cc @@ -51,7 +51,7 @@ Status DecodeArg(const substrait::FunctionArgument& arg, uint32_t idx, call->SetEnumArg(idx, enum_val.specified()); break; case substrait::FunctionArgument::Enum::EnumKindCase::kUnspecified: - call->SetEnumArg(idx, util::nullopt); + call->SetEnumArg(idx, std::nullopt); break; default: return Status::Invalid("Unrecognized enum kind case: ", @@ -138,7 +138,7 @@ Result FromProto(const substrait::Expression& expr, case substrait::Expression::kSelection: { if (!expr.selection().has_direct_reference()) break; - util::optional out; + std::optional out; if (expr.selection().has_expression()) { ARROW_ASSIGN_OR_RAISE( out, FromProto(expr.selection().expression(), ext_set, conversion_options)); @@ -906,7 +906,7 @@ Result> EncodeSubstraitCa substrait::FunctionArgument* arg = scalar_fn->add_arguments(); if (call.HasEnumArg(i)) { auto enum_val = internal::make_unique(); - ARROW_ASSIGN_OR_RAISE(util::optional enum_arg, + ARROW_ASSIGN_OR_RAISE(std::optional enum_arg, call.GetEnumArg(i)); if (enum_arg) { enum_val->set_specified(enum_arg->to_string()); diff --git a/cpp/src/arrow/engine/substrait/extension_set.cc b/cpp/src/arrow/engine/substrait/extension_set.cc index 0e1f5ebc6647c..926fe846fffdd 100644 --- a/cpp/src/arrow/engine/substrait/extension_set.cc +++ b/cpp/src/arrow/engine/substrait/extension_set.cc @@ -78,24 +78,24 @@ Id IdStorage::Emplace(Id id) { return {owned_uri, owned_name}; } -util::optional IdStorage::Find(Id id) const { - util::optional maybe_owned_uri = FindUri(id.uri); +std::optional IdStorage::Find(Id id) const { + std::optional maybe_owned_uri = FindUri(id.uri); if (!maybe_owned_uri) { - return util::nullopt; + return std::nullopt; } auto name_itr = names_.find(id.name); if (name_itr == names_.end()) { - return util::nullopt; + return std::nullopt; } else { return Id{*maybe_owned_uri, *name_itr}; } } -util::optional IdStorage::FindUri(util::string_view uri) const { +std::optional IdStorage::FindUri(util::string_view uri) const { auto uri_itr = uris_.find(uri); if (uri_itr == uris_.end()) { - return util::nullopt; + return std::nullopt; } return *uri_itr; } @@ -111,8 +111,7 @@ util::string_view IdStorage::EmplaceUri(util::string_view uri) { return *uri_itr; } -Result> SubstraitCall::GetEnumArg( - uint32_t index) const { +Result> SubstraitCall::GetEnumArg(uint32_t index) const { if (index >= size_) { return Status::Invalid("Expected Substrait call to have an enum argument at index ", index, " but it did not have enough arguments"); @@ -129,7 +128,7 @@ bool SubstraitCall::HasEnumArg(uint32_t index) const { return enum_args_.find(index) != enum_args_.end(); } -void SubstraitCall::SetEnumArg(uint32_t index, util::optional enum_arg) { +void SubstraitCall::SetEnumArg(uint32_t index, std::optional enum_arg) { size_ = std::max(size_, index + 1); enum_args_[index] = std::move(enum_arg); } @@ -203,7 +202,7 @@ Result ExtensionSet::Make( set.registry_ = registry; for (auto& uri : uris) { - util::optional maybe_uri_internal = registry->FindUri(uri.second); + std::optional maybe_uri_internal = registry->FindUri(uri.second); if (maybe_uri_internal) { set.uris_[uri.first] = *maybe_uri_internal; } else { @@ -233,7 +232,7 @@ Result ExtensionSet::Make( for (const auto& function_id : function_ids) { if (function_id.second.empty()) continue; RETURN_NOT_OK(set.CheckHasUri(function_id.second.uri)); - util::optional maybe_id_internal = registry->FindId(function_id.second); + std::optional maybe_id_internal = registry->FindId(function_id.second); if (maybe_id_internal) { set.functions_[function_id.first] = *maybe_id_internal; } else { @@ -309,9 +308,9 @@ struct ExtensionIdRegistryImpl : ExtensionIdRegistry { virtual ~ExtensionIdRegistryImpl() {} - util::optional FindUri(util::string_view uri) const override { + std::optional FindUri(util::string_view uri) const override { if (parent_) { - util::optional parent_uri = parent_->FindUri(uri); + std::optional parent_uri = parent_->FindUri(uri); if (parent_uri) { return parent_uri; } @@ -319,9 +318,9 @@ struct ExtensionIdRegistryImpl : ExtensionIdRegistry { return ids_.FindUri(uri); } - util::optional FindId(Id id) const override { + std::optional FindId(Id id) const override { if (parent_) { - util::optional parent_id = parent_->FindId(id); + std::optional parent_id = parent_->FindId(id); if (parent_id) { return parent_id; } @@ -329,7 +328,7 @@ struct ExtensionIdRegistryImpl : ExtensionIdRegistry { return ids_.Find(id); } - util::optional GetType(const DataType& type) const override { + std::optional GetType(const DataType& type) const override { if (auto index = GetIndex(type_to_index_, &type)) { return TypeRecord{type_ids_[*index], types_[*index]}; } @@ -339,7 +338,7 @@ struct ExtensionIdRegistryImpl : ExtensionIdRegistry { return {}; } - util::optional GetType(Id id) const override { + std::optional GetType(Id id) const override { if (auto index = GetIndex(id_to_index_, id)) { return TypeRecord{type_ids_[*index], types_[*index]}; } @@ -605,7 +604,7 @@ struct ExtensionIdRegistryImpl : ExtensionIdRegistry { }; template -using EnumParser = std::function(util::optional)>; +using EnumParser = std::function(std::optional)>; template EnumParser GetEnumParser(const std::vector& options) { @@ -613,7 +612,7 @@ EnumParser GetEnumParser(const std::vector& options) { for (std::size_t i = 0; i < options.size(); i++) { parse_map[options[i]] = static_cast(i + 1); } - return [parse_map](util::optional enum_val) -> Result { + return [parse_map](std::optional enum_val) -> Result { if (!enum_val) { // Assumes 0 is always kUnspecified in Enum return static_cast(0); @@ -640,7 +639,7 @@ static EnumParser kOverflowParser = template Result ParseEnumArg(const SubstraitCall& call, uint32_t arg_index, const EnumParser& parser) { - ARROW_ASSIGN_OR_RAISE(util::optional enum_arg, + ARROW_ASSIGN_OR_RAISE(std::optional enum_arg, call.GetEnumArg(arg_index)); return parser(enum_arg); } diff --git a/cpp/src/arrow/engine/substrait/extension_set.h b/cpp/src/arrow/engine/substrait/extension_set.h index 410a19ecf61ea..e2b20f989ac11 100644 --- a/cpp/src/arrow/engine/substrait/extension_set.h +++ b/cpp/src/arrow/engine/substrait/extension_set.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include #include @@ -31,7 +32,6 @@ #include "arrow/type_fwd.h" #include "arrow/util/hash_util.h" #include "arrow/util/hashing.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" namespace arrow { @@ -86,11 +86,11 @@ class IdStorage { /// \brief Get an equivalent id pointing into this storage /// /// If no id is found then nullopt will be returned - util::optional Find(Id id) const; + std::optional Find(Id id) const; /// \brief Get an equivalent view pointing into this storage for a URI /// /// If no URI is found then nullopt will be returned - util::optional FindUri(util::string_view uri) const; + std::optional FindUri(util::string_view uri) const; private: std::unordered_set uris_; @@ -119,8 +119,8 @@ class SubstraitCall { bool is_hash() const { return is_hash_; } bool HasEnumArg(uint32_t index) const; - Result> GetEnumArg(uint32_t index) const; - void SetEnumArg(uint32_t index, util::optional enum_arg); + Result> GetEnumArg(uint32_t index) const; + void SetEnumArg(uint32_t index, std::optional enum_arg); Result GetValueArg(uint32_t index) const; bool HasValueArg(uint32_t index) const; void SetValueArg(uint32_t index, compute::Expression value_arg); @@ -133,7 +133,7 @@ class SubstraitCall { // Only needed when converting from Substrait -> Arrow aggregates. The // Arrow function name depends on whether or not there are any groups bool is_hash_; - std::unordered_map> enum_args_; + std::unordered_map> enum_args_; std::unordered_map value_args_; uint32_t size_ = 0; }; @@ -174,13 +174,13 @@ class ARROW_ENGINE_EXPORT ExtensionIdRegistry { /// \brief Return a uri view owned by this registry /// /// If the URI has never been emplaced it will return nullopt - virtual util::optional FindUri(util::string_view uri) const = 0; + virtual std::optional FindUri(util::string_view uri) const = 0; /// \brief Return a id view owned by this registry /// /// If the id has never been emplaced it will return nullopt - virtual util::optional FindId(Id id) const = 0; - virtual util::optional GetType(const DataType&) const = 0; - virtual util::optional GetType(Id) const = 0; + virtual std::optional FindId(Id id) const = 0; + virtual std::optional GetType(const DataType&) const = 0; + virtual std::optional GetType(Id) const = 0; virtual Status CanRegisterType(Id, const std::shared_ptr& type) const = 0; virtual Status RegisterType(Id, std::shared_ptr) = 0; /// \brief Register a converter that converts an Arrow call to a Substrait call diff --git a/cpp/src/arrow/engine/substrait/extension_types.cc b/cpp/src/arrow/engine/substrait/extension_types.cc index b8fd191b3fdf7..2b7211766ee53 100644 --- a/cpp/src/arrow/engine/substrait/extension_types.cc +++ b/cpp/src/arrow/engine/substrait/extension_types.cc @@ -115,18 +115,18 @@ bool UnwrapUuid(const DataType& t) { return false; } -util::optional UnwrapFixedChar(const DataType& t) { +std::optional UnwrapFixedChar(const DataType& t) { if (auto params = FixedCharType::GetIf(t)) { return params->length; } - return util::nullopt; + return std::nullopt; } -util::optional UnwrapVarChar(const DataType& t) { +std::optional UnwrapVarChar(const DataType& t) { if (auto params = VarCharType::GetIf(t)) { return params->length; } - return util::nullopt; + return std::nullopt; } bool UnwrapIntervalYear(const DataType& t) { diff --git a/cpp/src/arrow/engine/substrait/extension_types.h b/cpp/src/arrow/engine/substrait/extension_types.h index d6db454ec30dc..c623d081b188e 100644 --- a/cpp/src/arrow/engine/substrait/extension_types.h +++ b/cpp/src/arrow/engine/substrait/extension_types.h @@ -19,13 +19,13 @@ #pragma once +#include #include #include "arrow/buffer.h" #include "arrow/compute/function.h" #include "arrow/engine/substrait/visibility.h" #include "arrow/type_fwd.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" namespace arrow { @@ -64,11 +64,11 @@ bool UnwrapUuid(const DataType&); /// Return FixedChar length if t is FixedChar, otherwise nullopt ARROW_ENGINE_EXPORT -util::optional UnwrapFixedChar(const DataType&); +std::optional UnwrapFixedChar(const DataType&); /// Return Varchar (max) length if t is VarChar, otherwise nullopt ARROW_ENGINE_EXPORT -util::optional UnwrapVarChar(const DataType& t); +std::optional UnwrapVarChar(const DataType& t); /// Return true if t is IntervalYear, otherwise false ARROW_ENGINE_EXPORT diff --git a/cpp/src/arrow/engine/substrait/serde_test.cc b/cpp/src/arrow/engine/substrait/serde_test.cc index b50e1c6084cf8..cb1eadcdbdf80 100644 --- a/cpp/src/arrow/engine/substrait/serde_test.cc +++ b/cpp/src/arrow/engine/substrait/serde_test.cc @@ -80,7 +80,7 @@ Result> GetTableFromPlan( const std::shared_ptr& output_schema) { ARROW_ASSIGN_OR_RAISE(auto plan, compute::ExecPlan::Make(&exec_context)); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; auto sink_node_options = compute::SinkNodeOptions{&sink_gen}; auto sink_declaration = compute::Declaration({"sink", sink_node_options, "e"}); auto declarations = compute::Declaration::Sequence({other_declrs, sink_declaration}); @@ -1949,7 +1949,7 @@ TEST(Substrait, BasicPlanRoundTripping) { auto comp_right_value = compute::field_ref(filter_col_right); auto filter = compute::equal(comp_left_value, comp_right_value); - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; auto declarations = compute::Declaration::Sequence( {compute::Declaration( diff --git a/cpp/src/arrow/engine/substrait/util.cc b/cpp/src/arrow/engine/substrait/util.cc index f51666ef8585b..6587ea077ddd5 100644 --- a/cpp/src/arrow/engine/substrait/util.cc +++ b/cpp/src/arrow/engine/substrait/util.cc @@ -29,7 +29,7 @@ namespace { class SubstraitSinkConsumer : public compute::SinkNodeConsumer { public: explicit SubstraitSinkConsumer( - arrow::PushGenerator>::Producer producer) + arrow::PushGenerator>::Producer producer) : producer_(std::move(producer)) {} Status Consume(compute::ExecBatch batch) override { @@ -53,7 +53,7 @@ class SubstraitSinkConsumer : public compute::SinkNodeConsumer { std::shared_ptr schema() { return schema_; } private: - arrow::PushGenerator>::Producer producer_; + arrow::PushGenerator>::Producer producer_; std::shared_ptr schema_; }; @@ -105,7 +105,7 @@ class SubstraitExecutor { } private: - arrow::PushGenerator> generator_; + arrow::PushGenerator> generator_; std::vector declarations_; std::shared_ptr plan_; bool plan_started_; diff --git a/cpp/src/arrow/engine/substrait/util.h b/cpp/src/arrow/engine/substrait/util.h index 90cb4e3dd2a37..a616968d96112 100644 --- a/cpp/src/arrow/engine/substrait/util.h +++ b/cpp/src/arrow/engine/substrait/util.h @@ -18,11 +18,12 @@ #pragma once #include +#include + #include "arrow/compute/registry.h" #include "arrow/engine/substrait/api.h" #include "arrow/engine/substrait/options.h" #include "arrow/util/iterator.h" -#include "arrow/util/optional.h" namespace arrow { diff --git a/cpp/src/arrow/filesystem/gcsfs.h b/cpp/src/arrow/filesystem/gcsfs.h index 77b8a0b201a8c..c3d03b5cb21a2 100644 --- a/cpp/src/arrow/filesystem/gcsfs.h +++ b/cpp/src/arrow/filesystem/gcsfs.h @@ -18,11 +18,11 @@ #pragma once #include +#include #include #include #include "arrow/filesystem/filesystem.h" -#include "arrow/util/optional.h" #include "arrow/util/uri.h" namespace arrow { @@ -70,7 +70,7 @@ struct ARROW_EXPORT GcsOptions { /// errors. /// /// The default policy is to retry for up to 15 minutes. - arrow::util::optional retry_limit_seconds; + std::optional retry_limit_seconds; /// \brief Default metadata for OpenOutputStream. /// diff --git a/cpp/src/arrow/filesystem/path_util.cc b/cpp/src/arrow/filesystem/path_util.cc index 1afc3b2a89b49..2216a4bb258f8 100644 --- a/cpp/src/arrow/filesystem/path_util.cc +++ b/cpp/src/arrow/filesystem/path_util.cc @@ -189,10 +189,10 @@ bool IsAncestorOf(util::string_view ancestor, util::string_view descendant) { return descendant.starts_with(std::string{kSep}); } -util::optional RemoveAncestor(util::string_view ancestor, - util::string_view descendant) { +std::optional RemoveAncestor(util::string_view ancestor, + util::string_view descendant) { if (!IsAncestorOf(ancestor, descendant)) { - return util::nullopt; + return std::nullopt; } auto relative_to_ancestor = descendant.substr(ancestor.size()); diff --git a/cpp/src/arrow/filesystem/path_util.h b/cpp/src/arrow/filesystem/path_util.h index d4083d3b5c9d0..ea8e56df5d43b 100644 --- a/cpp/src/arrow/filesystem/path_util.h +++ b/cpp/src/arrow/filesystem/path_util.h @@ -17,12 +17,12 @@ #pragma once +#include #include #include #include #include "arrow/type_fwd.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" namespace arrow { @@ -79,8 +79,8 @@ ARROW_EXPORT bool IsAncestorOf(util::string_view ancestor, util::string_view descendant); ARROW_EXPORT -util::optional RemoveAncestor(util::string_view ancestor, - util::string_view descendant); +std::optional RemoveAncestor(util::string_view ancestor, + util::string_view descendant); /// Return a vector of ancestors between a base path and a descendant. /// For example, diff --git a/cpp/src/arrow/filesystem/s3fs.cc b/cpp/src/arrow/filesystem/s3fs.cc index 878f54812ba9e..db79810f5d732 100644 --- a/cpp/src/arrow/filesystem/s3fs.cc +++ b/cpp/src/arrow/filesystem/s3fs.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -90,7 +91,6 @@ #include "arrow/util/io_util.h" #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/string.h" #include "arrow/util/task_group.h" #include "arrow/util/thread_pool.h" @@ -657,7 +657,7 @@ class S3Client : public Aws::S3::S3Client { // We work around the issue by registering a DataReceivedEventHandler // which parses the XML response for embedded errors. - util::optional> aws_error; + std::optional> aws_error; auto handler = [&](const Aws::Http::HttpRequest* http_req, Aws::Http::HttpResponse* http_resp, @@ -762,7 +762,7 @@ class ClientBuilder { Aws::Client::ClientConfiguration* mutable_config() { return &client_config_; } Result> BuildClient( - util::optional io_context = util::nullopt) { + std::optional io_context = std::nullopt) { credentials_provider_ = options_.credentials_provider; if (!options_.region.empty()) { client_config_.region = ToAwsString(options_.region); @@ -1708,7 +1708,7 @@ class S3FileSystem::Impl : public std::enable_shared_from_this client_; - util::optional backend_; + std::optional backend_; const int32_t kListObjectsMaxKeys = 1000; // At most 1000 keys per multiple-delete request diff --git a/cpp/src/arrow/flight/cookie_internal.cc b/cpp/src/arrow/flight/cookie_internal.cc index 1a15da9267693..380ea56976d52 100644 --- a/cpp/src/arrow/flight/cookie_internal.cc +++ b/cpp/src/arrow/flight/cookie_internal.cc @@ -47,7 +47,7 @@ namespace arrow { namespace flight { namespace internal { -using CookiePair = arrow::util::optional>; +using CookiePair = std::optional>; using CookieHeaderPair = const std::pair&; @@ -139,7 +139,7 @@ CookiePair Cookie::ParseCookieAttribute(const std::string& cookie_header_value, if (std::string::npos == equals_pos) { // No cookie attribute. *start_pos = std::string::npos; - return arrow::util::nullopt; + return std::nullopt; } std::string::size_type semi_col_pos = cookie_header_value.find(';', equals_pos); diff --git a/cpp/src/arrow/flight/cookie_internal.h b/cpp/src/arrow/flight/cookie_internal.h index 6b3af516bb6b7..b87c8052266ad 100644 --- a/cpp/src/arrow/flight/cookie_internal.h +++ b/cpp/src/arrow/flight/cookie_internal.h @@ -21,13 +21,13 @@ #include #include +#include #include #include #include #include "arrow/flight/client_middleware.h" #include "arrow/result.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" namespace arrow { @@ -65,7 +65,7 @@ class ARROW_FLIGHT_EXPORT Cookie { /// function returns. /// /// \return Optional cookie key value pair. - static arrow::util::optional> ParseCookieAttribute( + static std::optional> ParseCookieAttribute( const std::string& cookie_header_value, std::string::size_type* start_pos); /// \brief Function to fix cookie format date string so it is accepted by Windows diff --git a/cpp/src/arrow/flight/flight_internals_test.cc b/cpp/src/arrow/flight/flight_internals_test.cc index 84040a1a47653..1275db6a8d417 100644 --- a/cpp/src/arrow/flight/flight_internals_test.cc +++ b/cpp/src/arrow/flight/flight_internals_test.cc @@ -359,12 +359,12 @@ class TestCookieParsing : public ::testing::Test { void VerifyCookieAttributeParsing( const std::string cookie_str, std::string::size_type start_pos, - const util::optional> cookie_attribute, + const std::optional> cookie_attribute, const std::string::size_type start_pos_after) { - util::optional> attr = + std::optional> attr = internal::Cookie::ParseCookieAttribute(cookie_str, &start_pos); - if (cookie_attribute == util::nullopt) { + if (cookie_attribute == std::nullopt) { EXPECT_EQ(cookie_attribute, attr); } else { EXPECT_EQ(cookie_attribute.value(), attr.value()); @@ -454,7 +454,7 @@ TEST_F(TestCookieParsing, DateConversion) { } TEST_F(TestCookieParsing, ParseCookieAttribute) { - VerifyCookieAttributeParsing("", 0, util::nullopt, std::string::npos); + VerifyCookieAttributeParsing("", 0, std::nullopt, std::string::npos); std::string cookie_string = "attr0=0; attr1=1; attr2=2; attr3=3"; auto attr_length = std::string("attr0=0;").length(); @@ -470,8 +470,8 @@ TEST_F(TestCookieParsing, ParseCookieAttribute) { VerifyCookieAttributeParsing(cookie_string, (start_pos += (attr_length + 1)), std::make_pair("attr3", "3"), std::string::npos); VerifyCookieAttributeParsing(cookie_string, (start_pos += (attr_length - 1)), - util::nullopt, std::string::npos); - VerifyCookieAttributeParsing(cookie_string, std::string::npos, util::nullopt, + std::nullopt, std::string::npos); + VerifyCookieAttributeParsing(cookie_string, std::string::npos, std::nullopt, std::string::npos); } @@ -491,28 +491,28 @@ TEST(TransportErrorHandling, ReconstructStatus) { EXPECT_RAISES_WITH_MESSAGE_THAT( Invalid, ::testing::HasSubstr(". Also, server sent unknown or invalid Arrow status code -1"), - internal::ReconstructStatus("-1", current, util::nullopt, util::nullopt, - util::nullopt, /*detail=*/nullptr)); + internal::ReconstructStatus("-1", current, std::nullopt, std::nullopt, std::nullopt, + /*detail=*/nullptr)); EXPECT_RAISES_WITH_MESSAGE_THAT( Invalid, ::testing::HasSubstr( ". Also, server sent unknown or invalid Arrow status code foobar"), - internal::ReconstructStatus("foobar", current, util::nullopt, util::nullopt, - util::nullopt, /*detail=*/nullptr)); + internal::ReconstructStatus("foobar", current, std::nullopt, std::nullopt, + std::nullopt, /*detail=*/nullptr)); // Override code EXPECT_RAISES_WITH_MESSAGE_THAT( AlreadyExists, ::testing::HasSubstr("Base error message"), internal::ReconstructStatus( std::to_string(static_cast(StatusCode::AlreadyExists)), current, - util::nullopt, util::nullopt, util::nullopt, /*detail=*/nullptr)); + std::nullopt, std::nullopt, std::nullopt, /*detail=*/nullptr)); // Override message EXPECT_RAISES_WITH_MESSAGE_THAT( AlreadyExists, ::testing::HasSubstr("Custom error message"), internal::ReconstructStatus( std::to_string(static_cast(StatusCode::AlreadyExists)), current, - "Custom error message", util::nullopt, util::nullopt, /*detail=*/nullptr)); + "Custom error message", std::nullopt, std::nullopt, /*detail=*/nullptr)); // With detail EXPECT_RAISES_WITH_MESSAGE_THAT( @@ -521,7 +521,7 @@ TEST(TransportErrorHandling, ReconstructStatus) { ::testing::HasSubstr(". Detail: Detail message")), internal::ReconstructStatus( std::to_string(static_cast(StatusCode::AlreadyExists)), current, - "Custom error message", "Detail message", util::nullopt, /*detail=*/nullptr)); + "Custom error message", "Detail message", std::nullopt, /*detail=*/nullptr)); // With detail and bin auto reconstructed = internal::ReconstructStatus( diff --git a/cpp/src/arrow/flight/sql/client_test.cc b/cpp/src/arrow/flight/sql/client_test.cc index b9eeda76b00ad..acd078a847792 100644 --- a/cpp/src/arrow/flight/sql/client_test.cc +++ b/cpp/src/arrow/flight/sql/client_test.cc @@ -213,7 +213,7 @@ TEST_F(TestFlightSqlClient, TestGetExported) { ON_CALL(sql_client_, GetFlightInfo).WillByDefault(ReturnEmptyFlightInfo); EXPECT_CALL(sql_client_, GetFlightInfo(Ref(call_options_), descriptor)); - TableRef table_ref = {util::make_optional(catalog), util::make_optional(schema), table}; + TableRef table_ref = {std::make_optional(catalog), std::make_optional(schema), table}; ASSERT_OK(sql_client_.GetExportedKeys(call_options_, table_ref)); } @@ -231,7 +231,7 @@ TEST_F(TestFlightSqlClient, TestGetImported) { ON_CALL(sql_client_, GetFlightInfo).WillByDefault(ReturnEmptyFlightInfo); EXPECT_CALL(sql_client_, GetFlightInfo(Ref(call_options_), descriptor)); - TableRef table_ref = {util::make_optional(catalog), util::make_optional(schema), table}; + TableRef table_ref = {std::make_optional(catalog), std::make_optional(schema), table}; ASSERT_OK(sql_client_.GetImportedKeys(call_options_, table_ref)); } @@ -249,7 +249,7 @@ TEST_F(TestFlightSqlClient, TestGetPrimary) { ON_CALL(sql_client_, GetFlightInfo).WillByDefault(ReturnEmptyFlightInfo); EXPECT_CALL(sql_client_, GetFlightInfo(Ref(call_options_), descriptor)); - TableRef table_ref = {util::make_optional(catalog), util::make_optional(schema), table}; + TableRef table_ref = {std::make_optional(catalog), std::make_optional(schema), table}; ASSERT_OK(sql_client_.GetPrimaryKeys(call_options_, table_ref)); } @@ -273,10 +273,10 @@ TEST_F(TestFlightSqlClient, TestGetCrossReference) { ON_CALL(sql_client_, GetFlightInfo).WillByDefault(ReturnEmptyFlightInfo); EXPECT_CALL(sql_client_, GetFlightInfo(Ref(call_options_), descriptor)); - TableRef pk_table_ref = {util::make_optional(pk_catalog), - util::make_optional(pk_schema), pk_table}; - TableRef fk_table_ref = {util::make_optional(fk_catalog), - util::make_optional(fk_schema), fk_table}; + TableRef pk_table_ref = {std::make_optional(pk_catalog), std::make_optional(pk_schema), + pk_table}; + TableRef fk_table_ref = {std::make_optional(fk_catalog), std::make_optional(fk_schema), + fk_table}; ASSERT_OK(sql_client_.GetCrossReference(call_options_, pk_table_ref, fk_table_ref)); } diff --git a/cpp/src/arrow/flight/sql/server.cc b/cpp/src/arrow/flight/sql/server.cc index 78fbff0c33a4e..a8f3ed8a80c24 100644 --- a/cpp/src/arrow/flight/sql/server.cc +++ b/cpp/src/arrow/flight/sql/server.cc @@ -33,7 +33,7 @@ #include "arrow/util/checked_cast.h" #define PROPERTY_TO_OPTIONAL(COMMAND, PROPERTY) \ - COMMAND.has_##PROPERTY() ? util::make_optional(COMMAND.PROPERTY()) : util::nullopt + COMMAND.has_##PROPERTY() ? std::make_optional(COMMAND.PROPERTY()) : std::nullopt namespace arrow { namespace flight { diff --git a/cpp/src/arrow/flight/sql/server.h b/cpp/src/arrow/flight/sql/server.h index 49e239a0cddd4..91dad98843f52 100644 --- a/cpp/src/arrow/flight/sql/server.h +++ b/cpp/src/arrow/flight/sql/server.h @@ -21,6 +21,7 @@ #pragma once #include +#include #include #include @@ -29,7 +30,6 @@ #include "arrow/flight/sql/types.h" #include "arrow/flight/sql/visibility.h" #include "arrow/flight/types.h" -#include "arrow/util/optional.h" namespace arrow { namespace flight { @@ -79,19 +79,19 @@ struct ARROW_FLIGHT_SQL_EXPORT GetSqlInfo { /// \brief A request to list database schemas. struct ARROW_FLIGHT_SQL_EXPORT GetDbSchemas { /// \brief An optional database catalog to filter on. - util::optional catalog; + std::optional catalog; /// \brief An optional database schema to filter on. - util::optional db_schema_filter_pattern; + std::optional db_schema_filter_pattern; }; /// \brief A request to list database tables. struct ARROW_FLIGHT_SQL_EXPORT GetTables { /// \brief An optional database catalog to filter on. - util::optional catalog; + std::optional catalog; /// \brief An optional database schema to filter on. - util::optional db_schema_filter_pattern; + std::optional db_schema_filter_pattern; /// \brief An optional table name to filter on. - util::optional table_name_filter_pattern; + std::optional table_name_filter_pattern; /// \brief A list of table types to filter on. std::vector table_types; /// \brief Whether to include the Arrow schema in the response. @@ -101,7 +101,7 @@ struct ARROW_FLIGHT_SQL_EXPORT GetTables { /// \brief A request to get SQL data type information. struct ARROW_FLIGHT_SQL_EXPORT GetXdbcTypeInfo { /// \brief A specific SQL type ID to fetch information about. - util::optional data_type; + std::optional data_type; }; /// \brief A request to list primary keys of a table. diff --git a/cpp/src/arrow/flight/sql/server_test.cc b/cpp/src/arrow/flight/sql/server_test.cc index 69081acdb59c6..7ba3ca4a24364 100644 --- a/cpp/src/arrow/flight/sql/server_test.cc +++ b/cpp/src/arrow/flight/sql/server_test.cc @@ -640,7 +640,7 @@ TEST_F(TestFlightSqlServer, TestCommandPreparedStatementUpdate) { TEST_F(TestFlightSqlServer, TestCommandGetPrimaryKeys) { FlightCallOptions options = {}; - TableRef table_ref = {util::nullopt, util::nullopt, "int%"}; + TableRef table_ref = {std::nullopt, std::nullopt, "int%"}; ASSERT_OK_AND_ASSIGN(auto flight_info, sql_client->GetPrimaryKeys(options, table_ref)); ASSERT_OK_AND_ASSIGN(auto stream, @@ -664,7 +664,7 @@ TEST_F(TestFlightSqlServer, TestCommandGetPrimaryKeys) { TEST_F(TestFlightSqlServer, TestCommandGetImportedKeys) { FlightCallOptions options = {}; - TableRef table_ref = {util::nullopt, util::nullopt, "intTable"}; + TableRef table_ref = {std::nullopt, std::nullopt, "intTable"}; ASSERT_OK_AND_ASSIGN(auto flight_info, sql_client->GetImportedKeys(options, table_ref)); ASSERT_OK_AND_ASSIGN(auto stream, @@ -696,7 +696,7 @@ TEST_F(TestFlightSqlServer, TestCommandGetImportedKeys) { TEST_F(TestFlightSqlServer, TestCommandGetExportedKeys) { FlightCallOptions options = {}; - TableRef table_ref = {util::nullopt, util::nullopt, "foreignTable"}; + TableRef table_ref = {std::nullopt, std::nullopt, "foreignTable"}; ASSERT_OK_AND_ASSIGN(auto flight_info, sql_client->GetExportedKeys(options, table_ref)); ASSERT_OK_AND_ASSIGN(auto stream, @@ -728,8 +728,8 @@ TEST_F(TestFlightSqlServer, TestCommandGetExportedKeys) { TEST_F(TestFlightSqlServer, TestCommandGetCrossReference) { FlightCallOptions options = {}; - TableRef pk_table_ref = {util::nullopt, util::nullopt, "foreignTable"}; - TableRef fk_table_ref = {util::nullopt, util::nullopt, "intTable"}; + TableRef pk_table_ref = {std::nullopt, std::nullopt, "foreignTable"}; + TableRef fk_table_ref = {std::nullopt, std::nullopt, "intTable"}; ASSERT_OK_AND_ASSIGN(auto flight_info, sql_client->GetCrossReference( options, pk_table_ref, fk_table_ref)); diff --git a/cpp/src/arrow/flight/sql/test_app_cli.cc b/cpp/src/arrow/flight/sql/test_app_cli.cc index 7989210dd098b..2df05d2875b1f 100644 --- a/cpp/src/arrow/flight/sql/test_app_cli.cc +++ b/cpp/src/arrow/flight/sql/test_app_cli.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "arrow/array/builder_binary.h" #include "arrow/array/builder_primitive.h" @@ -29,7 +30,6 @@ #include "arrow/pretty_print.h" #include "arrow/status.h" #include "arrow/table.h" -#include "arrow/util/optional.h" using arrow::Result; using arrow::Schema; @@ -159,16 +159,16 @@ Status RunMain() { info, sql_client.GetTables(call_options, &FLAGS_catalog, &FLAGS_schema, &FLAGS_table, false, nullptr)); } else if (FLAGS_command == "GetExportedKeys") { - TableRef table_ref = {arrow::util::make_optional(FLAGS_catalog), - arrow::util::make_optional(FLAGS_schema), FLAGS_table}; + TableRef table_ref = {std::make_optional(FLAGS_catalog), + std::make_optional(FLAGS_schema), FLAGS_table}; ARROW_ASSIGN_OR_RAISE(info, sql_client.GetExportedKeys(call_options, table_ref)); } else if (FLAGS_command == "GetImportedKeys") { - TableRef table_ref = {arrow::util::make_optional(FLAGS_catalog), - arrow::util::make_optional(FLAGS_schema), FLAGS_table}; + TableRef table_ref = {std::make_optional(FLAGS_catalog), + std::make_optional(FLAGS_schema), FLAGS_table}; ARROW_ASSIGN_OR_RAISE(info, sql_client.GetImportedKeys(call_options, table_ref)); } else if (FLAGS_command == "GetPrimaryKeys") { - TableRef table_ref = {arrow::util::make_optional(FLAGS_catalog), - arrow::util::make_optional(FLAGS_schema), FLAGS_table}; + TableRef table_ref = {std::make_optional(FLAGS_catalog), + std::make_optional(FLAGS_schema), FLAGS_table}; ARROW_ASSIGN_OR_RAISE(info, sql_client.GetPrimaryKeys(call_options, table_ref)); } else if (FLAGS_command == "GetSqlInfo") { ARROW_ASSIGN_OR_RAISE(info, sql_client.GetSqlInfo(call_options, {})); diff --git a/cpp/src/arrow/flight/sql/types.h b/cpp/src/arrow/flight/sql/types.h index a6c2648e7c49e..20c7952d8d710 100644 --- a/cpp/src/arrow/flight/sql/types.h +++ b/cpp/src/arrow/flight/sql/types.h @@ -18,13 +18,13 @@ #pragma once #include +#include #include #include #include #include "arrow/flight/sql/visibility.h" #include "arrow/type_fwd.h" -#include "arrow/util/optional.h" #include "arrow/util/variant.h" namespace arrow { @@ -838,9 +838,9 @@ struct ARROW_FLIGHT_SQL_EXPORT SqlInfoOptions { /// \brief A SQL %table reference, optionally containing table's catalog and db_schema. struct ARROW_FLIGHT_SQL_EXPORT TableRef { /// \brief The table's catalog. - util::optional catalog; + std::optional catalog; /// \brief The table's database schema. - util::optional db_schema; + std::optional db_schema; /// \brief The table name. std::string table; }; diff --git a/cpp/src/arrow/flight/transport.cc b/cpp/src/arrow/flight/transport.cc index 0da81a567eb1a..7f0b1cf929d2c 100644 --- a/cpp/src/arrow/flight/transport.cc +++ b/cpp/src/arrow/flight/transport.cc @@ -299,9 +299,9 @@ Status TransportStatus::ToStatus() const { } Status ReconstructStatus(const std::string& code_str, const Status& current_status, - util::optional message, - util::optional detail_message, - util::optional detail_bin, + std::optional message, + std::optional detail_message, + std::optional detail_bin, std::shared_ptr detail) { // Bounce through std::string to get a proper null-terminated C string StatusCode status_code = current_status.code(); diff --git a/cpp/src/arrow/flight/transport.h b/cpp/src/arrow/flight/transport.h index 66ded71fbe9b9..6406734e6e7e7 100644 --- a/cpp/src/arrow/flight/transport.h +++ b/cpp/src/arrow/flight/transport.h @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -65,7 +66,6 @@ #include "arrow/flight/type_fwd.h" #include "arrow/flight/visibility.h" #include "arrow/type_fwd.h" -#include "arrow/util/optional.h" namespace arrow { namespace ipc { @@ -265,9 +265,9 @@ struct ARROW_FLIGHT_EXPORT TransportStatus { /// back to an Arrow status. ARROW_FLIGHT_EXPORT Status ReconstructStatus(const std::string& code_str, const Status& current_status, - util::optional message, - util::optional detail_message, - util::optional detail_bin, + std::optional message, + std::optional detail_message, + std::optional detail_bin, std::shared_ptr detail); } // namespace internal diff --git a/cpp/src/arrow/flight/transport/grpc/util_internal.cc b/cpp/src/arrow/flight/transport/grpc/util_internal.cc index 0455dc119a989..be858fb6d4463 100644 --- a/cpp/src/arrow/flight/transport/grpc/util_internal.cc +++ b/cpp/src/arrow/flight/transport/grpc/util_internal.cc @@ -55,25 +55,25 @@ static bool FromGrpcContext(const ::grpc::ClientContext& ctx, if (code_val == trailers.end()) return false; const auto message_val = trailers.find(kGrpcStatusMessageHeader); - const util::optional message = + const std::optional message = message_val == trailers.end() - ? util::nullopt - : util::optional( + ? std::nullopt + : std::optional( std::string(message_val->second.data(), message_val->second.size())); const auto detail_val = trailers.find(kGrpcStatusDetailHeader); - const util::optional detail_message = + const std::optional detail_message = detail_val == trailers.end() - ? util::nullopt - : util::optional( + ? std::nullopt + : std::optional( std::string(detail_val->second.data(), detail_val->second.size())); const auto grpc_detail_val = trailers.find(kBinaryErrorDetailsKey); - const util::optional detail_bin = + const std::optional detail_bin = grpc_detail_val == trailers.end() - ? util::nullopt - : util::optional(std::string(grpc_detail_val->second.data(), - grpc_detail_val->second.size())); + ? std::nullopt + : std::optional(std::string(grpc_detail_val->second.data(), + grpc_detail_val->second.size())); std::string code_str(code_val->second.data(), code_val->second.size()); *status = internal::ReconstructStatus(code_str, current_status, std::move(message), diff --git a/cpp/src/arrow/flight/transport/ucx/ucx_internal.cc b/cpp/src/arrow/flight/transport/ucx/ucx_internal.cc index abcf79112552a..373333663f8f7 100644 --- a/cpp/src/arrow/flight/transport/ucx/ucx_internal.cc +++ b/cpp/src/arrow/flight/transport/ucx/ucx_internal.cc @@ -274,7 +274,7 @@ Status HeadersFrame::GetStatus(Status* out) { *out = transport_status.ToStatus(); util::string_view detail_str, bin_str; - util::optional message, detail_message, detail_bin; + std::optional message, detail_message, detail_bin; if (!Get(kHeaderStatusCode).Value(&code_str).ok()) { // No Arrow status sent, go with the transport status return Status::OK(); diff --git a/cpp/src/arrow/memory_pool.cc b/cpp/src/arrow/memory_pool.cc index dff6fd830762f..99cb068246240 100644 --- a/cpp/src/arrow/memory_pool.cc +++ b/cpp/src/arrow/memory_pool.cc @@ -25,6 +25,7 @@ #include #include #include +#include #if defined(sun) || defined(__sun) #include @@ -40,7 +41,6 @@ #include "arrow/util/int_util_overflow.h" #include "arrow/util/io_util.h" #include "arrow/util/logging.h" // IWYU pragma: keep -#include "arrow/util/optional.h" #include "arrow/util/string.h" #include "arrow/util/thread_pool.h" #include "arrow/util/ubsan.h" @@ -103,8 +103,8 @@ const std::vector& SupportedBackends() { // Return the MemoryPoolBackend selected by the user through the // ARROW_DEFAULT_MEMORY_POOL environment variable, if any. -util::optional UserSelectedBackend() { - static auto user_selected_backend = []() -> util::optional { +std::optional UserSelectedBackend() { + static auto user_selected_backend = []() -> std::optional { auto unsupported_backend = [](const std::string& name) { std::vector supported; for (const auto backend : SupportedBackends()) { diff --git a/cpp/src/arrow/public_api_test.cc b/cpp/src/arrow/public_api_test.cc index a2aa624d0928a..a611dd7920c38 100644 --- a/cpp/src/arrow/public_api_test.cc +++ b/cpp/src/arrow/public_api_test.cc @@ -109,7 +109,7 @@ TEST(Misc, SetTimezoneConfig) { #else auto fs = std::make_shared(); - util::optional tzdata_result = GetTestTimezoneDatabaseRoot(); + std::optional tzdata_result = GetTestTimezoneDatabaseRoot(); std::string tzdata_dir; if (tzdata_result.has_value()) { tzdata_dir = tzdata_result.value(); @@ -129,7 +129,7 @@ TEST(Misc, SetTimezoneConfig) { ASSERT_OK_AND_ASSIGN(auto tempdir, arrow::internal::TemporaryDir::Make("tzdata")); // Validate that setting tzdb to that dir fails - arrow::GlobalOptions options = {util::make_optional(tempdir->path().ToString())}; + arrow::GlobalOptions options = {std::make_optional(tempdir->path().ToString())}; ASSERT_NOT_OK(arrow::Initialize(options)); // Copy tzdb data from ~/Downloads diff --git a/cpp/src/arrow/stl_iterator.h b/cpp/src/arrow/stl_iterator.h index e1eeb33fbae07..5f2acfb071b29 100644 --- a/cpp/src/arrow/stl_iterator.h +++ b/cpp/src/arrow/stl_iterator.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "arrow/chunked_array.h" @@ -27,7 +28,6 @@ #include "arrow/type_fwd.h" #include "arrow/type_traits.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" namespace arrow { namespace stl { @@ -49,7 +49,7 @@ template > class ArrayIterator { public: - using value_type = arrow::util::optional; + using value_type = std::optional; using difference_type = int64_t; using pointer = value_type*; using reference = value_type&; @@ -138,7 +138,7 @@ template > class ChunkedArrayIterator { public: - using value_type = arrow::util::optional; + using value_type = std::optional; using difference_type = int64_t; using pointer = value_type*; using reference = value_type&; diff --git a/cpp/src/arrow/stl_iterator_test.cc b/cpp/src/arrow/stl_iterator_test.cc index d4a011e450706..652a66cb516f1 100644 --- a/cpp/src/arrow/stl_iterator_test.cc +++ b/cpp/src/arrow/stl_iterator_test.cc @@ -30,8 +30,8 @@ namespace arrow { using internal::checked_cast; using internal::checked_pointer_cast; -using util::nullopt; -using util::optional; +using std::nullopt; +using std::optional; namespace stl { diff --git a/cpp/src/arrow/stl_test.cc b/cpp/src/arrow/stl_test.cc index 52dda54ce18da..ec12db2d74c81 100644 --- a/cpp/src/arrow/stl_test.cc +++ b/cpp/src/arrow/stl_test.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,6 @@ #include "arrow/testing/gtest_util.h" #include "arrow/type.h" #include "arrow/type_fwd.h" -#include "arrow/util/optional.h" using primitive_types_tuple = std::tuple; @@ -101,10 +101,10 @@ struct TestInt32Type { namespace arrow { using optional_types_tuple = - std::tuple, util::optional, util::optional, - util::optional, util::optional, util::optional, - util::optional, util::optional, util::optional, - util::optional>; + std::tuple, std::optional, std::optional, + std::optional, std::optional, std::optional, + std::optional, std::optional, std::optional, + std::optional>; template <> struct CTypeTraits { @@ -291,9 +291,8 @@ TEST(TestTableFromTupleVector, NullableTypesWithBoostOptional) { std::vector rows{ types_tuple(-1, -2, -3, -4, 1, 2, 3, 4, true, std::string("Tests")), types_tuple(-10, -20, -30, -40, 10, 20, 30, 40, false, std::string("Other")), - types_tuple(util::nullopt, util::nullopt, util::nullopt, util::nullopt, - util::nullopt, util::nullopt, util::nullopt, util::nullopt, - util::nullopt, util::nullopt), + types_tuple(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, + std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt), }; std::shared_ptr table; ASSERT_OK(TableFromTupleRange(default_memory_pool(), rows, names, &table)); diff --git a/cpp/src/arrow/testing/gtest_util.cc b/cpp/src/arrow/testing/gtest_util.cc index a4d867088000f..2ba944e41f1c2 100644 --- a/cpp/src/arrow/testing/gtest_util.cc +++ b/cpp/src/arrow/testing/gtest_util.cc @@ -466,10 +466,10 @@ std::shared_ptr
TableFromJSON(const std::shared_ptr& schema, return *Table::FromRecordBatches(schema, std::move(batches)); } -Result> PrintArrayDiff(const ChunkedArray& expected, - const ChunkedArray& actual) { +Result> PrintArrayDiff(const ChunkedArray& expected, + const ChunkedArray& actual) { if (actual.Equals(expected)) { - return util::nullopt; + return std::nullopt; } std::stringstream ss; diff --git a/cpp/src/arrow/testing/gtest_util.h b/cpp/src/arrow/testing/gtest_util.h index 8ce5049452a9e..b6bfcb8e2d38c 100644 --- a/cpp/src/arrow/testing/gtest_util.h +++ b/cpp/src/arrow/testing/gtest_util.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +39,6 @@ #include "arrow/type_fwd.h" #include "arrow/type_traits.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" @@ -270,7 +270,7 @@ ARROW_TESTING_EXPORT void AssertSchemaNotEqual(const std::shared_ptr& lh const std::shared_ptr& rhs, bool check_metadata = false); -ARROW_TESTING_EXPORT Result> PrintArrayDiff( +ARROW_TESTING_EXPORT Result> PrintArrayDiff( const ChunkedArray& expected, const ChunkedArray& actual); ARROW_TESTING_EXPORT void AssertTablesEqual(const Table& expected, const Table& actual, @@ -541,21 +541,4 @@ void PrintTo(const basic_string_view& view, std::ostream* os) { } } // namespace sv_lite - -namespace optional_lite { - -template -void PrintTo(const optional& opt, std::ostream* os) { - if (opt.has_value()) { - *os << "{"; - ::testing::internal::UniversalPrint(*opt, os); - *os << "}"; - } else { - *os << "nullopt"; - } -} - -inline void PrintTo(const decltype(nullopt)&, std::ostream* os) { *os << "nullopt"; } - -} // namespace optional_lite } // namespace nonstd diff --git a/cpp/src/arrow/testing/matchers.h b/cpp/src/arrow/testing/matchers.h index 25607c1ff5b8e..4d5bb6957572a 100644 --- a/cpp/src/arrow/testing/matchers.h +++ b/cpp/src/arrow/testing/matchers.h @@ -220,14 +220,14 @@ class ResultMatcher { class ErrorMatcher { public: explicit ErrorMatcher(StatusCode code, - util::optional> message_matcher) + std::optional> message_matcher) : code_(code), message_matcher_(std::move(message_matcher)) {} template operator testing::Matcher() const { // NOLINT runtime/explicit struct Impl : testing::MatcherInterface { explicit Impl(StatusCode code, - util::optional> message_matcher) + std::optional> message_matcher) : code_(code), message_matcher_(std::move(message_matcher)) {} void DescribeTo(::std::ostream* os) const override { @@ -270,7 +270,7 @@ class ErrorMatcher { } const StatusCode code_; - const util::optional> message_matcher_; + const std::optional> message_matcher_; }; return testing::Matcher(new Impl(code_, message_matcher_)); @@ -278,7 +278,7 @@ class ErrorMatcher { private: const StatusCode code_; - const util::optional> message_matcher_; + const std::optional> message_matcher_; }; class OkMatcher { @@ -324,7 +324,7 @@ inline OkMatcher Ok() { return {}; } // Returns a matcher that matches the StatusCode of a Status or Result. // Do not use Raises(StatusCode::OK) to match a non error code. -inline ErrorMatcher Raises(StatusCode code) { return ErrorMatcher(code, util::nullopt); } +inline ErrorMatcher Raises(StatusCode code) { return ErrorMatcher(code, std::nullopt); } // Returns a matcher that matches the StatusCode and message of a Status or Result. template @@ -421,7 +421,7 @@ template ::ArrayType, typename BuilderType = typename TypeTraits::BuilderType, typename ValueType = typename ::arrow::stl::detail::DefaultValueAccessor::ValueType> -DataEqMatcher DataEqArray(T type, const std::vector>& values) { +DataEqMatcher DataEqArray(T type, const std::vector>& values) { // FIXME(bkietz) broken until DataType is move constructible BuilderType builder(std::make_shared(std::move(type)), default_memory_pool()); DCHECK_OK(builder.Reserve(static_cast(values.size()))); @@ -453,7 +453,7 @@ inline DataEqMatcher DataEqScalar(const std::shared_ptr& type, /// Constructs a scalar against which arguments are matched template ::ScalarType, typename ValueType = typename ScalarType::ValueType> -DataEqMatcher DataEqScalar(T type, util::optional value) { +DataEqMatcher DataEqScalar(T type, std::optional value) { ScalarType expected(std::make_shared(std::move(type))); if (value) { diff --git a/cpp/src/arrow/testing/util.cc b/cpp/src/arrow/testing/util.cc index bc8e1e2699533..b59854480765b 100644 --- a/cpp/src/arrow/testing/util.cc +++ b/cpp/src/arrow/testing/util.cc @@ -111,12 +111,12 @@ Status GetTestResourceRoot(std::string* out) { return Status::OK(); } -util::optional GetTestTimezoneDatabaseRoot() { +std::optional GetTestTimezoneDatabaseRoot() { const char* c_root = std::getenv("ARROW_TIMEZONE_DATABASE"); if (!c_root) { - return util::optional(); + return std::optional(); } - return util::make_optional(std::string(c_root)); + return std::make_optional(std::string(c_root)); } Status InitTestTimezoneDatabase() { @@ -125,7 +125,7 @@ Status InitTestTimezoneDatabase() { if (!maybe_tzdata.has_value()) return Status::OK(); auto tzdata_path = std::string(maybe_tzdata.value()); - arrow::GlobalOptions options = {util::make_optional(tzdata_path)}; + arrow::GlobalOptions options = {std::make_optional(tzdata_path)}; ARROW_RETURN_NOT_OK(arrow::Initialize(options)); return Status::OK(); } diff --git a/cpp/src/arrow/testing/util.h b/cpp/src/arrow/testing/util.h index 457713f969b48..4f4b03438fd58 100644 --- a/cpp/src/arrow/testing/util.h +++ b/cpp/src/arrow/testing/util.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -34,7 +35,6 @@ #include "arrow/testing/visibility.h" #include "arrow/type_fwd.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" namespace arrow { @@ -112,7 +112,7 @@ UnionTypeFactories() { ARROW_TESTING_EXPORT Status GetTestResourceRoot(std::string*); // Return the value of the ARROW_TIMEZONE_DATABASE environment variable -ARROW_TESTING_EXPORT util::optional GetTestTimezoneDatabaseRoot(); +ARROW_TESTING_EXPORT std::optional GetTestTimezoneDatabaseRoot(); // Set the Timezone database based on the ARROW_TIMEZONE_DATABASE env variable // This is only relevant on Windows, since other OSs have compatible databases built-in diff --git a/cpp/src/arrow/util/async_generator.h b/cpp/src/arrow/util/async_generator.h index 9819b5ce92326..d4a9c2829a77d 100644 --- a/cpp/src/arrow/util/async_generator.h +++ b/cpp/src/arrow/util/async_generator.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "arrow/util/async_util.h" @@ -30,7 +31,6 @@ #include "arrow/util/io_util.h" #include "arrow/util/iterator.h" #include "arrow/util/mutex.h" -#include "arrow/util/optional.h" #include "arrow/util/queue.h" #include "arrow/util/thread_pool.h" @@ -498,7 +498,7 @@ class TransformingGenerator { } // See comment on TransformingIterator::Pump - Result> Pump() { + Result> Pump() { if (!finished_ && last_value_.has_value()) { ARROW_ASSIGN_OR_RAISE(TransformFlow next, transformer_(*last_value_)); if (next.ReadyForNext()) { @@ -517,12 +517,12 @@ class TransformingGenerator { if (finished_) { return IterationTraits::End(); } - return util::nullopt; + return std::nullopt; } AsyncGenerator generator_; Transformer transformer_; - util::optional last_value_; + std::optional last_value_; bool finished_; }; @@ -839,7 +839,7 @@ class PushGenerator { util::Mutex mutex; std::deque> result_q; - util::optional> consumer_fut; + std::optional> consumer_fut; bool finished = false; }; @@ -1726,7 +1726,7 @@ class BackgroundGenerator { bool should_shutdown; // If the queue is empty, the consumer will create a waiting future and wait for it std::queue> queue; - util::optional> waiting_future; + std::optional> waiting_future; // Every background task is given a future to complete when it is entirely finished // processing and ready for the next task to start or for State to be destroyed Future<> task_finished; diff --git a/cpp/src/arrow/util/async_generator_test.cc b/cpp/src/arrow/util/async_generator_test.cc index e75ca577c77ee..2b4c869bedc32 100644 --- a/cpp/src/arrow/util/async_generator_test.cc +++ b/cpp/src/arrow/util/async_generator_test.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include "arrow/type_fwd.h" #include "arrow/util/async_generator.h" #include "arrow/util/async_util.h" -#include "arrow/util/optional.h" #include "arrow/util/test_common.h" #include "arrow/util/vector.h" @@ -1846,7 +1846,7 @@ TEST(PushGenerator, CloseEarly) { } TEST(PushGenerator, DanglingProducer) { - util::optional> gen; + std::optional> gen; gen.emplace(); auto producer = gen->producer(); diff --git a/cpp/src/arrow/util/async_util.cc b/cpp/src/arrow/util/async_util.cc index 7e8c5513aab21..3ac4519a6f0b3 100644 --- a/cpp/src/arrow/util/async_util.cc +++ b/cpp/src/arrow/util/async_util.cc @@ -34,14 +34,14 @@ class ThrottleImpl : public AsyncTaskScheduler::Throttle { public: explicit ThrottleImpl(int max_concurrent_cost) : available_cost_(max_concurrent_cost) {} - util::optional> TryAcquire(int amt) override { + std::optional> TryAcquire(int amt) override { std::lock_guard lk(mutex_); if (backoff_.is_valid()) { return backoff_; } if (amt <= available_cost_) { available_cost_ -= amt; - return nullopt; + return std::nullopt; } backoff_ = Future<>::Make(); return backoff_; @@ -151,7 +151,7 @@ class AsyncTaskSchedulerImpl : public AsyncTaskScheduler { queue_->Push(std::move(task)); return true; } - util::optional> maybe_backoff = throttle_->TryAcquire(task->cost()); + std::optional> maybe_backoff = throttle_->TryAcquire(task->cost()); if (maybe_backoff) { queue_->Push(std::move(task)); lk.unlock(); @@ -238,7 +238,7 @@ class AsyncTaskSchedulerImpl : public AsyncTaskScheduler { void ContinueTasksUnlocked(std::unique_lock&& lk) { while (!queue_->Empty()) { int next_cost = queue_->Peek().cost(); - util::optional> maybe_backoff = throttle_->TryAcquire(next_cost); + std::optional> maybe_backoff = throttle_->TryAcquire(next_cost); if (maybe_backoff) { lk.unlock(); if (!maybe_backoff->TryAddCallback([this] { diff --git a/cpp/src/arrow/util/async_util.h b/cpp/src/arrow/util/async_util.h index 653654668fd97..707f70d471fab 100644 --- a/cpp/src/arrow/util/async_util.h +++ b/cpp/src/arrow/util/async_util.h @@ -140,7 +140,7 @@ class ARROW_EXPORT AsyncTaskScheduler { /// acquired and the caller can proceed. If a future is returned then the caller /// should wait for the future to complete first. When the returned future completes /// the permits have NOT been acquired and the caller must call Acquire again - virtual util::optional> TryAcquire(int amt) = 0; + virtual std::optional> TryAcquire(int amt) = 0; /// Release amt permits /// /// This will possibly complete waiting futures and should probably not be diff --git a/cpp/src/arrow/util/async_util_test.cc b/cpp/src/arrow/util/async_util_test.cc index 25a3ca77cea1f..dfb688f70d175 100644 --- a/cpp/src/arrow/util/async_util_test.cc +++ b/cpp/src/arrow/util/async_util_test.cc @@ -200,9 +200,9 @@ TEST(AsyncTaskScheduler, SubSchedulerNoTasks) { class CustomThrottle : public AsyncTaskScheduler::Throttle { public: - virtual util::optional> TryAcquire(int amt) { + virtual std::optional> TryAcquire(int amt) { if (gate_.is_finished()) { - return nullopt; + return std::nullopt; } else { return gate_; } diff --git a/cpp/src/arrow/util/cancel_test.cc b/cpp/src/arrow/util/cancel_test.cc index b9bf94ba43a56..bca78034c04df 100644 --- a/cpp/src/arrow/util/cancel_test.cc +++ b/cpp/src/arrow/util/cancel_test.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -35,7 +36,6 @@ #include "arrow/util/future.h" #include "arrow/util/io_util.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" namespace arrow { @@ -100,7 +100,7 @@ TEST_F(CancelTest, Unstoppable) { TEST_F(CancelTest, SourceVanishes) { { - util::optional source{StopSource()}; + std::optional source{StopSource()}; StopToken token = source->token(); ASSERT_FALSE(token.IsStopRequested()); ASSERT_OK(token.Poll()); @@ -110,7 +110,7 @@ TEST_F(CancelTest, SourceVanishes) { ASSERT_OK(token.Poll()); } { - util::optional source{StopSource()}; + std::optional source{StopSource()}; StopToken token = source->token(); source->RequestStop(); @@ -125,7 +125,7 @@ static void noop_signal_handler(int signum) { } #ifndef _WIN32 -static util::optional signal_stop_source; +static std::optional signal_stop_source; static void signal_handler(int signum) { signal_stop_source->RequestStopFromSignal(signum); @@ -207,8 +207,8 @@ class SignalCancelTest : public CancelTest { #else const int expected_signal_ = SIGALRM; #endif - util::optional guard_; - util::optional stop_token_; + std::optional guard_; + std::optional stop_token_; }; TEST_F(SignalCancelTest, Register) { diff --git a/cpp/src/arrow/util/cpu_info.cc b/cpp/src/arrow/util/cpu_info.cc index fbe55aec0c157..9bc33f0457063 100644 --- a/cpp/src/arrow/util/cpu_info.cc +++ b/cpp/src/arrow/util/cpu_info.cc @@ -41,13 +41,13 @@ #include #include #include +#include #include #include #include "arrow/result.h" #include "arrow/util/io_util.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/string.h" #undef CPUINFO_ARCH_X86 @@ -226,7 +226,7 @@ void OsRetrieveCpuInfo(int64_t* hardware_flags, CpuInfo::Vendor* vendor, #elif defined(__APPLE__) //------------------------------ MACOS ------------------------------// -util::optional IntegerSysCtlByName(const char* name) { +std::optional IntegerSysCtlByName(const char* name) { size_t len = sizeof(int64_t); int64_t data = 0; if (sysctlbyname(name, &data, &len, nullptr, 0) == 0) { @@ -238,7 +238,7 @@ util::optional IntegerSysCtlByName(const char* name) { auto st = IOErrorFromErrno(errno, "sysctlbyname failed for '", name, "'"); ARROW_LOG(WARNING) << st.ToString(); } - return util::nullopt; + return std::nullopt; } void OsRetrieveCacheSize(std::array* cache_sizes) { diff --git a/cpp/src/arrow/util/future.h b/cpp/src/arrow/util/future.h index 3be4e334b14da..7fc0d5063f66d 100644 --- a/cpp/src/arrow/util/future.h +++ b/cpp/src/arrow/util/future.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include "arrow/util/config.h" #include "arrow/util/functional.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" #include "arrow/util/tracing.h" #include "arrow/util/type_fwd.h" #include "arrow/util/visibility.h" @@ -781,18 +781,18 @@ Future<> AllFinished(const std::vector>& futures); struct Continue { template - operator util::optional() && { // NOLINT explicit + operator std::optional() && { // NOLINT explicit return {}; } }; template -util::optional Break(T break_value = {}) { - return util::optional{std::move(break_value)}; +std::optional Break(T break_value = {}) { + return std::optional{std::move(break_value)}; } template -using ControlFlow = util::optional; +using ControlFlow = std::optional; /// \brief Loop through an asynchronous sequence /// diff --git a/cpp/src/arrow/util/io_util_test.cc b/cpp/src/arrow/util/io_util_test.cc index 57c75fff3c7d3..f4fcc26d07201 100644 --- a/cpp/src/arrow/util/io_util_test.cc +++ b/cpp/src/arrow/util/io_util_test.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,6 @@ #include "arrow/util/cpu_info.h" #include "arrow/util/io_util.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/windows_compatibility.h" #include "arrow/util/windows_fixup.h" diff --git a/cpp/src/arrow/util/iterator.h b/cpp/src/arrow/util/iterator.h index 2f42803d26ff3..0eae7f6a8571b 100644 --- a/cpp/src/arrow/util/iterator.h +++ b/cpp/src/arrow/util/iterator.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "arrow/util/compare.h" #include "arrow/util/functional.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" #include "arrow/util/visibility.h" namespace arrow { @@ -66,16 +66,16 @@ bool IsIterationEnd(const T& val) { } template -struct IterationTraits> { +struct IterationTraits> { /// \brief by default when iterating through a sequence of optional, /// nullopt indicates the end of iteration. /// Specialize IterationTraits if different end semantics are required. - static util::optional End() { return util::nullopt; } + static std::optional End() { return std::nullopt; } /// \brief by default when iterating through a sequence of optional, /// nullopt (!has_value()) indicates the end of iteration. /// Specialize IterationTraits if different end semantics are required. - static bool IsEnd(const util::optional& val) { return !val.has_value(); } + static bool IsEnd(const std::optional& val) { return !val.has_value(); } // TODO(bkietz) The range-for loop over Iterator> yields // Result> which is unnecessary (since only the unyielded end optional @@ -227,7 +227,7 @@ struct TransformFlow { bool finished_ = false; bool ready_for_next_ = false; - util::optional yield_value_; + std::optional yield_value_; }; struct TransformFinish { @@ -263,7 +263,7 @@ class TransformIterator { Result Next() { while (!finished_) { - ARROW_ASSIGN_OR_RAISE(util::optional next, Pump()); + ARROW_ASSIGN_OR_RAISE(std::optional next, Pump()); if (next.has_value()) { return std::move(*next); } @@ -278,7 +278,7 @@ class TransformIterator { // * If an invalid status is encountered that will be returned // * If finished it will return IterationTraits::End() // * If a value is returned by the transformer that will be returned - Result> Pump() { + Result> Pump() { if (!finished_ && last_value_.has_value()) { auto next_res = transformer_(*last_value_); if (!next_res.ok()) { @@ -302,12 +302,12 @@ class TransformIterator { if (finished_) { return IterationTraits::End(); } - return util::nullopt; + return std::nullopt; } Iterator it_; Transformer transformer_; - util::optional last_value_; + std::optional last_value_; bool finished_ = false; }; diff --git a/cpp/src/arrow/util/optional.h b/cpp/src/arrow/util/optional.h deleted file mode 100644 index e1c32e7613428..0000000000000 --- a/cpp/src/arrow/util/optional.h +++ /dev/null @@ -1,35 +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 - -#define optional_CONFIG_SELECT_OPTIONAL optional_OPTIONAL_NONSTD - -#include "arrow/vendored/optional.hpp" // IWYU pragma: export - -namespace arrow { -namespace util { - -template -using optional = nonstd::optional; - -using nonstd::bad_optional_access; -using nonstd::make_optional; -using nonstd::nullopt; - -} // namespace util -} // namespace arrow diff --git a/cpp/src/arrow/util/reflection_test.cc b/cpp/src/arrow/util/reflection_test.cc index fb3d3b8fb028a..8ca9077ddc679 100644 --- a/cpp/src/arrow/util/reflection_test.cc +++ b/cpp/src/arrow/util/reflection_test.cc @@ -79,7 +79,7 @@ struct FromStringImpl { props.ForEach(*this); } - void Fail() { obj_ = util::nullopt; } + void Fail() { obj_ = std::nullopt; } void Init(util::string_view class_name, util::string_view repr, size_t num_properties) { if (!repr.starts_with(class_name)) return Fail(); @@ -116,7 +116,7 @@ struct FromStringImpl { prop.set(&*obj_, std::move(value)); } - util::optional obj_ = Class{}; + std::optional obj_ = Class{}; std::vector members_; }; @@ -146,7 +146,7 @@ std::string ToString(const Person& obj) { void PrintTo(const Person& obj, std::ostream* os) { *os << ToString(obj); } -util::optional PersonFromString(util::string_view repr) { +std::optional PersonFromString(util::string_view repr) { return FromStringImpl("Person", repr, kPersonProperties).obj_; } @@ -174,23 +174,23 @@ TEST(Reflection, FromStringToDataMembers) { EXPECT_EQ(PersonFromString(ToString(genos)), genos); - EXPECT_EQ(PersonFromString(""), util::nullopt); - EXPECT_EQ(PersonFromString("Per"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{age:19,name:Genos"), util::nullopt); + EXPECT_EQ(PersonFromString(""), std::nullopt); + EXPECT_EQ(PersonFromString("Per"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{age:19,name:Genos"), std::nullopt); - EXPECT_EQ(PersonFromString("Person{name:Genos"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{age:19,name:Genos,extra:Cyborg}"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{name:Genos,age:19"), util::nullopt); + EXPECT_EQ(PersonFromString("Person{name:Genos"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{age:19,name:Genos,extra:Cyborg}"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{name:Genos,age:19"), std::nullopt); - EXPECT_EQ(PersonFromString("Fake{age:19,name:Genos}"), util::nullopt); + EXPECT_EQ(PersonFromString("Fake{age:19,name:Genos}"), std::nullopt); - EXPECT_EQ(PersonFromString("Person{age,name:Genos}"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{age:nineteen,name:Genos}"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{age:19 ,name:Genos}"), util::nullopt); - EXPECT_EQ(PersonFromString("Person{age:19,moniker:Genos}"), util::nullopt); + EXPECT_EQ(PersonFromString("Person{age,name:Genos}"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{age:nineteen,name:Genos}"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{age:19 ,name:Genos}"), std::nullopt); + EXPECT_EQ(PersonFromString("Person{age:19,moniker:Genos}"), std::nullopt); - EXPECT_EQ(PersonFromString("Person{age: 19, name: Genos}"), util::nullopt); + EXPECT_EQ(PersonFromString("Person{age: 19, name: Genos}"), std::nullopt); } enum class PersonType : int8_t { diff --git a/cpp/src/arrow/util/string.cc b/cpp/src/arrow/util/string.cc index 00ab8e64c4757..09df881a9b078 100644 --- a/cpp/src/arrow/util/string.cc +++ b/cpp/src/arrow/util/string.cc @@ -182,11 +182,11 @@ std::string AsciiToUpper(util::string_view value) { return result; } -util::optional Replace(util::string_view s, util::string_view token, - util::string_view replacement) { +std::optional Replace(util::string_view s, util::string_view token, + util::string_view replacement) { size_t token_start = s.find(token); if (token_start == std::string::npos) { - return util::nullopt; + return std::nullopt; } return s.substr(0, token_start).to_string() + replacement.to_string() + s.substr(token_start + token.size()).to_string(); diff --git a/cpp/src/arrow/util/string.h b/cpp/src/arrow/util/string.h index b2baa0ebedaaf..fd9a3d1e06366 100644 --- a/cpp/src/arrow/util/string.h +++ b/cpp/src/arrow/util/string.h @@ -17,11 +17,11 @@ #pragma once +#include #include #include #include "arrow/result.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" #include "arrow/util/visibility.h" @@ -74,8 +74,8 @@ std::string AsciiToUpper(util::string_view value); /// \brief Search for the first instance of a token and replace it or return nullopt if /// the token is not found. ARROW_EXPORT -util::optional Replace(util::string_view s, util::string_view token, - util::string_view replacement); +std::optional Replace(util::string_view s, util::string_view token, + util::string_view replacement); /// \brief Get boolean value from string /// diff --git a/cpp/src/arrow/util/task_group.cc b/cpp/src/arrow/util/task_group.cc index 0679b6ef1f688..96b7fbb8b3bf6 100644 --- a/cpp/src/arrow/util/task_group.cc +++ b/cpp/src/arrow/util/task_group.cc @@ -207,7 +207,7 @@ class ThreadedTaskGroup : public TaskGroup { std::mutex mutex_; std::condition_variable cv_; Status status_; - util::optional> completion_future_; + std::optional> completion_future_; }; } // namespace diff --git a/cpp/src/arrow/vendored/optional.hpp b/cpp/src/arrow/vendored/optional.hpp deleted file mode 100644 index e266bb20be2ef..0000000000000 --- a/cpp/src/arrow/vendored/optional.hpp +++ /dev/null @@ -1,1553 +0,0 @@ -// Vendored from git tag v3.2.0 - -// Copyright (c) 2014-2018 Martin Moene -// -// https://github.com/martinmoene/optional-lite -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#ifndef NONSTD_OPTIONAL_LITE_HPP -#define NONSTD_OPTIONAL_LITE_HPP - -#define optional_lite_MAJOR 3 -#define optional_lite_MINOR 2 -#define optional_lite_PATCH 0 - -#define optional_lite_VERSION optional_STRINGIFY(optional_lite_MAJOR) "." optional_STRINGIFY(optional_lite_MINOR) "." optional_STRINGIFY(optional_lite_PATCH) - -#define optional_STRINGIFY( x ) optional_STRINGIFY_( x ) -#define optional_STRINGIFY_( x ) #x - -// optional-lite configuration: - -#define optional_OPTIONAL_DEFAULT 0 -#define optional_OPTIONAL_NONSTD 1 -#define optional_OPTIONAL_STD 2 - -#if !defined( optional_CONFIG_SELECT_OPTIONAL ) -# define optional_CONFIG_SELECT_OPTIONAL ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD ) -#endif - -// Control presence of exception handling (try and auto discover): - -#ifndef optional_CONFIG_NO_EXCEPTIONS -# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) -# define optional_CONFIG_NO_EXCEPTIONS 0 -# else -# define optional_CONFIG_NO_EXCEPTIONS 1 -# endif -#endif - -// C++ language version detection (C++20 is speculative): -// Note: VC14.0/1900 (VS2015) lacks too much from C++14. - -#ifndef optional_CPLUSPLUS -# if defined(_MSVC_LANG ) && !defined(__clang__) -# define optional_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) -# else -# define optional_CPLUSPLUS __cplusplus -# endif -#endif - -#define optional_CPP98_OR_GREATER ( optional_CPLUSPLUS >= 199711L ) -#define optional_CPP11_OR_GREATER ( optional_CPLUSPLUS >= 201103L ) -#define optional_CPP11_OR_GREATER_ ( optional_CPLUSPLUS >= 201103L ) -#define optional_CPP14_OR_GREATER ( optional_CPLUSPLUS >= 201402L ) -#define optional_CPP17_OR_GREATER ( optional_CPLUSPLUS >= 201703L ) -#define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202000L ) - -// C++ language version (represent 98 as 3): - -#define optional_CPLUSPLUS_V ( optional_CPLUSPLUS / 100 - (optional_CPLUSPLUS > 200000 ? 2000 : 1994) ) - -// Use C++17 std::optional if available and requested: - -#if optional_CPP17_OR_GREATER && defined(__has_include ) -# if __has_include( ) -# define optional_HAVE_STD_OPTIONAL 1 -# else -# define optional_HAVE_STD_OPTIONAL 0 -# endif -#else -# define optional_HAVE_STD_OPTIONAL 0 -#endif - -#define optional_USES_STD_OPTIONAL ( (optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_STD) || ((optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_DEFAULT) && optional_HAVE_STD_OPTIONAL) ) - -// -// in_place: code duplicated in any-lite, expected-lite, optional-lite, value-ptr-lite, variant-lite: -// - -#ifndef nonstd_lite_HAVE_IN_PLACE_TYPES -#define nonstd_lite_HAVE_IN_PLACE_TYPES 1 - -// C++17 std::in_place in : - -#if optional_CPP17_OR_GREATER - -#include - -namespace nonstd { - -using std::in_place; -using std::in_place_type; -using std::in_place_index; -using std::in_place_t; -using std::in_place_type_t; -using std::in_place_index_t; - -#define nonstd_lite_in_place_t( T) std::in_place_t -#define nonstd_lite_in_place_type_t( T) std::in_place_type_t -#define nonstd_lite_in_place_index_t(K) std::in_place_index_t - -#define nonstd_lite_in_place( T) std::in_place_t{} -#define nonstd_lite_in_place_type( T) std::in_place_type_t{} -#define nonstd_lite_in_place_index(K) std::in_place_index_t{} - -} // namespace nonstd - -#else // optional_CPP17_OR_GREATER - -#include - -namespace nonstd { -namespace detail { - -template< class T > -struct in_place_type_tag {}; - -template< std::size_t K > -struct in_place_index_tag {}; - -} // namespace detail - -struct in_place_t {}; - -template< class T > -inline in_place_t in_place( detail::in_place_type_tag /*unused*/ = detail::in_place_type_tag() ) -{ - return in_place_t(); -} - -template< std::size_t K > -inline in_place_t in_place( detail::in_place_index_tag /*unused*/ = detail::in_place_index_tag() ) -{ - return in_place_t(); -} - -template< class T > -inline in_place_t in_place_type( detail::in_place_type_tag /*unused*/ = detail::in_place_type_tag() ) -{ - return in_place_t(); -} - -template< std::size_t K > -inline in_place_t in_place_index( detail::in_place_index_tag /*unused*/ = detail::in_place_index_tag() ) -{ - return in_place_t(); -} - -// mimic templated typedef: - -#define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag ) -#define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag ) -#define nonstd_lite_in_place_index_t(K) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag ) - -#define nonstd_lite_in_place( T) nonstd::in_place_type -#define nonstd_lite_in_place_type( T) nonstd::in_place_type -#define nonstd_lite_in_place_index(K) nonstd::in_place_index - -} // namespace nonstd - -#endif // optional_CPP17_OR_GREATER -#endif // nonstd_lite_HAVE_IN_PLACE_TYPES - -// -// Using std::optional: -// - -#if optional_USES_STD_OPTIONAL - -#include - -namespace nonstd { - - using std::optional; - using std::bad_optional_access; - using std::hash; - - using std::nullopt; - using std::nullopt_t; - - using std::operator==; - using std::operator!=; - using std::operator<; - using std::operator<=; - using std::operator>; - using std::operator>=; - using std::make_optional; - using std::swap; -} - -#else // optional_USES_STD_OPTIONAL - -#include -#include - -// optional-lite alignment configuration: - -#ifndef optional_CONFIG_MAX_ALIGN_HACK -# define optional_CONFIG_MAX_ALIGN_HACK 0 -#endif - -#ifndef optional_CONFIG_ALIGN_AS -// no default, used in #if defined() -#endif - -#ifndef optional_CONFIG_ALIGN_AS_FALLBACK -# define optional_CONFIG_ALIGN_AS_FALLBACK double -#endif - -// Compiler warning suppression: - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wundef" -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wundef" -#elif defined(_MSC_VER ) -# pragma warning( push ) -#endif - -// half-open range [lo..hi): -#define optional_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) - -// Compiler versions: -// -// MSVC++ 6.0 _MSC_VER == 1200 (Visual Studio 6.0) -// MSVC++ 7.0 _MSC_VER == 1300 (Visual Studio .NET 2002) -// MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio .NET 2003) -// MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005) -// MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008) -// MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010) -// MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012) -// MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) -// MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) -// MSVC++ 14.1 _MSC_VER >= 1910 (Visual Studio 2017) - -#if defined(_MSC_VER ) && !defined(__clang__) -# define optional_COMPILER_MSVC_VER (_MSC_VER ) -# define optional_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) -#else -# define optional_COMPILER_MSVC_VER 0 -# define optional_COMPILER_MSVC_VERSION 0 -#endif - -#define optional_COMPILER_VERSION( major, minor, patch ) ( 10 * (10 * (major) + (minor) ) + (patch) ) - -#if defined(__GNUC__) && !defined(__clang__) -# define optional_COMPILER_GNUC_VERSION optional_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#else -# define optional_COMPILER_GNUC_VERSION 0 -#endif - -#if defined(__clang__) -# define optional_COMPILER_CLANG_VERSION optional_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) -#else -# define optional_COMPILER_CLANG_VERSION 0 -#endif - -#if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 140 ) -# pragma warning( disable: 4345 ) // initialization behavior changed -#endif - -#if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 150 ) -# pragma warning( disable: 4814 ) // in C++14 'constexpr' will not imply 'const' -#endif - -// Presence of language and library features: - -#define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) - -#ifdef _HAS_CPP0X -# define optional_HAS_CPP0X _HAS_CPP0X -#else -# define optional_HAS_CPP0X 0 -#endif - -// Unless defined otherwise below, consider VC14 as C++11 for optional-lite: - -#if optional_COMPILER_MSVC_VER >= 1900 -# undef optional_CPP11_OR_GREATER -# define optional_CPP11_OR_GREATER 1 -#endif - -#define optional_CPP11_90 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1500) -#define optional_CPP11_100 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1600) -#define optional_CPP11_110 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1700) -#define optional_CPP11_120 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1800) -#define optional_CPP11_140 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1900) -#define optional_CPP11_141 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1910) - -#define optional_CPP14_000 (optional_CPP14_OR_GREATER) -#define optional_CPP17_000 (optional_CPP17_OR_GREATER) - -// Presence of C++11 language features: - -#define optional_HAVE_CONSTEXPR_11 optional_CPP11_140 -#define optional_HAVE_IS_DEFAULT optional_CPP11_140 -#define optional_HAVE_NOEXCEPT optional_CPP11_140 -#define optional_HAVE_NULLPTR optional_CPP11_100 -#define optional_HAVE_REF_QUALIFIER optional_CPP11_140 - -// Presence of C++14 language features: - -#define optional_HAVE_CONSTEXPR_14 optional_CPP14_000 - -// Presence of C++17 language features: - -#define optional_HAVE_NODISCARD optional_CPP17_000 - -// Presence of C++ library features: - -#define optional_HAVE_CONDITIONAL optional_CPP11_120 -#define optional_HAVE_REMOVE_CV optional_CPP11_120 -#define optional_HAVE_TYPE_TRAITS optional_CPP11_90 - -#define optional_HAVE_TR1_TYPE_TRAITS (!! optional_COMPILER_GNUC_VERSION ) -#define optional_HAVE_TR1_ADD_POINTER (!! optional_COMPILER_GNUC_VERSION ) - -// C++ feature usage: - -#if optional_HAVE( CONSTEXPR_11 ) -# define optional_constexpr constexpr -#else -# define optional_constexpr /*constexpr*/ -#endif - -#if optional_HAVE( IS_DEFAULT ) -# define optional_is_default = default; -#else -# define optional_is_default {} -#endif - -#if optional_HAVE( CONSTEXPR_14 ) -# define optional_constexpr14 constexpr -#else -# define optional_constexpr14 /*constexpr*/ -#endif - -#if optional_HAVE( NODISCARD ) -# define optional_nodiscard [[nodiscard]] -#else -# define optional_nodiscard /*[[nodiscard]]*/ -#endif - -#if optional_HAVE( NOEXCEPT ) -# define optional_noexcept noexcept -#else -# define optional_noexcept /*noexcept*/ -#endif - -#if optional_HAVE( NULLPTR ) -# define optional_nullptr nullptr -#else -# define optional_nullptr NULL -#endif - -#if optional_HAVE( REF_QUALIFIER ) -// NOLINTNEXTLINE( bugprone-macro-parentheses ) -# define optional_ref_qual & -# define optional_refref_qual && -#else -# define optional_ref_qual /*&*/ -# define optional_refref_qual /*&&*/ -#endif - -// additional includes: - -#if optional_CONFIG_NO_EXCEPTIONS -// already included: -#else -# include -#endif - -#if optional_CPP11_OR_GREATER -# include -#endif - -#if optional_HAVE( INITIALIZER_LIST ) -# include -#endif - -#if optional_HAVE( TYPE_TRAITS ) -# include -#elif optional_HAVE( TR1_TYPE_TRAITS ) -# include -#endif - -// Method enabling - -#if optional_CPP11_OR_GREATER - -#define optional_REQUIRES_0(...) \ - template< bool B = (__VA_ARGS__), typename std::enable_if::type = 0 > - -#define optional_REQUIRES_T(...) \ - , typename = typename std::enable_if< (__VA_ARGS__), nonstd::optional_lite::detail::enabler >::type - -#define optional_REQUIRES_R(R, ...) \ - typename std::enable_if< (__VA_ARGS__), R>::type - -#define optional_REQUIRES_A(...) \ - , typename std::enable_if< (__VA_ARGS__), void*>::type = nullptr - -#endif - -// -// optional: -// - -namespace nonstd { namespace optional_lite { - -namespace std11 { - -#if optional_CPP11_OR_GREATER - using std::move; -#else - template< typename T > T & move( T & t ) { return t; } -#endif - -#if optional_HAVE( CONDITIONAL ) - using std::conditional; -#else - template< bool B, typename T, typename F > struct conditional { typedef T type; }; - template< typename T, typename F > struct conditional { typedef F type; }; -#endif // optional_HAVE_CONDITIONAL - -} // namespace std11 - -#if optional_CPP11_OR_GREATER - -/// type traits C++17: - -namespace std17 { - -#if optional_CPP17_OR_GREATER - -using std::is_swappable; -using std::is_nothrow_swappable; - -#elif optional_CPP11_OR_GREATER - -namespace detail { - -using std::swap; - -struct is_swappable -{ - template< typename T, typename = decltype( swap( std::declval(), std::declval() ) ) > - static std::true_type test( int /*unused*/ ); - - template< typename > - static std::false_type test(...); -}; - -struct is_nothrow_swappable -{ - // wrap noexcept(expr) in separate function as work-around for VC140 (VS2015): - - template< typename T > - static constexpr bool satisfies() - { - return noexcept( swap( std::declval(), std::declval() ) ); - } - - template< typename T > - static auto test( int /*unused*/ ) -> std::integral_constant()>{} - - template< typename > - static auto test(...) -> std::false_type; -}; - -} // namespace detail - -// is [nothow] swappable: - -template< typename T > -struct is_swappable : decltype( detail::is_swappable::test(0) ){}; - -template< typename T > -struct is_nothrow_swappable : decltype( detail::is_nothrow_swappable::test(0) ){}; - -#endif // optional_CPP17_OR_GREATER - -} // namespace std17 - -/// type traits C++20: - -namespace std20 { - -template< typename T > -struct remove_cvref -{ - typedef typename std::remove_cv< typename std::remove_reference::type >::type type; -}; - -} // namespace std20 - -#endif // optional_CPP11_OR_GREATER - -/// class optional - -template< typename T > -class optional; - -namespace detail { - -// for optional_REQUIRES_T - -#if optional_CPP11_OR_GREATER -enum class enabler{}; -#endif - -// C++11 emulation: - -struct nulltype{}; - -template< typename Head, typename Tail > -struct typelist -{ - typedef Head head; - typedef Tail tail; -}; - -#if optional_CONFIG_MAX_ALIGN_HACK - -// Max align, use most restricted type for alignment: - -#define optional_UNIQUE( name ) optional_UNIQUE2( name, __LINE__ ) -#define optional_UNIQUE2( name, line ) optional_UNIQUE3( name, line ) -#define optional_UNIQUE3( name, line ) name ## line - -#define optional_ALIGN_TYPE( type ) \ - type optional_UNIQUE( _t ); struct_t< type > optional_UNIQUE( _st ) - -template< typename T > -struct struct_t { T _; }; - -union max_align_t -{ - optional_ALIGN_TYPE( char ); - optional_ALIGN_TYPE( short int ); - optional_ALIGN_TYPE( int ); - optional_ALIGN_TYPE( long int ); - optional_ALIGN_TYPE( float ); - optional_ALIGN_TYPE( double ); - optional_ALIGN_TYPE( long double ); - optional_ALIGN_TYPE( char * ); - optional_ALIGN_TYPE( short int * ); - optional_ALIGN_TYPE( int * ); - optional_ALIGN_TYPE( long int * ); - optional_ALIGN_TYPE( float * ); - optional_ALIGN_TYPE( double * ); - optional_ALIGN_TYPE( long double * ); - optional_ALIGN_TYPE( void * ); - -#ifdef HAVE_LONG_LONG - optional_ALIGN_TYPE( long long ); -#endif - - struct Unknown; - - Unknown ( * optional_UNIQUE(_) )( Unknown ); - Unknown * Unknown::* optional_UNIQUE(_); - Unknown ( Unknown::* optional_UNIQUE(_) )( Unknown ); - - struct_t< Unknown ( * )( Unknown) > optional_UNIQUE(_); - struct_t< Unknown * Unknown::* > optional_UNIQUE(_); - struct_t< Unknown ( Unknown::* )(Unknown) > optional_UNIQUE(_); -}; - -#undef optional_UNIQUE -#undef optional_UNIQUE2 -#undef optional_UNIQUE3 - -#undef optional_ALIGN_TYPE - -#elif defined( optional_CONFIG_ALIGN_AS ) // optional_CONFIG_MAX_ALIGN_HACK - -// Use user-specified type for alignment: - -#define optional_ALIGN_AS( unused ) \ - optional_CONFIG_ALIGN_AS - -#else // optional_CONFIG_MAX_ALIGN_HACK - -// Determine POD type to use for alignment: - -#define optional_ALIGN_AS( to_align ) \ - typename type_of_size< alignment_types, alignment_of< to_align >::value >::type - -template< typename T > -struct alignment_of; - -template< typename T > -struct alignment_of_hack -{ - char c; - T t; - alignment_of_hack(); -}; - -template< size_t A, size_t S > -struct alignment_logic -{ - enum { value = A < S ? A : S }; -}; - -template< typename T > -struct alignment_of -{ - enum { value = alignment_logic< - sizeof( alignment_of_hack ) - sizeof(T), sizeof(T) >::value }; -}; - -template< typename List, size_t N > -struct type_of_size -{ - typedef typename std11::conditional< - N == sizeof( typename List::head ), - typename List::head, - typename type_of_size::type >::type type; -}; - -template< size_t N > -struct type_of_size< nulltype, N > -{ - typedef optional_CONFIG_ALIGN_AS_FALLBACK type; -}; - -template< typename T> -struct struct_t { T _; }; - -#define optional_ALIGN_TYPE( type ) \ - typelist< type , typelist< struct_t< type > - -struct Unknown; - -typedef - optional_ALIGN_TYPE( char ), - optional_ALIGN_TYPE( short ), - optional_ALIGN_TYPE( int ), - optional_ALIGN_TYPE( long), optional_ALIGN_TYPE(float), optional_ALIGN_TYPE(double), - optional_ALIGN_TYPE(long double), - - optional_ALIGN_TYPE(char*), optional_ALIGN_TYPE(short*), optional_ALIGN_TYPE(int*), - optional_ALIGN_TYPE(long*), optional_ALIGN_TYPE(float*), optional_ALIGN_TYPE(double*), - optional_ALIGN_TYPE(long double*), - - optional_ALIGN_TYPE(Unknown (*)(Unknown)), optional_ALIGN_TYPE(Unknown* Unknown::*), - optional_ALIGN_TYPE(Unknown (Unknown::*)(Unknown)), - - nulltype >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> alignment_types; - -#undef optional_ALIGN_TYPE - -#endif // optional_CONFIG_MAX_ALIGN_HACK - -/// C++03 constructed union to hold value. - -template -union storage_t { - // private: - // template< typename > friend class optional; - - typedef T value_type; - - storage_t() optional_is_default - - explicit storage_t(value_type const& v) { - construct_value(v); - } - - void construct_value(value_type const& v) { ::new (value_ptr()) value_type(v); } - -#if optional_CPP11_OR_GREATER - - explicit storage_t(value_type&& v) { construct_value(std::move(v)); } - - void construct_value(value_type&& v) { ::new (value_ptr()) value_type(std::move(v)); } - - template - void emplace(Args&&... args) { - ::new (value_ptr()) value_type(std::forward(args)...); - } - - template - void emplace(std::initializer_list il, Args&&... args) { - ::new (value_ptr()) value_type(il, std::forward(args)...); - } - -#endif - - void destruct_value() { value_ptr()->~T(); } - - optional_nodiscard value_type const* value_ptr() const { return as(); } - - value_type* value_ptr() { return as(); } - - optional_nodiscard value_type const& value() const optional_ref_qual { - return *value_ptr(); - } - - value_type& value() optional_ref_qual { return *value_ptr(); } - -#if optional_CPP11_OR_GREATER - - optional_nodiscard value_type const&& value() const optional_refref_qual { - return std::move(value()); - } - - value_type&& value() optional_refref_qual { return std::move(value()); } - -#endif - -#if optional_CPP11_OR_GREATER - - using aligned_storage_t = - typename std::aligned_storage::type; - aligned_storage_t data; - -#elif optional_CONFIG_MAX_ALIGN_HACK - - typedef struct { - unsigned char data[sizeof(value_type)]; - } aligned_storage_t; - - max_align_t hack; - aligned_storage_t data; - -#else - typedef optional_ALIGN_AS(value_type) align_as_type; - - typedef struct { - align_as_type data[1 + (sizeof(value_type) - 1) / sizeof(align_as_type)]; - } aligned_storage_t; - aligned_storage_t data; - -#undef optional_ALIGN_AS - -#endif // optional_CONFIG_MAX_ALIGN_HACK - - optional_nodiscard void* ptr() optional_noexcept { return &data; } - - optional_nodiscard void const* ptr() const optional_noexcept { return &data; } - - template - optional_nodiscard U* as() { - return reinterpret_cast(ptr()); - } - - template - optional_nodiscard U const* as() const { - return reinterpret_cast(ptr()); - } -}; - -} // namespace detail - -/// disengaged state tag - -struct nullopt_t { - struct init {}; - explicit optional_constexpr nullopt_t(init /*unused*/) optional_noexcept {} -}; - -#if optional_HAVE(CONSTEXPR_11) -constexpr nullopt_t nullopt{nullopt_t::init{}}; -#else -// extra parenthesis to prevent the most vexing parse: -const nullopt_t nullopt((nullopt_t::init())); -#endif - -/// optional access error - -#if !optional_CONFIG_NO_EXCEPTIONS - -class bad_optional_access : public std::logic_error { - public: - explicit bad_optional_access() : logic_error("bad optional access") {} -}; - -#endif // optional_CONFIG_NO_EXCEPTIONS - -/// optional - -template -class optional { - private: - template - friend class optional; - - typedef void (optional::*safe_bool)() const; - - public: - typedef T value_type; - - // x.x.3.1, constructors - - // 1a - default construct - optional_constexpr optional() optional_noexcept : has_value_(false), contained() {} - - // 1b - construct explicitly empty - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional_constexpr optional(nullopt_t /*unused*/) optional_noexcept : has_value_(false), - contained() {} - - // 2 - copy-construct - optional_constexpr14 optional( - optional const& other -#if optional_CPP11_OR_GREATER - optional_REQUIRES_A(true || std::is_copy_constructible::value) -#endif - ) - : has_value_(other.has_value()) { - if (other.has_value()) { - contained.construct_value(other.contained.value()); - } - } - -#if optional_CPP11_OR_GREATER - - // 3 (C++11) - move-construct from optional - optional_constexpr14 optional( - optional&& other optional_REQUIRES_A(true || std::is_move_constructible::value) - // NOLINTNEXTLINE( performance-noexcept-move-constructor ) - ) noexcept(std::is_nothrow_move_constructible::value) - : has_value_(other.has_value()) { - if (other.has_value()) { - contained.construct_value(std::move(other.contained.value())); - } - } - - // 4a (C++11) - explicit converting copy-construct from optional - template - explicit optional(optional const& other optional_REQUIRES_A( - std::is_constructible::value && - !std::is_constructible&>::value && - !std::is_constructible&&>::value && - !std::is_constructible const&>::value && - !std::is_constructible const&&>::value && - !std::is_convertible&, T>::value && - !std::is_convertible&&, T>::value && - !std::is_convertible const&, T>::value && - !std::is_convertible const&&, T>::value && - !std::is_convertible::value /*=> explicit */ - )) - : has_value_(other.has_value()) { - if (other.has_value()) { - contained.construct_value(T{other.contained.value()}); - } - } -#endif // optional_CPP11_OR_GREATER - - // 4b (C++98 and later) - non-explicit converting copy-construct from optional - template - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional( - optional const& other -#if optional_CPP11_OR_GREATER - optional_REQUIRES_A(std::is_constructible::value && - !std::is_constructible&>::value && - !std::is_constructible&&>::value && - !std::is_constructible const&>::value && - !std::is_constructible const&&>::value && - !std::is_convertible&, T>::value && - !std::is_convertible&&, T>::value && - !std::is_convertible const&, T>::value && - !std::is_convertible const&&, T>::value && - std::is_convertible::value /*=> non-explicit */ - ) -#endif // optional_CPP11_OR_GREATER - ) - : has_value_(other.has_value()) { - if (other.has_value()) { - contained.construct_value(other.contained.value()); - } - } - -#if optional_CPP11_OR_GREATER - - // 5a (C++11) - explicit converting move-construct from optional - template - explicit optional(optional&& other optional_REQUIRES_A( - std::is_constructible::value && - !std::is_constructible&>::value && - !std::is_constructible&&>::value && - !std::is_constructible const&>::value && - !std::is_constructible const&&>::value && - !std::is_convertible&, T>::value && - !std::is_convertible&&, T>::value && - !std::is_convertible const&, T>::value && - !std::is_convertible const&&, T>::value && - !std::is_convertible::value /*=> explicit */ - )) - : has_value_(other.has_value()) { - if (other.has_value()) { - contained.construct_value(T{std::move(other.contained.value())}); - } - } - - // 5a (C++11) - non-explicit converting move-construct from optional - template - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional(optional&& other optional_REQUIRES_A( - std::is_constructible::value && - !std::is_constructible&>::value && - !std::is_constructible&&>::value && - !std::is_constructible const&>::value && - !std::is_constructible const&&>::value && - !std::is_convertible&, T>::value && - !std::is_convertible&&, T>::value && - !std::is_convertible const&, T>::value && - !std::is_convertible const&&, T>::value && - std::is_convertible::value /*=> non-explicit */ - )) - : has_value_(other.has_value()) { - if (other.has_value()) { - contained.construct_value(std::move(other.contained.value())); - } - } - - // 6 (C++11) - in-place construct - template < - typename... Args optional_REQUIRES_T(std::is_constructible::value)> - optional_constexpr explicit optional(nonstd_lite_in_place_t(T), Args&&... args) - : has_value_(true), contained(T(std::forward(args)...)) {} - - // 7 (C++11) - in-place construct, initializer-list - template &, Args&&...>::value)> - optional_constexpr explicit optional(nonstd_lite_in_place_t(T), - std::initializer_list il, Args&&... args) - : has_value_(true), contained(T(il, std::forward(args)...)) {} - - // 8a (C++11) - explicit move construct from value - template - optional_constexpr explicit optional(U&& value optional_REQUIRES_A( - std::is_constructible::value && - !std::is_same::type, - nonstd_lite_in_place_t(U)>::value && - !std::is_same::type, optional >::value && - !std::is_convertible::value /*=> explicit */ - )) - : has_value_(true), contained(T{std::forward(value)}) {} - - // 8b (C++11) - non-explicit move construct from value - template - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional_constexpr optional(U&& value optional_REQUIRES_A( - std::is_constructible::value && - !std::is_same::type, - nonstd_lite_in_place_t(U)>::value && - !std::is_same::type, optional >::value && - std::is_convertible::value /*=> non-explicit */ - )) - : has_value_(true), contained(std::forward(value)) {} - -#else // optional_CPP11_OR_GREATER - - // 8 (C++98) - optional(value_type const& value) : has_value_(true), contained(value) {} - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.2, destructor - - ~optional() { - if (has_value()) { - contained.destruct_value(); - } - } - - // x.x.3.3, assignment - - // 1 (C++98and later) - assign explicitly empty - optional& operator=(nullopt_t /*unused*/) optional_noexcept { - reset(); - return *this; - } - - // 2 (C++98and later) - copy-assign from optional -#if optional_CPP11_OR_GREATER - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, - // misc-unconventional-assign-operator ) - optional_REQUIRES_R(optional&, true - // std::is_copy_constructible::value - // && std::is_copy_assignable::value - ) - operator=(optional const& other) noexcept( - std::is_nothrow_move_assignable::value&& - std::is_nothrow_move_constructible::value) -#else - optional& operator=(optional const& other) -#endif - { - if ((has_value() == true) && (other.has_value() == false)) { - reset(); - } else if ((has_value() == false) && (other.has_value() == true)) { - initialize(*other); - } else if ((has_value() == true) && (other.has_value() == true)) { - contained.value() = *other; - } - return *this; - } - -#if optional_CPP11_OR_GREATER - - // 3 (C++11) - move-assign from optional - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, - // misc-unconventional-assign-operator ) - optional_REQUIRES_R(optional&, true - // std::is_move_constructible::value - // && std::is_move_assignable::value - ) - operator=(optional&& other) noexcept { - if ((has_value() == true) && (other.has_value() == false)) { - reset(); - } else if ((has_value() == false) && (other.has_value() == true)) { - initialize(std::move(*other)); - } else if ((has_value() == true) && (other.has_value() == true)) { - contained.value() = std::move(*other); - } - return *this; - } - - // 4 (C++11) - move-assign from value - template - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, - // misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional&, - std::is_constructible::value&& std::is_assignable::value && - !std::is_same::type, - nonstd_lite_in_place_t(U)>::value && - !std::is_same::type, optional >::value && - !(std::is_scalar::value && - std::is_same::type>::value)) - operator=(U&& value) { - if (has_value()) { - contained.value() = std::forward(value); - } else { - initialize(T(std::forward(value))); - } - return *this; - } - -#else // optional_CPP11_OR_GREATER - - // 4 (C++98) - copy-assign from value - template - optional& operator=(U const& value) { - if (has_value()) - contained.value() = value; - else - initialize(T(value)); - return *this; - } - -#endif // optional_CPP11_OR_GREATER - - // 5 (C++98 and later) - converting copy-assign from optional - template -#if optional_CPP11_OR_GREATER - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, - // misc-unconventional-assign-operator ) - optional_REQUIRES_R(optional&, - std::is_constructible::value&& - std::is_assignable::value && - !std::is_constructible&>::value && - !std::is_constructible&&>::value && - !std::is_constructible const&>::value && - !std::is_constructible const&&>::value && - !std::is_convertible&, T>::value && - !std::is_convertible&&, T>::value && - !std::is_convertible const&, T>::value && - !std::is_convertible const&&, T>::value && - !std::is_assignable&>::value && - !std::is_assignable&&>::value && - !std::is_assignable const&>::value && - !std::is_assignable const&&>::value) -#else - optional& -#endif // optional_CPP11_OR_GREATER - operator=(optional const& other) { - return *this = optional(other); - } - -#if optional_CPP11_OR_GREATER - - // 6 (C++11) - converting move-assign from optional - template - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, - // misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional&, std::is_constructible::value&& std::is_assignable::value && - !std::is_constructible&>::value && - !std::is_constructible&&>::value && - !std::is_constructible const&>::value && - !std::is_constructible const&&>::value && - !std::is_convertible&, T>::value && - !std::is_convertible&&, T>::value && - !std::is_convertible const&, T>::value && - !std::is_convertible const&&, T>::value && - !std::is_assignable&>::value && - !std::is_assignable&&>::value && - !std::is_assignable const&>::value && - !std::is_assignable const&&>::value) - operator=(optional&& other) { - return *this = optional(std::move(other)); - } - - // 7 (C++11) - emplace - template < - typename... Args optional_REQUIRES_T(std::is_constructible::value)> - T& emplace(Args&&... args) { - *this = nullopt; - contained.emplace(std::forward(args)...); - has_value_ = true; - return contained.value(); - } - - // 8 (C++11) - emplace, initializer-list - template &, Args&&...>::value)> - T& emplace(std::initializer_list il, Args&&... args) { - *this = nullopt; - contained.emplace(il, std::forward(args)...); - has_value_ = true; - return contained.value(); - } - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.4, swap - - void swap(optional& other) -#if optional_CPP11_OR_GREATER - noexcept(std::is_nothrow_move_constructible::value&& - std17::is_nothrow_swappable::value) -#endif - { - using std::swap; - if ((has_value() == true) && (other.has_value() == true)) { - swap(**this, *other); - } else if ((has_value() == false) && (other.has_value() == true)) { - initialize(std11::move(*other)); - other.reset(); - } else if ((has_value() == true) && (other.has_value() == false)) { - other.initialize(std11::move(**this)); - reset(); - } - } - - // x.x.3.5, observers - - optional_constexpr value_type const* operator->() const { - return assert(has_value()), contained.value_ptr(); - } - - optional_constexpr14 value_type* operator->() { - return assert(has_value()), contained.value_ptr(); - } - - optional_constexpr value_type const& operator*() const optional_ref_qual { - return assert(has_value()), contained.value(); - } - - optional_constexpr14 value_type& operator*() optional_ref_qual { - return assert(has_value()), contained.value(); - } - -#if optional_HAVE(REF_QUALIFIER) && \ - (!optional_COMPILER_GNUC_VERSION || optional_COMPILER_GNUC_VERSION >= 490) - - optional_constexpr value_type const&& operator*() const optional_refref_qual { - return std::move(**this); - } - - optional_constexpr14 value_type&& operator*() optional_refref_qual { - return std::move(**this); - } - -#endif - -#if optional_CPP11_OR_GREATER - optional_constexpr explicit operator bool() const optional_noexcept { - return has_value(); - } -#else - optional_constexpr operator safe_bool() const optional_noexcept { - return has_value() ? &optional::this_type_does_not_support_comparisons : 0; - } -#endif - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr bool has_value() const optional_noexcept { - return has_value_; - } - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr14 value_type const& value() const - optional_ref_qual { -#if optional_CONFIG_NO_EXCEPTIONS - assert(has_value()); -#else - if (!has_value()) { - throw bad_optional_access(); - } -#endif - return contained.value(); - } - - optional_constexpr14 value_type& value() optional_ref_qual { -#if optional_CONFIG_NO_EXCEPTIONS - assert(has_value()); -#else - if (!has_value()) { - throw bad_optional_access(); - } -#endif - return contained.value(); - } - -#if optional_HAVE(REF_QUALIFIER) && \ - (!optional_COMPILER_GNUC_VERSION || optional_COMPILER_GNUC_VERSION >= 490) - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr value_type const&& value() const - optional_refref_qual { - return std::move(value()); - } - - optional_constexpr14 value_type&& value() optional_refref_qual { - return std::move(value()); - } - -#endif - -#if optional_CPP11_OR_GREATER - - template - optional_constexpr value_type value_or(U&& v) const optional_ref_qual { - return has_value() ? contained.value() : static_cast(std::forward(v)); - } - - template - optional_constexpr14 value_type value_or(U&& v) optional_refref_qual { - return has_value() ? std::move(contained.value()) - : static_cast(std::forward(v)); - } - -#else - - template - optional_constexpr value_type value_or(U const& v) const { - return has_value() ? contained.value() : static_cast(v); - } - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.6, modifiers - - void reset() optional_noexcept { - if (has_value()) { - contained.destruct_value(); - } - - has_value_ = false; - } - - private: - void this_type_does_not_support_comparisons() const {} - - template - void initialize(V const& value) { - assert(!has_value()); - contained.construct_value(value); - has_value_ = true; - } - -#if optional_CPP11_OR_GREATER - template - void initialize(V&& value) { - assert(!has_value()); - contained.construct_value(std::move(value)); - has_value_ = true; - } - -#endif - - private: - bool has_value_; - detail::storage_t contained; -}; - -// Relational operators - -template -inline optional_constexpr bool operator==(optional const& x, optional const& y) { - return bool(x) != bool(y) ? false : !bool(x) ? true : *x == *y; -} - -template -inline optional_constexpr bool operator!=(optional const& x, optional const& y) { - return !(x == y); -} - -template -inline optional_constexpr bool operator<(optional const& x, optional const& y) { - return (!y) ? false : (!x) ? true : *x < *y; -} - -template -inline optional_constexpr bool operator>(optional const& x, optional const& y) { - return (y < x); -} - -template -inline optional_constexpr bool operator<=(optional const& x, optional const& y) { - return !(y < x); -} - -template -inline optional_constexpr bool operator>=(optional const& x, optional const& y) { - return !(x < y); -} - -// Comparison with nullopt - -template -inline optional_constexpr bool operator==(optional const& x, - nullopt_t /*unused*/) optional_noexcept { - return (!x); -} - -template -inline optional_constexpr bool operator==(nullopt_t /*unused*/, - optional const& x) optional_noexcept { - return (!x); -} - -template -inline optional_constexpr bool operator!=(optional const& x, - nullopt_t /*unused*/) optional_noexcept { - return bool(x); -} - -template -inline optional_constexpr bool operator!=(nullopt_t /*unused*/, - optional const& x) optional_noexcept { - return bool(x); -} - -template -inline optional_constexpr bool operator<(optional const& /*unused*/, - nullopt_t /*unused*/) optional_noexcept { - return false; -} - -template -inline optional_constexpr bool operator<(nullopt_t /*unused*/, - optional const& x) optional_noexcept { - return bool(x); -} - -template -inline optional_constexpr bool operator<=(optional const& x, - nullopt_t /*unused*/) optional_noexcept { - return (!x); -} - -template -inline optional_constexpr bool operator<=( - nullopt_t /*unused*/, optional const& /*unused*/) optional_noexcept { - return true; -} - -template -inline optional_constexpr bool operator>(optional const& x, - nullopt_t /*unused*/) optional_noexcept { - return bool(x); -} - -template -inline optional_constexpr bool operator>( - nullopt_t /*unused*/, optional const& /*unused*/) optional_noexcept { - return false; -} - -template -inline optional_constexpr bool operator>=(optional const& /*unused*/, - nullopt_t /*unused*/) optional_noexcept { - return true; -} - -template -inline optional_constexpr bool operator>=(nullopt_t /*unused*/, - optional const& x) optional_noexcept { - return (!x); -} - -// Comparison with T - -template -inline optional_constexpr bool operator==(optional const& x, U const& v) { - return bool(x) ? *x == v : false; -} - -template -inline optional_constexpr bool operator==(U const& v, optional const& x) { - return bool(x) ? v == *x : false; -} - -template -inline optional_constexpr bool operator!=(optional const& x, U const& v) { - return bool(x) ? *x != v : true; -} - -template -inline optional_constexpr bool operator!=(U const& v, optional const& x) { - return bool(x) ? v != *x : true; -} - -template -inline optional_constexpr bool operator<(optional const& x, U const& v) { - return bool(x) ? *x < v : true; -} - -template -inline optional_constexpr bool operator<(U const& v, optional const& x) { - return bool(x) ? v < *x : false; -} - -template -inline optional_constexpr bool operator<=(optional const& x, U const& v) { - return bool(x) ? *x <= v : true; -} - -template -inline optional_constexpr bool operator<=(U const& v, optional const& x) { - return bool(x) ? v <= *x : false; -} - -template -inline optional_constexpr bool operator>(optional const& x, U const& v) { - return bool(x) ? *x > v : false; -} - -template -inline optional_constexpr bool operator>(U const& v, optional const& x) { - return bool(x) ? v > *x : true; -} - -template -inline optional_constexpr bool operator>=(optional const& x, U const& v) { - return bool(x) ? *x >= v : false; -} - -template -inline optional_constexpr bool operator>=(U const& v, optional const& x) { - return bool(x) ? v >= *x : true; -} - -// Specialized algorithms - -template ::value&& std17::is_swappable::value) -#endif - > -void swap(optional& x, optional& y) -#if optional_CPP11_OR_GREATER - noexcept(noexcept(x.swap(y))) -#endif -{ - x.swap(y); -} - -#if optional_CPP11_OR_GREATER - -template -optional_constexpr optional::type> make_optional(T&& value) { - return optional::type>(std::forward(value)); -} - -template -optional_constexpr optional make_optional(Args&&... args) { - return optional(nonstd_lite_in_place(T), std::forward(args)...); -} - -template -optional_constexpr optional make_optional(std::initializer_list il, - Args&&... args) { - return optional(nonstd_lite_in_place(T), il, std::forward(args)...); -} - -#else - -template -optional make_optional(T const& value) { - return optional(value); -} - -#endif // optional_CPP11_OR_GREATER - -} // namespace optional_lite - -using optional_lite::bad_optional_access; -using optional_lite::nullopt; -using optional_lite::nullopt_t; -using optional_lite::optional; - -using optional_lite::make_optional; - -} // namespace nonstd - -#if optional_CPP11_OR_GREATER - -// specialize the std::hash algorithm: - -namespace std { - -template -struct hash > { - public: - std::size_t operator()(nonstd::optional const& v) const optional_noexcept { - return bool(v) ? std::hash{}(*v) : 0; - } -}; - -} // namespace std - -#endif // optional_CPP11_OR_GREATER - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#elif defined(_MSC_VER) -#pragma warning(pop) -#endif - -#endif // optional_USES_STD_OPTIONAL - -#endif // NONSTD_OPTIONAL_LITE_HPP diff --git a/cpp/src/gandiva/cache.h b/cpp/src/gandiva/cache.h index 8b80ff8c5e895..7cff9b02692ae 100644 --- a/cpp/src/gandiva/cache.h +++ b/cpp/src/gandiva/cache.h @@ -39,10 +39,10 @@ class Cache { Cache() : Cache(GetCapacity()) {} ValueType GetObjectCode(const KeyType& cache_key) { - arrow::util::optional result; + std::optional result; std::lock_guard lock(mtx_); result = cache_.get(cache_key); - return result != arrow::util::nullopt ? *result : nullptr; + return result != std::nullopt ? *result : nullptr; } void PutObjectCode(const KeyType& cache_key, const ValueType& module) { diff --git a/cpp/src/gandiva/lru_cache.h b/cpp/src/gandiva/lru_cache.h index 6602116b0a06b..2fa7ccfbfe568 100644 --- a/cpp/src/gandiva/lru_cache.h +++ b/cpp/src/gandiva/lru_cache.h @@ -18,11 +18,10 @@ #pragma once #include +#include #include #include -#include "arrow/util/optional.h" - // modified from boost LRU cache -> the boost cache supported only an // ordered map. namespace gandiva { @@ -70,12 +69,12 @@ class LruCache { } } - arrow::util::optional get(const key_type& key) { + std::optional get(const key_type& key) { // lookup value in the cache typename map_type::iterator value_for_key = map_.find(key); if (value_for_key == map_.end()) { // value not in cache - return arrow::util::nullopt; + return std::nullopt; } // return the value, but first update its place in the most diff --git a/cpp/src/gandiva/lru_cache_test.cc b/cpp/src/gandiva/lru_cache_test.cc index 06c86d6903249..ccd5867b32270 100644 --- a/cpp/src/gandiva/lru_cache_test.cc +++ b/cpp/src/gandiva/lru_cache_test.cc @@ -50,7 +50,7 @@ TEST_F(TestLruCache, TestEvict) { cache_.insert(TestCacheKey(3), "hello"); // should have evicted key 1 ASSERT_EQ(2, cache_.size()); - ASSERT_EQ(cache_.get(TestCacheKey(1)), arrow::util::nullopt); + ASSERT_EQ(cache_.get(TestCacheKey(1)), std::nullopt); } TEST_F(TestLruCache, TestLruBehavior) { diff --git a/cpp/src/parquet/level_conversion.cc b/cpp/src/parquet/level_conversion.cc index ffdca476ddd22..49ae15d6408d4 100644 --- a/cpp/src/parquet/level_conversion.cc +++ b/cpp/src/parquet/level_conversion.cc @@ -18,12 +18,12 @@ #include #include +#include #include "arrow/util/bit_run_reader.h" #include "arrow/util/bit_util.h" #include "arrow/util/cpu_info.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "parquet/exception.h" #include "parquet/level_comparison.h" @@ -36,7 +36,7 @@ namespace internal { namespace { using ::arrow::internal::CpuInfo; -using ::arrow::util::optional; +using ::std::optional; template void DefRepLevelsToListInfo(const int16_t* def_levels, const int16_t* rep_levels, diff --git a/cpp/src/parquet/statistics.cc b/cpp/src/parquet/statistics.cc index 591925554fa06..13d20fcb33df5 100644 --- a/cpp/src/parquet/statistics.cc +++ b/cpp/src/parquet/statistics.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,6 @@ #include "arrow/util/bit_run_reader.h" #include "arrow/util/checked_cast.h" #include "arrow/util/logging.h" -#include "arrow/util/optional.h" #include "arrow/util/ubsan.h" #include "arrow/visit_data_inline.h" #include "parquet/encoding.h" @@ -276,7 +276,7 @@ template struct CompareHelper : public BinaryLikeCompareHelperBase {}; -using ::arrow::util::optional; +using ::std::optional; template ::arrow::enable_if_t::value, optional>> @@ -297,11 +297,11 @@ CleanStatistic(std::pair min_max) { // Ignore if one of the value is nan. if (std::isnan(min) || std::isnan(max)) { - return ::arrow::util::nullopt; + return ::std::nullopt; } if (min == std::numeric_limits::max() && max == std::numeric_limits::lowest()) { - return ::arrow::util::nullopt; + return ::std::nullopt; } T zero{}; @@ -319,7 +319,7 @@ CleanStatistic(std::pair min_max) { optional> CleanStatistic(std::pair min_max) { if (min_max.first.ptr == nullptr || min_max.second.ptr == nullptr) { - return ::arrow::util::nullopt; + return ::std::nullopt; } return min_max; } @@ -327,7 +327,7 @@ optional> CleanStatistic(std::pair min_max) { optional> CleanStatistic( std::pair min_max) { if (min_max.first.ptr == nullptr || min_max.second.ptr == nullptr) { - return ::arrow::util::nullopt; + return ::std::nullopt; } return min_max; } diff --git a/cpp/src/parquet/stream_reader.h b/cpp/src/parquet/stream_reader.h index 806b0e8ad9a22..e16f8ee694c2c 100644 --- a/cpp/src/parquet/stream_reader.h +++ b/cpp/src/parquet/stream_reader.h @@ -22,10 +22,10 @@ #include #include #include +#include #include #include -#include "arrow/util/optional.h" #include "parquet/column_reader.h" #include "parquet/file_reader.h" #include "parquet/stream_writer.h" @@ -44,9 +44,9 @@ namespace parquet { /// Required and optional fields are supported: /// - Required fields are read using operator>>(T) /// - Optional fields are read with -/// operator>>(arrow::util::optional) +/// operator>>(std::optional) /// -/// Note that operator>>(arrow::util::optional) can be used to read +/// Note that operator>>(std::optional) can be used to read /// required fields. /// /// Similarly operator>>(T) can be used to read optional fields. @@ -58,7 +58,7 @@ namespace parquet { class PARQUET_EXPORT StreamReader { public: template - using optional = ::arrow::util::optional; + using optional = ::std::optional; // N.B. Default constructed objects are not usable. This // constructor is provided so that the object may be move diff --git a/cpp/src/parquet/stream_reader_test.cc b/cpp/src/parquet/stream_reader_test.cc index eb7b133740e6f..aa0ff25b10dbe 100644 --- a/cpp/src/parquet/stream_reader_test.cc +++ b/cpp/src/parquet/stream_reader_test.cc @@ -34,7 +34,7 @@ namespace test { template using optional = StreamReader::optional; -using ::arrow::util::nullopt; +using ::std::nullopt; struct TestData { static void init() { std::time(&ts_offset_); } diff --git a/cpp/src/parquet/stream_writer.h b/cpp/src/parquet/stream_writer.h index d0db850c3411d..5801011e16676 100644 --- a/cpp/src/parquet/stream_writer.h +++ b/cpp/src/parquet/stream_writer.h @@ -21,10 +21,10 @@ #include #include #include +#include #include #include -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" #include "parquet/column_writer.h" #include "parquet/file_writer.h" @@ -48,11 +48,11 @@ namespace parquet { /// Required and optional fields are supported: /// - Required fields are written using operator<<(T) /// - Optional fields are written using -/// operator<<(arrow::util::optional). +/// operator<<(std::optional). /// /// Note that operator<<(T) can be used to write optional fields. /// -/// Similarly, operator<<(arrow::util::optional) can be used to +/// Similarly, operator<<(std::optional) can be used to /// write required fields. However if the optional parameter does not /// have a value (i.e. it is nullopt) then a ParquetException will be /// raised. @@ -62,7 +62,7 @@ namespace parquet { class PARQUET_EXPORT StreamWriter { public: template - using optional = ::arrow::util::optional; + using optional = ::std::optional; // N.B. Default constructed objects are not usable. This // constructor is provided so that the object may be move diff --git a/dev/release/verify-release-candidate.sh b/dev/release/verify-release-candidate.sh index b016988ba91a7..73fdd53b8f27c 100755 --- a/dev/release/verify-release-candidate.sh +++ b/dev/release/verify-release-candidate.sh @@ -1039,7 +1039,7 @@ test_macos_wheels() { local check_flight=OFF else local python_versions="3.7m 3.8 3.9 3.10" - local platform_tags="macosx_10_9_x86_64 macosx_10_13_x86_64" + local platform_tags="macosx_10_14_x86_64" fi # verify arch-native wheels inside an arch-native conda environment diff --git a/dev/tasks/homebrew-formulae/autobrew/apache-arrow.rb b/dev/tasks/homebrew-formulae/autobrew/apache-arrow.rb index 1530a7b1d9713..8677b55c15916 100644 --- a/dev/tasks/homebrew-formulae/autobrew/apache-arrow.rb +++ b/dev/tasks/homebrew-formulae/autobrew/apache-arrow.rb @@ -46,6 +46,7 @@ def install -DARROW_BUILD_UTILITIES=ON -DARROW_COMPUTE=ON -DARROW_CSV=ON + -DARROW_CXXFLAGS="-D_LIBCPP_DISABLE_AVAILABILITY" -DARROW_DATASET=ON -DARROW_FILESYSTEM=ON -DARROW_GCS=ON diff --git a/dev/tasks/tasks.yml b/dev/tasks/tasks.yml index a0bb7e304b713..98af1a194bf77 100644 --- a/dev/tasks/tasks.yml +++ b/dev/tasks/tasks.yml @@ -478,7 +478,7 @@ tasks: {############################## Wheel OSX ####################################} -{% for macos_version, macos_codename in [("10.13", "high-sierra")] %} +{% for macos_version, macos_codename in [("10.14", "mojave")] %} {% set platform_tag = "macosx_{}_x86_64".format(macos_version.replace('.', '_')) %} wheel-macos-{{ macos_codename }}-{{ python_tag }}-amd64: @@ -538,9 +538,9 @@ tasks: params: arch: universal2 python_version: "{{ python_version }}" - macos_deployment_target: "10.13" + macos_deployment_target: "10.14" artifacts: - - pyarrow-{no_rc_version}-{{ python_tag }}-{{ python_tag }}-macosx_10_13_universal2.whl + - pyarrow-{no_rc_version}-{{ python_tag }}-{{ python_tag }}-macosx_10_14_universal2.whl {% endfor %} {############################ Python sdist ####################################} diff --git a/docs/source/cpp/datatypes.rst b/docs/source/cpp/datatypes.rst index 2a31ac65a9394..1d2133cbdf3d6 100644 --- a/docs/source/cpp/datatypes.rst +++ b/docs/source/cpp/datatypes.rst @@ -140,7 +140,7 @@ function for any numeric (integer or float) array: typename CType = typename DataType::c_type> arrow::enable_if_number SumArray(const ArrayType& array) { CType sum = 0; - for (arrow::util::optional value : array) { + for (std::optional value : array) { if (value.has_value()) { sum += value.value(); } @@ -192,7 +192,7 @@ here is how one might sum across columns of arbitrary numeric types: template arrow::enable_if_number Visit(const ArrayType& array) { - for (arrow::util::optional value : array) { + for (std::optional value : array) { if (value.has_value()) { partial += static_cast(value.value()); } @@ -205,4 +205,4 @@ Arrow also provides abstract visitor classes (:class:`arrow::TypeVisitor`, :class:`arrow::ScalarVisitor`, :class:`arrow::ArrayVisitor`) and an ``Accept()`` method on each of the corresponding base types (e.g. :func:`arrow::Array::Accept`). However, these are not able to be implemented using template functions, so you -will typically prefer using the inline type visitors. \ No newline at end of file +will typically prefer using the inline type visitors. diff --git a/docs/source/cpp/gdb.rst b/docs/source/cpp/gdb.rst index beb9267f567b5..609f11a993ab2 100644 --- a/docs/source/cpp/gdb.rst +++ b/docs/source/cpp/gdb.rst @@ -165,5 +165,4 @@ Important utility classes are also covered: * :class:`arrow::Status` and :class:`arrow::Result` * :class:`arrow::Buffer` and subclasses * :class:`arrow::Decimal128`, :class:`arrow::Decimal256` -* :class:`arrow::util::string_view`, :class:`arrow::util::optional`, - :class:`arrow::util::Variant` +* :class:`arrow::util::string_view`, :class:`arrow::util::Variant` diff --git a/docs/source/cpp/streaming_execution.rst b/docs/source/cpp/streaming_execution.rst index daa5f4be2f013..88922a04aa712 100644 --- a/docs/source/cpp/streaming_execution.rst +++ b/docs/source/cpp/streaming_execution.rst @@ -593,7 +593,7 @@ be quite tricky to configure. To process data from files the scan operation is The source node requires some kind of function that can be called to poll for more data. This function should take no arguments and should return an -``arrow::Future>>``. +``arrow::Future>``. This function might be reading a file, iterating through an in memory structure, or receiving data from a network connection. The arrow library refers to these functions as ``arrow::AsyncGenerator`` and there are a number of utilities for working with these functions. For this example we use @@ -752,7 +752,7 @@ execution definition. :class:`arrow::compute::SinkNodeOptions` interface is used the required options. Similar to the source operator the sink operator exposes the output with a function that returns a record batch future each time it is called. It is expected the caller will repeatedly call this function until the generator function is exhausted (returns -``arrow::util::optional::nullopt``). If this function is not called often enough then record batches +``std::optional::nullopt``). If this function is not called often enough then record batches will accumulate in memory. An execution plan should only have one "terminal" node (one sink node). An :class:`ExecPlan` can terminate early due to cancellation or an error, before the output is fully consumed. However, the plan can be safely destroyed independently @@ -1003,4 +1003,4 @@ Complete Example: :start-after: (Doc section: Execution Plan Documentation Example) :end-before: (Doc section: Execution Plan Documentation Example) :linenos: - :lineno-match: \ No newline at end of file + :lineno-match: diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index e2c53974cfe68..5a61227deed8e 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -59,7 +59,7 @@ set(CMAKE_MACOSX_RPATH 1) if(DEFINED ENV{MACOSX_DEPLOYMENT_TARGET}) set(CMAKE_OSX_DEPLOYMENT_TARGET $ENV{MACOSX_DEPLOYMENT_TARGET}) else() - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14) endif() # Generate a Clang compile_commands.json "compilation database" file for use diff --git a/python/pyarrow/includes/common.pxd b/python/pyarrow/includes/common.pxd index 07a75d4a08121..c4beca4d15ece 100644 --- a/python/pyarrow/includes/common.pxd +++ b/python/pyarrow/includes/common.pxd @@ -35,6 +35,15 @@ cimport cpython cdef extern from * namespace "std" nogil: cdef shared_ptr[T] static_pointer_cast[T, U](shared_ptr[U]) + +cdef extern from "" namespace "std" nogil: + cdef cppclass optional[T]: + c_bool has_value() + T value() + optional(T&) + optional& operator=[U](U&) + + # vendored from the cymove project https://github.com/ozars/cymove cdef extern from * namespace "cymove" nogil: """ diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd index 489d73bf27e6f..d9dde7803abf9 100644 --- a/python/pyarrow/includes/libarrow.pxd +++ b/python/pyarrow/includes/libarrow.pxd @@ -54,13 +54,6 @@ cdef extern from "arrow/util/decimal.h" namespace "arrow" nogil: cdef cppclass CDecimal256" arrow::Decimal256": c_string ToString(int32_t scale) const -cdef extern from "arrow/util/optional.h" namespace "arrow::util" nogil: - cdef cppclass c_optional"arrow::util::optional"[T]: - c_bool has_value() - T value() - c_optional(T&) - c_optional& operator=[U](U&) - cdef extern from "arrow/config.h" namespace "arrow" nogil: cdef cppclass CBuildInfo" arrow::BuildInfo": diff --git a/python/pyarrow/includes/libarrow_fs.pxd b/python/pyarrow/includes/libarrow_fs.pxd index 7984b54f587b8..bf22ead83ec00 100644 --- a/python/pyarrow/includes/libarrow_fs.pxd +++ b/python/pyarrow/includes/libarrow_fs.pxd @@ -223,7 +223,7 @@ cdef extern from "arrow/filesystem/api.h" namespace "arrow::fs" nogil: c_string endpoint_override c_string scheme c_string default_bucket_location - c_optional[double] retry_limit_seconds + optional[double] retry_limit_seconds shared_ptr[const CKeyValueMetadata] default_metadata c_bool Equals(const CS3Options& other) diff --git a/python/pyarrow/src/gdb.cc b/python/pyarrow/src/gdb.cc index 297bc6dbffc71..7541e52460903 100644 --- a/python/pyarrow/src/gdb.cc +++ b/python/pyarrow/src/gdb.cc @@ -34,7 +34,6 @@ #include "arrow/util/key_value_metadata.h" #include "arrow/util/logging.h" #include "arrow/util/macros.h" -#include "arrow/util/optional.h" #include "arrow/util/string_view.h" #include "arrow/util/variant.h" @@ -122,10 +121,6 @@ void TestSession() { auto error_result = Result(error_status); auto error_detail_result = Result(error_detail_status); - // Optionals - util::optional int_optional{42}; - util::optional null_int_optional{}; - // Variants using VariantType = util::Variant; diff --git a/python/pyarrow/src/python_test.cc b/python/pyarrow/src/python_test.cc index 54086faa7ca76..865d4cf5c0f83 100644 --- a/python/pyarrow/src/python_test.cc +++ b/python/pyarrow/src/python_test.cc @@ -18,6 +18,7 @@ #include "gtest/gtest.h" #include +#include #include #include @@ -28,7 +29,6 @@ #include "arrow/table.h" #include "arrow/testing/gtest_util.h" #include "arrow/util/decimal.h" -#include "arrow/util/optional.h" #include "arrow_to_pandas.h" #include "decimal.h" @@ -399,7 +399,7 @@ TEST(BuiltinConversionTest, TestMixedTypeFails) { template void DecimalTestFromPythonDecimalRescale(std::shared_ptr type, OwnedRef python_decimal, - ::arrow::util::optional expected) { + std::optional expected) { DecimalValue value; const auto& decimal_type = checked_cast(*type); diff --git a/python/pyarrow/tests/test_gdb.py b/python/pyarrow/tests/test_gdb.py index 1990198d9f120..6b76d9b626e68 100644 --- a/python/pyarrow/tests/test_gdb.py +++ b/python/pyarrow/tests/test_gdb.py @@ -297,13 +297,6 @@ def test_buffer_heap(gdb_arrow): 'arrow::Buffer of size 3, mutable, "abc"') -def test_optionals(gdb_arrow): - check_stack_repr(gdb_arrow, "int_optional", - "arrow::util::optional(42)") - check_stack_repr(gdb_arrow, "null_int_optional", - "arrow::util::optional(nullopt)") - - def test_variants(gdb_arrow): check_stack_repr( gdb_arrow, "int_variant", diff --git a/r/configure.win b/r/configure.win index 8aa05ef5970d6..1eb72e15613d3 100755 --- a/r/configure.win +++ b/r/configure.win @@ -139,7 +139,12 @@ if [ "$ARROW_R_CXXFLAGS" ]; then PKG_CFLAGS="$PKG_CFLAGS $ARROW_R_CXXFLAGS" fi -echo "*** Writing Makevars.win" +echo "*** Writing $(pwd)/src/Makevars.win" sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars.win + +echo "*** Contents of $(pwd)/src/Makevars.win" +cat src/Makevars.win +echo "*** /End contents" + # Success exit 0 diff --git a/r/src/Makevars.ucrt b/r/src/Makevars.ucrt index 52488eb2b858e..a91dedc2d559d 100644 --- a/r/src/Makevars.ucrt +++ b/r/src/Makevars.ucrt @@ -17,3 +17,6 @@ CRT=-ucrt include Makevars.win + +# XXX for some reason, this variable doesn't seem propagated from Makevars.win +CXX_STD=CXX17 diff --git a/r/src/compute-exec.cpp b/r/src/compute-exec.cpp index f9183a3a10303..abcb418a2c237 100644 --- a/r/src/compute-exec.cpp +++ b/r/src/compute-exec.cpp @@ -25,10 +25,10 @@ #include #include #include -#include #include #include +#include namespace compute = ::arrow::compute; @@ -66,7 +66,7 @@ ExecPlan_prepare(const std::shared_ptr& plan, // For now, don't require R to construct SinkNodes. // Instead, just pass the node we should collect as an argument. - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; // Sorting uses a different sink node; there is no general sort yet if (sort_options.size() > 0) { @@ -170,7 +170,7 @@ std::string ExecPlan_BuildAndShow(const std::shared_ptr& plan // For now, don't require R to construct SinkNodes. // Instead, just pass the node we should collect as an argument. - arrow::AsyncGenerator> sink_gen; + arrow::AsyncGenerator> sink_gen; // Sorting uses a different sink node; there is no general sort yet if (sort_options.size() > 0) { diff --git a/r/src/config.cpp b/r/src/config.cpp index 1d322205b5d15..a45df73a64a69 100644 --- a/r/src/config.cpp +++ b/r/src/config.cpp @@ -17,8 +17,9 @@ #include "./arrow_types.h" +#include + #include -#include // [[arrow::export]] std::vector build_info() { @@ -41,6 +42,6 @@ void set_timezone_database(cpp11::strings path) { } arrow::GlobalOptions options; - options.timezone_db_path = arrow::util::make_optional(paths[0]); + options.timezone_db_path = std::make_optional(paths[0]); arrow::StopIfNotOk(arrow::Initialize(options)); }