Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-17517: [C++] Remove internal headers from substrait API #14131

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ if(ARROW_COMPUTE)
compute/exec/hash_join_node.cc
compute/exec/key_hash.cc
compute/exec/key_map.cc
compute/exec/map_node.cc
compute/exec/order_by_impl.cc
compute/exec/partition_util.cc
compute/exec/options.cc
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/compute/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@
/// @{
/// @}

#include "arrow/compute/exec.h" // IWYU pragma: export
#include "arrow/compute/exec.h" // IWYU pragma: export
#include "arrow/compute/exec/exec_plan.h" // IWYU pragma: export
2 changes: 2 additions & 0 deletions cpp/src/arrow/compute/exec/aggregate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include "arrow/compute/exec/aggregate.h"

#include <mutex>
#include <thread>

#include "arrow/compute/exec_internal.h"
#include "arrow/compute/registry.h"
#include "arrow/compute/row/grouper.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/logging.h"
#include "arrow/util/task_group.h"

namespace arrow {
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/compute/exec/benchmark_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "arrow/compute/exec/exec_plan.h"
#include "arrow/compute/exec/options.h"
#include "arrow/compute/exec/task_util.h"
#include "arrow/compute/exec/util.h"
#include "arrow/util/macros.h"

namespace arrow {
Expand Down
95 changes: 1 addition & 94 deletions cpp/src/arrow/compute/exec/exec_plan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "arrow/compute/exec/expression.h"
#include "arrow/compute/exec/options.h"
#include "arrow/compute/exec/task_util.h"
#include "arrow/compute/exec/util.h"
#include "arrow/compute/exec_internal.h"
#include "arrow/compute/registry.h"
#include "arrow/datum.h"
Expand Down Expand Up @@ -474,100 +475,6 @@ bool ExecNode::ErrorIfNotOk(Status status) {
return true;
}

MapNode::MapNode(ExecPlan* plan, std::vector<ExecNode*> inputs,
std::shared_ptr<Schema> output_schema, bool async_mode)
: ExecNode(plan, std::move(inputs), /*input_labels=*/{"target"},
std::move(output_schema),
/*num_outputs=*/1) {
if (async_mode) {
executor_ = plan_->exec_context()->executor();
} else {
executor_ = nullptr;
}
}

void MapNode::ErrorReceived(ExecNode* input, Status error) {
DCHECK_EQ(input, inputs_[0]);
EVENT(span_, "ErrorReceived", {{"error.message", error.message()}});
outputs_[0]->ErrorReceived(this, std::move(error));
}

void MapNode::InputFinished(ExecNode* input, int total_batches) {
DCHECK_EQ(input, inputs_[0]);
EVENT(span_, "InputFinished", {{"batches.length", total_batches}});
outputs_[0]->InputFinished(this, total_batches);
if (input_counter_.SetTotal(total_batches)) {
this->Finish();
}
}

Status MapNode::StartProducing() {
START_COMPUTE_SPAN(
span_, std::string(kind_name()) + ":" + label(),
{{"node.label", label()}, {"node.detail", ToString()}, {"node.kind", kind_name()}});
return Status::OK();
}

void MapNode::PauseProducing(ExecNode* output, int32_t counter) {
inputs_[0]->PauseProducing(this, counter);
}

void MapNode::ResumeProducing(ExecNode* output, int32_t counter) {
inputs_[0]->ResumeProducing(this, counter);
}

void MapNode::StopProducing(ExecNode* output) {
DCHECK_EQ(output, outputs_[0]);
StopProducing();
}

void MapNode::StopProducing() {
EVENT(span_, "StopProducing");
if (executor_) {
this->stop_source_.RequestStop();
}
if (input_counter_.Cancel()) {
this->Finish();
}
inputs_[0]->StopProducing(this);
}

void MapNode::SubmitTask(std::function<Result<ExecBatch>(ExecBatch)> map_fn,
ExecBatch batch) {
Status status;
// This will be true if the node is stopped early due to an error or manual
// cancellation
if (input_counter_.Completed()) {
return;
}
auto task = [this, map_fn, batch]() {
auto guarantee = batch.guarantee;
auto output_batch = map_fn(std::move(batch));
if (ErrorIfNotOk(output_batch.status())) {
return output_batch.status();
}
output_batch->guarantee = guarantee;
outputs_[0]->InputReceived(this, output_batch.MoveValueUnsafe());
return Status::OK();
};

status = task();
if (!status.ok()) {
if (input_counter_.Cancel()) {
this->Finish(status);
}
inputs_[0]->StopProducing(this);
return;
}
if (input_counter_.Increment()) {
this->Finish();
}
}

void MapNode::Finish(Status finish_st /*= Status::OK()*/) {
this->finished_.MarkFinished(finish_st);
}

std::shared_ptr<RecordBatchReader> MakeGeneratorReader(
std::shared_ptr<Schema> schema, std::function<Future<std::optional<ExecBatch>>()> gen,
MemoryPool* pool) {
Expand Down
49 changes: 5 additions & 44 deletions cpp/src/arrow/compute/exec/exec_plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@

#pragma once

#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "arrow/compute/exec.h"
#include "arrow/compute/exec/util.h"
#include "arrow/compute/type_fwd.h"
#include "arrow/type_fwd.h"
#include "arrow/util/async_util.h"
#include "arrow/util/cancel.h"
#include "arrow/util/future.h"
#include "arrow/util/key_value_metadata.h"
#include "arrow/util/macros.h"
#include "arrow/util/tracing.h"
#include "arrow/util/type_fwd.h"
#include "arrow/util/visibility.h"

namespace arrow {
Expand Down Expand Up @@ -369,48 +372,6 @@ class ARROW_EXPORT ExecNode {
util::tracing::Span span_;
};

/// \brief MapNode is an ExecNode type class which process a task like filter/project
/// (See SubmitTask method) to each given ExecBatch object, which have one input, one
/// output, and are pure functions on the input
///
/// A simple parallel runner is created with a "map_fn" which is just a function that
/// takes a batch in and returns a batch. This simple parallel runner also needs an
/// executor (use simple synchronous runner if there is no executor)

class ARROW_EXPORT MapNode : public ExecNode {
public:
MapNode(ExecPlan* plan, std::vector<ExecNode*> inputs,
std::shared_ptr<Schema> output_schema, bool async_mode);

void ErrorReceived(ExecNode* input, Status error) override;

void InputFinished(ExecNode* input, int total_batches) override;

Status StartProducing() override;

void PauseProducing(ExecNode* output, int32_t counter) override;

void ResumeProducing(ExecNode* output, int32_t counter) override;

void StopProducing(ExecNode* output) override;

void StopProducing() override;

protected:
void SubmitTask(std::function<Result<ExecBatch>(ExecBatch)> map_fn, ExecBatch batch);

virtual void Finish(Status finish_st = Status::OK());

protected:
// Counter for the number of batches received
AtomicCounter input_counter_;

::arrow::internal::Executor* executor_;

// Variable used to cancel remaining tasks in the executor
StopSource stop_source_;
};

/// \brief An extensible registry for factories of ExecNodes
class ARROW_EXPORT ExecFactoryRegistry {
public:
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/compute/exec/expression_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "benchmark/benchmark.h"

#include <thread>

#include "arrow/compute/cast.h"
#include "arrow/compute/exec/expression.h"
#include "arrow/compute/exec/test_util.h"
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/compute/exec/filter_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "arrow/compute/exec.h"
#include "arrow/compute/exec/exec_plan.h"
#include "arrow/compute/exec/expression.h"
#include "arrow/compute/exec/map_node.h"
#include "arrow/compute/exec/options.h"
#include "arrow/datum.h"
#include "arrow/result.h"
Expand Down
131 changes: 131 additions & 0 deletions cpp/src/arrow/compute/exec/map_node.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

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

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

#include "arrow/compute/exec.h"
#include "arrow/compute/exec/expression.h"
#include "arrow/result.h"
#include "arrow/status.h"
#include "arrow/util/logging.h"
#include "arrow/util/tracing_internal.h"

namespace arrow {
namespace compute {

MapNode::MapNode(ExecPlan* plan, std::vector<ExecNode*> inputs,
std::shared_ptr<Schema> output_schema, bool async_mode)
: ExecNode(plan, std::move(inputs), /*input_labels=*/{"target"},
std::move(output_schema),
/*num_outputs=*/1) {
if (async_mode) {
executor_ = plan_->exec_context()->executor();
} else {
executor_ = nullptr;
}
}

void MapNode::ErrorReceived(ExecNode* input, Status error) {
DCHECK_EQ(input, inputs_[0]);
EVENT(span_, "ErrorReceived", {{"error.message", error.message()}});
outputs_[0]->ErrorReceived(this, std::move(error));
}

void MapNode::InputFinished(ExecNode* input, int total_batches) {
DCHECK_EQ(input, inputs_[0]);
EVENT(span_, "InputFinished", {{"batches.length", total_batches}});
outputs_[0]->InputFinished(this, total_batches);
if (input_counter_.SetTotal(total_batches)) {
this->Finish();
}
}

Status MapNode::StartProducing() {
START_COMPUTE_SPAN(
span_, std::string(kind_name()) + ":" + label(),
{{"node.label", label()}, {"node.detail", ToString()}, {"node.kind", kind_name()}});
return Status::OK();
}

void MapNode::PauseProducing(ExecNode* output, int32_t counter) {
inputs_[0]->PauseProducing(this, counter);
}

void MapNode::ResumeProducing(ExecNode* output, int32_t counter) {
inputs_[0]->ResumeProducing(this, counter);
}

void MapNode::StopProducing(ExecNode* output) {
DCHECK_EQ(output, outputs_[0]);
StopProducing();
}

void MapNode::StopProducing() {
EVENT(span_, "StopProducing");
if (executor_) {
this->stop_source_.RequestStop();
}
if (input_counter_.Cancel()) {
this->Finish();
}
inputs_[0]->StopProducing(this);
}

void MapNode::SubmitTask(std::function<Result<ExecBatch>(ExecBatch)> map_fn,
ExecBatch batch) {
Status status;
// This will be true if the node is stopped early due to an error or manual
// cancellation
if (input_counter_.Completed()) {
return;
}
auto task = [this, map_fn, batch]() {
auto guarantee = batch.guarantee;
auto output_batch = map_fn(std::move(batch));
if (ErrorIfNotOk(output_batch.status())) {
return output_batch.status();
}
output_batch->guarantee = guarantee;
outputs_[0]->InputReceived(this, output_batch.MoveValueUnsafe());
return Status::OK();
};

status = task();
if (!status.ok()) {
if (input_counter_.Cancel()) {
this->Finish(status);
}
inputs_[0]->StopProducing(this);
return;
}
if (input_counter_.Increment()) {
this->Finish();
}
}

void MapNode::Finish(Status finish_st /*= Status::OK()*/) {
this->finished_.MarkFinished(finish_st);
}

} // namespace compute
} // namespace arrow
Loading