Skip to content

Commit

Permalink
ARROW-17694: [C++] Remove std::optional backport (#14105)
Browse files Browse the repository at this point in the history
Just use the C++17 standard library version.

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
pitrou committed Sep 15, 2022
1 parent 2749fef commit 5e49174
Show file tree
Hide file tree
Showing 148 changed files with 653 additions and 2,311 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down
28 changes: 0 additions & 28 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions c_glib/arrow-glib/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecBatch>;
using ExecBatchOptional = std::optional<ExecBatch>;
auto arrow_record_batch_result = arrow_reader->Next();
if (!arrow_record_batch_result.ok()) {
return arrow::AsyncGeneratorEnd<ExecBatchOptional>();
Expand Down Expand Up @@ -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<ExecBatch>;
using ExecBatchOptional = std::optional<ExecBatch>;
if (!state->generated) {
state->generated = true;
return arrow::Future<ExecBatchOptional>::MakeFinished(
Expand Down Expand Up @@ -1296,7 +1296,7 @@ garrow_aggregate_node_options_new(GList *aggregations,


typedef struct GArrowSinkNodeOptionsPrivate_ {
arrow::AsyncGenerator<arrow::util::optional<arrow::compute::ExecBatch>> generator;
arrow::AsyncGenerator<std::optional<arrow::compute::ExecBatch>> generator;
GArrowRecordBatchReader *reader;
} GArrowSinkNodeOptionsPrivate;

Expand Down Expand Up @@ -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::util::optional<arrow::compute::ExecBatch>>();
arrow::AsyncGenerator<std::optional<arrow::compute::ExecBatch>>();
}

static void
Expand Down
2 changes: 1 addition & 1 deletion ci/scripts/python_wheel_macos_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ci/vcpkg/universal2-osx-static-debug.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ci/vcpkg/universal2-osx-static-release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion cpp/examples/arrow/compute_register_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<arrow::util::optional<cp::ExecBatch>> source_gen, sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> source_gen, sink_gen;
ARROW_RETURN_NOT_OK(
cp::Declaration::Sequence(
{
Expand Down
32 changes: 16 additions & 16 deletions cpp/examples/arrow/execution_plan_documentation_examples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ struct BatchesWithSchema {
std::shared_ptr<arrow::Schema> schema;
// This method uses internal arrow utilities to
// convert a vector of record batches to an AsyncGenerator of optional batches
arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> gen() const {
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> 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<arrow::util::optional<cp::ExecBatch>> gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> gen;
gen = arrow::MakeVectorGenerator(std::move(opt_batches));
return gen;
}
Expand Down Expand Up @@ -259,7 +259,7 @@ arrow::Result<BatchesWithSchema> MakeGroupableBatches(int multiplicity = 1) {
arrow::Status ExecutePlanAndCollectAsTable(
cp::ExecContext& exec_context, std::shared_ptr<cp::ExecPlan> plan,
std::shared_ptr<arrow::Schema> schema,
arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen) {
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen) {
// translate sink_gen (async) to sink_reader (sync)
std::shared_ptr<arrow::RecordBatchReader> sink_reader =
cp::MakeGeneratorReader(schema, std::move(sink_gen), exec_context.memory_pool());
Expand Down Expand Up @@ -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<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

ARROW_RETURN_NOT_OK(
cp::MakeExecNode("sink", plan.get(), {scan}, cp::SinkNodeOptions{&sink_gen}));
Expand All @@ -337,7 +337,7 @@ arrow::Status SourceSinkExample(cp::ExecContext& exec_context) {

ARROW_ASSIGN_OR_RAISE(auto basic_data, MakeBasicBatches());

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()};

Expand Down Expand Up @@ -367,7 +367,7 @@ arrow::Status TableSourceSinkExample(cp::ExecContext& exec_context) {

ARROW_ASSIGN_OR_RAISE(auto table, GetTable());

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;
int max_batch_size = 2;
auto table_source_options = cp::TableSourceNodeOptions{table, max_batch_size};

Expand Down Expand Up @@ -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<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;
ARROW_RETURN_NOT_OK(
cp::MakeExecNode("sink", plan.get(), {filter}, cp::SinkNodeOptions{&sink_gen}));

Expand Down Expand Up @@ -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<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> 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())});
Expand All @@ -496,7 +496,7 @@ arrow::Status SourceScalarAggregateSinkExample(cp::ExecContext& exec_context) {

ARROW_ASSIGN_OR_RAISE(auto basic_data, MakeBasicBatches());

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()};

Expand Down Expand Up @@ -532,7 +532,7 @@ arrow::Status SourceGroupAggregateSinkExample(cp::ExecContext& exec_context) {

ARROW_ASSIGN_OR_RAISE(auto basic_data, MakeBasicBatches());

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()};

Expand Down Expand Up @@ -640,7 +640,7 @@ arrow::Status SourceOrderBySinkExample(cp::ExecContext& exec_context) {

std::cout << "basic data created" << std::endl;

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

auto source_node_options = cp::SourceNodeOptions{basic_data.schema, basic_data.gen()};
ARROW_ASSIGN_OR_RAISE(cp::ExecNode * source,
Expand Down Expand Up @@ -670,7 +670,7 @@ arrow::Status SourceHashJoinSinkExample(cp::ExecContext& exec_context) {
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<cp::ExecPlan> plan,
cp::ExecPlan::Make(&exec_context));

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

cp::ExecNode* left_source;
cp::ExecNode* right_source;
Expand Down Expand Up @@ -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<cp::ExecPlan> plan,
cp::ExecPlan::Make(&exec_context));
arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

ARROW_ASSIGN_OR_RAISE(
cp::ExecNode * source,
Expand Down Expand Up @@ -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<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

std::string root_path = "";
std::string uri = "file://" + file_path;
Expand Down Expand Up @@ -820,7 +820,7 @@ arrow::Status SourceUnionSinkExample(cp::ExecContext& exec_context) {

ARROW_ASSIGN_OR_RAISE(std::shared_ptr<cp::ExecPlan> plan,
cp::ExecPlan::Make(&exec_context));
arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

cp::Declaration union_node{"union", cp::ExecNodeOptions{}};
cp::Declaration lhs{"source",
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/arrow/join_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ arrow::Status DoHashJoin() {
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<cp::ExecPlan> plan,
cp::ExecPlan::Make(&exec_context));

arrow::AsyncGenerator<arrow::util::optional<cp::ExecBatch>> sink_gen;
arrow::AsyncGenerator<std::optional<cp::ExecBatch>> sink_gen;

cp::ExecNode* left_source;
cp::ExecNode* right_source;
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/minimal_build/run_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
24 changes: 0 additions & 24 deletions cpp/gdb_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
# 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.
Expand Down Expand Up @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/array/array_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BaseBinaryArray : public FlatArray {
raw_value_offsets_[i + 1] - pos);
}

util::optional<util::string_view> operator[](int64_t i) const {
std::optional<util::string_view> operator[](int64_t i) const {
return *IteratorType(*this, i);
}

Expand Down Expand Up @@ -240,7 +240,7 @@ class ARROW_EXPORT FixedSizeBinaryArray : public PrimitiveArray {
return util::string_view(reinterpret_cast<const char*>(GetValue(i)), byte_width());
}

util::optional<util::string_view> operator[](int64_t i) const {
std::optional<util::string_view> operator[](int64_t i) const {
return *IteratorType(*this, i);
}

Expand Down
8 changes: 4 additions & 4 deletions cpp/src/arrow/array/array_primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ARROW_EXPORT BooleanArray : public PrimitiveArray {

bool GetView(int64_t i) const { return Value(i); }

util::optional<bool> operator[](int64_t i) const { return *IteratorType(*this, i); }
std::optional<bool> 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.
Expand Down Expand Up @@ -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<value_type> operator[](int64_t i) const {
std::optional<value_type> operator[](int64_t i) const {
return *IteratorType(*this, i);
}

Expand Down Expand Up @@ -152,7 +152,7 @@ class ARROW_EXPORT DayTimeIntervalArray : public PrimitiveArray {

IteratorType end() const { return IteratorType(*this, length()); }

util::optional<TypeClass::DayMilliseconds> operator[](int64_t i) const {
std::optional<TypeClass::DayMilliseconds> operator[](int64_t i) const {
return *IteratorType(*this, i);
}

Expand Down Expand Up @@ -188,7 +188,7 @@ class ARROW_EXPORT MonthDayNanoIntervalArray : public PrimitiveArray {

IteratorType end() const { return IteratorType(*this, length()); }

util::optional<TypeClass::MonthDayNanos> operator[](int64_t i) const {
std::optional<TypeClass::MonthDayNanos> operator[](int64_t i) const {
return *IteratorType(*this, i);
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ TEST_F(TestFWBinaryArray, ArrayIndexOperator) {
auto fsba = checked_pointer_cast<FixedSizeBinaryArray>(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());
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/exec/asof_join_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<util::optional<ExecBatch>> sink_gen;
AsyncGenerator<std::optional<ExecBatch>> sink_gen;
ASSERT_OK(MakeExecNode("sink", plan.get(), {join_node}, SinkNodeOptions{&sink_gen}));
state.ResumeTiming();
ASSERT_FINISHES_OK(StartAndCollect(plan.get(), sink_gen));
Expand Down
Loading

0 comments on commit 5e49174

Please sign in to comment.