Skip to content

Commit

Permalink
ARROW-17694: [C++] Remove std::optional backport
Browse files Browse the repository at this point in the history
Just use the C++17 standard library version.
  • Loading branch information
pitrou committed Sep 13, 2022
1 parent 8ceb3b8 commit 9168b04
Show file tree
Hide file tree
Showing 121 changed files with 581 additions and 2,217 deletions.
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
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
26 changes: 13 additions & 13 deletions cpp/src/arrow/compute/exec/asof_join_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <condition_variable>
#include <mutex>
#include <optional>
#include <thread>
#include <unordered_map>
#include <unordered_set>
Expand All @@ -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 {
Expand Down Expand Up @@ -99,11 +99,11 @@ class ConcurrentQueue {
queue_ = std::queue<T>();
}

util::optional<T> TryPop() {
std::optional<T> TryPop() {
// Try to pop the oldest value from the queue (or return nullopt if none)
std::unique_lock<std::mutex> lock(mutex_);
if (queue_.empty()) {
return util::nullopt;
return std::nullopt;
} else {
auto item = queue_.front();
queue_.pop();
Expand Down Expand Up @@ -156,10 +156,10 @@ struct MemoStore {
e.time = time;
}

util::optional<const Entry*> GetEntryForKey(ByType key) const {
std::optional<const Entry*> GetEntryForKey(ByType key) const {
auto e = entries_.find(key);
if (entries_.end() == e) return util::nullopt;
return util::optional<const Entry*>(&e->second);
if (entries_.end() == e) return std::nullopt;
return std::optional<const Entry*>(&e->second);
}

void RemoveEntriesWithLesserTime(OnType ts) {
Expand Down Expand Up @@ -263,7 +263,7 @@ class InputState {
return dst_offset;
}

const util::optional<col_index_t>& MapSrcToDst(col_index_t src) const {
const std::optional<col_index_t>& MapSrcToDst(col_index_t src) const {
return src_to_dst_[src];
}

Expand Down Expand Up @@ -436,16 +436,16 @@ class InputState {
return Status::OK();
}

util::optional<const MemoStore::Entry*> GetMemoEntryForKey(ByType key) {
std::optional<const MemoStore::Entry*> GetMemoEntryForKey(ByType key) {
return memo_.GetEntryForKey(key);
}

util::optional<OnType> GetMemoTimeForKey(ByType key) {
std::optional<OnType> GetMemoTimeForKey(ByType key) {
auto r = GetMemoEntryForKey(key);
if (r.has_value()) {
return (*r)->time;
} else {
return util::nullopt;
return std::nullopt;
}
}

Expand Down Expand Up @@ -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<util::optional<col_index_t>> src_to_dst_;
std::vector<std::optional<col_index_t>> src_to_dst_;
};

template <size_t MAX_TABLES>
Expand Down Expand Up @@ -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<const MemoStore::Entry*> opt_entry = in[i]->GetMemoEntryForKey(key);
std::optional<const MemoStore::Entry*> opt_entry = in[i]->GetMemoEntryForKey(key);
if (opt_entry.has_value()) {
DCHECK(*opt_entry);
if ((*opt_entry)->time + tolerance >= lhs_latest_time) {
Expand Down Expand Up @@ -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<col_index_t> i_dst_col_opt =
std::optional<col_index_t> 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;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/compute/exec/asof_join_node_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<util::optional<ExecBatch>> sink_gen;
AsyncGenerator<std::optional<ExecBatch>> sink_gen;

ASSERT_OK(Declaration::Sequence({join, {"sink", SinkNodeOptions{&sink_gen}}})
.AddToPlan(plan.get()));
Expand Down Expand Up @@ -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<util::optional<ExecBatch>> sink_gen;
AsyncGenerator<std::optional<ExecBatch>> sink_gen;
ASSERT_OK(Declaration::Sequence({join, {"sink", SinkNodeOptions{&sink_gen}}})
.AddToPlan(plan.get()));
EXPECT_FINISHES_AND_RAISES_WITH_MESSAGE_THAT(Invalid,
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/compute/exec/benchmark_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Status BenchmarkIsolatedNodeOverhead(benchmark::State& state,
arrow::compute::ExecNodeOptions& options) {
for (auto _ : state) {
state.PauseTiming();
AsyncGenerator<util::optional<arrow::compute::ExecBatch>> sink_gen;
AsyncGenerator<std::optional<arrow::compute::ExecBatch>> sink_gen;

ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::compute::ExecPlan> plan,
arrow::compute::ExecPlan::Make(&ctx));
Expand Down Expand Up @@ -119,7 +119,7 @@ Status BenchmarkNodeOverhead(
state.PauseTiming();
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::compute::ExecPlan> plan,
arrow::compute::ExecPlan::Make(&ctx));
AsyncGenerator<util::optional<arrow::compute::ExecBatch>> sink_gen;
AsyncGenerator<std::optional<arrow::compute::ExecBatch>> sink_gen;
arrow::compute::Declaration source = arrow::compute::Declaration(
{"source",
arrow::compute::SourceNodeOptions{data.schema,
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/arrow/compute/exec/exec_plan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "arrow/compute/exec/exec_plan.h"

#include <optional>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
Expand All @@ -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 {
Expand Down Expand Up @@ -339,12 +339,12 @@ const ExecPlanImpl* ToDerived(const ExecPlan* ptr) {
return checked_cast<const ExecPlanImpl*>(ptr);
}

util::optional<int> GetNodeIndex(const std::vector<ExecNode*>& nodes,
const ExecNode* node) {
std::optional<int> GetNodeIndex(const std::vector<ExecNode*>& nodes,
const ExecNode* node) {
for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
if (nodes[i] == node) return i;
}
return util::nullopt;
return std::nullopt;
}

} // namespace
Expand Down Expand Up @@ -569,8 +569,8 @@ void MapNode::Finish(Status finish_st /*= Status::OK()*/) {
}

std::shared_ptr<RecordBatchReader> MakeGeneratorReader(
std::shared_ptr<Schema> schema,
std::function<Future<util::optional<ExecBatch>>()> gen, MemoryPool* pool) {
std::shared_ptr<Schema> schema, std::function<Future<std::optional<ExecBatch>>()> gen,
MemoryPool* pool) {
struct Impl : RecordBatchReader {
std::shared_ptr<Schema> schema() const override { return schema_; }

Expand All @@ -596,7 +596,7 @@ std::shared_ptr<RecordBatchReader> MakeGeneratorReader(

MemoryPool* pool_;
std::shared_ptr<Schema> schema_;
Iterator<util::optional<ExecBatch>> iterator_;
Iterator<std::optional<ExecBatch>> iterator_;
};

auto out = std::make_shared<Impl>();
Expand Down Expand Up @@ -699,12 +699,12 @@ ExecFactoryRegistry* default_exec_factory_registry() {
return &instance;
}

Result<std::function<Future<util::optional<ExecBatch>>()>> MakeReaderGenerator(
Result<std::function<Future<std::optional<ExecBatch>>()>> MakeReaderGenerator(
std::shared_ptr<RecordBatchReader> reader, ::arrow::internal::Executor* io_executor,
int max_q, int q_restart) {
auto batch_it = MakeMapIterator(
[](std::shared_ptr<RecordBatch> batch) {
return util::make_optional(ExecBatch(*batch));
return std::make_optional(ExecBatch(*batch));
},
MakeIteratorFromReader(reader));

Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/compute/exec/exec_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>

Expand All @@ -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"

Expand Down Expand Up @@ -525,7 +525,7 @@ struct ARROW_EXPORT Declaration {
/// The RecordBatchReader does not impose any ordering on emitted batches.
ARROW_EXPORT
std::shared_ptr<RecordBatchReader> MakeGeneratorReader(
std::shared_ptr<Schema>, std::function<Future<util::optional<ExecBatch>>()>,
std::shared_ptr<Schema>, std::function<Future<std::optional<ExecBatch>>()>,
MemoryPool*);

constexpr int kDefaultBackgroundMaxQ = 32;
Expand All @@ -535,7 +535,7 @@ constexpr int kDefaultBackgroundQRestart = 16;
///
/// Useful as a source node for an Exec plan
ARROW_EXPORT
Result<std::function<Future<util::optional<ExecBatch>>()>> MakeReaderGenerator(
Result<std::function<Future<std::optional<ExecBatch>>()>> MakeReaderGenerator(
std::shared_ptr<RecordBatchReader> reader, arrow::internal::Executor* io_executor,
int max_q = kDefaultBackgroundMaxQ, int q_restart = kDefaultBackgroundQRestart);

Expand Down
Loading

0 comments on commit 9168b04

Please sign in to comment.