You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/03/17 19:32:29 UTC
[GitHub] [arrow] pitrou opened a new pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
pitrou opened a new pull request #9742:
URL: https://github.com/apache/arrow/pull/9742
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-804025092
> I don't think independent ExecNodes would work, since some operations (e.g. hash aggregation or any vector function) need access to the entire input before starting to compute their output.
Note: Hash aggregation does not need access to its entire input to start computing, and in the first iteration of this project vector functions will be entirely disallowed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598573395
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
+
+ /// Mark the inputs finished after the given number of batches.
+ ///
+ /// This may be called before all inputs are received. This simply fixes
+ /// the total number of incoming batches so that the ExecNode knows when
+ /// it has received all input.
+ Status InputFinished(int32_t num_batches);
Review comment:
As for the second question, it seems I should change this declaration to `Status InputFinished(int32_t input_index, int32_t num_batches)`. Does that sound right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou edited a comment on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou edited a comment on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-828652100
Note for readers: I'm working on a new PR which will supersede this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598571843
##########
File path: cpp/src/arrow/engine/query_plan.h
##########
@@ -0,0 +1,99 @@
+// 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.
Review comment:
Ok, perhaps the naming is bad, but this is not a logical plan. This is the physical plan. "Exec plan" is a particular instantiation of executing this physical plan.
Does that make sense?
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
Review comment:
The index of the batch in the batch stream.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598668228
##########
File path: cpp/src/arrow/engine/query_plan.h
##########
@@ -0,0 +1,99 @@
+// 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.
Review comment:
I see. How about:
* query_plan.h -> physical_plan.h
* exec_plan.h -> exec_node.h
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
westonpace commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-803842961
How does this handle fan-out style parallelism. For example, you can generally filter batch N while filtering batch N+1 at the same time. Would there be a single ExecNode that is run twice? If so won't you have trouble tracking inputs? Or would there be two ExecNode instances in the plan? In that case how would you decide which node to deliver batches to?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
westonpace commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598487916
##########
File path: cpp/src/arrow/engine/exec_plan.cc
##########
@@ -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/engine/exec_plan.h"
+
+#include "arrow/compute/exec.h"
+#include "arrow/engine/query_plan.h"
+#include "arrow/result.h"
+#include "arrow/status.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/future.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/thread_pool.h"
+
+namespace arrow {
+
+using internal::checked_cast;
+
+namespace engine {
+
+ExecNode::InputBatch::InputBatch(std::vector<util::optional<compute::ExecBatch>> batches)
+ : batches(std::move(batches)), ready_fut(Future<>::Make()) {}
+
+ExecNode::ExecNode(ExecPlan* plan, const QueryNode* query_node)
+ : plan_(plan),
+ query_node_(query_node),
+ num_inputs_(query_node->num_inputs()),
+ finished_fut_(Future<>::Make()) {}
+
+ExecNode::~ExecNode() = default;
+
+void ExecNode::ReserveBatches(int32_t num_batches) {
+ // Should be called with mutex locked
+ if (static_cast<size_t>(num_batches) > input_batches_.size()) {
+ input_batches_.resize(num_batches);
+ }
+}
+
+ExecNode::InputBatch* ExecNode::EnsureBatch(int32_t batch_index) {
+ // Should be called with mutex locked
+ if (input_batches_[batch_index] == nullptr) {
+ input_batches_[batch_index].reset(
+ new InputBatch{std::vector<util::optional<compute::ExecBatch>>(num_inputs_)});
+ }
+ return input_batches_[batch_index].get();
+}
+
+Status ExecNode::InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch) {
+ auto lock = mutex_.Lock();
+
+ if (input_index >= num_inputs_) {
+ return Status::Invalid("Invalid input index");
+ }
+ if (finish_at_ >= 0 && batch_index >= finish_at_) {
+ return Status::Invalid("Input batch index out of bounds");
+ }
+
+ ReserveBatches(batch_index + 1);
+ auto* input_batch = EnsureBatch(batch_index);
+
+ if (input_batch->batches[input_index].has_value()) {
+ return Status::Invalid("Batch #", batch_index, " for input #", input_index,
+ " already received");
+ }
+ input_batch->batches[input_index] = std::move(batch);
+ if (++input_batch->num_ready == num_inputs_) {
+ input_batch->ready_fut.MarkFinished();
+ }
+ return Status::OK();
+}
+
+Status ExecNode::InputFinished(int32_t num_batches) {
+ auto lock = mutex_.Lock();
+
+ if (finish_at_ >= 0) {
+ return Status::Invalid("InputFinished already called");
+ }
+ finish_at_ = num_batches;
+ ReserveBatches(num_batches);
+
+ std::vector<Future<>> batch_futures;
+ for (int32_t i = 0; i < num_batches; ++i) {
+ auto* input_batch = EnsureBatch(i);
+ batch_futures[i] = input_batch->ready_fut;
+ }
+
+ // TODO lifetime
+ AllComplete(std::move(batch_futures))
+ .AddCallback([this](const Result<detail::Empty>& res) {
+ finished_fut_.MarkFinished(res.status());
+ });
+ return Status::OK();
+}
+
+Future<> ExecNode::RunAsync(int32_t batch_index, internal::Executor* executor) {
+ auto lock = mutex_.Lock();
+
+ ReserveBatches(batch_index + 1);
+ auto* input_batch = EnsureBatch(batch_index);
+
+ // TODO lifetime (take strong ref to ExecPlan?)
+ return executor->Transfer(input_batch->ready_fut)
Review comment:
Would different nodes run on different executors? If not it might be simpler to avoid the transfer. Also, do I have to call RunAsync on every node for every batch index? Couldn't calling RunAsync on the root node(s?) be enough?
##########
File path: cpp/src/arrow/engine/query_plan.h
##########
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecPlan;
+class QueryContext;
+class QueryNode;
+
+class ARROW_EXPORT QueryPlan {
Review comment:
What is the relationship between a query plan and an execution plan? My current understanding is that a query plan is an AST of the query and the execution plan is a possibly optimized tree of workers. Is this correct?
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
Review comment:
How do I actually run this? There doesn't appear to be any public interface.
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
Review comment:
Shouldn't this be the other way around? The QueryPlan doesn't have any reference to the ExecPlan (and if my understanding of the relationship is correct it shouldn't). What value is there in this declaration?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-804034133
Also keep in mind (for subsequent work) that some nodes (ie “Limit” in particular) will need to be able to apply backpressure on their parents to get them to immediately quit producing outputs. For example, if you have a “limit 1000” query, as soon as you have 1000 rows of output you shut down the ancestors.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598582203
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
Review comment:
Sorry, this is just a WIP PR. I decided to post it to ensure that I'm not entirely going in a bad direction.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598576236
##########
File path: cpp/src/arrow/engine/exec_plan.cc
##########
@@ -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/engine/exec_plan.h"
+
+#include "arrow/compute/exec.h"
+#include "arrow/engine/query_plan.h"
+#include "arrow/result.h"
+#include "arrow/status.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/future.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/thread_pool.h"
+
+namespace arrow {
+
+using internal::checked_cast;
+
+namespace engine {
+
+ExecNode::InputBatch::InputBatch(std::vector<util::optional<compute::ExecBatch>> batches)
+ : batches(std::move(batches)), ready_fut(Future<>::Make()) {}
+
+ExecNode::ExecNode(ExecPlan* plan, const QueryNode* query_node)
+ : plan_(plan),
+ query_node_(query_node),
+ num_inputs_(query_node->num_inputs()),
+ finished_fut_(Future<>::Make()) {}
+
+ExecNode::~ExecNode() = default;
+
+void ExecNode::ReserveBatches(int32_t num_batches) {
+ // Should be called with mutex locked
+ if (static_cast<size_t>(num_batches) > input_batches_.size()) {
+ input_batches_.resize(num_batches);
+ }
+}
+
+ExecNode::InputBatch* ExecNode::EnsureBatch(int32_t batch_index) {
+ // Should be called with mutex locked
+ if (input_batches_[batch_index] == nullptr) {
+ input_batches_[batch_index].reset(
+ new InputBatch{std::vector<util::optional<compute::ExecBatch>>(num_inputs_)});
+ }
+ return input_batches_[batch_index].get();
+}
+
+Status ExecNode::InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch) {
+ auto lock = mutex_.Lock();
+
+ if (input_index >= num_inputs_) {
+ return Status::Invalid("Invalid input index");
+ }
+ if (finish_at_ >= 0 && batch_index >= finish_at_) {
+ return Status::Invalid("Input batch index out of bounds");
+ }
+
+ ReserveBatches(batch_index + 1);
+ auto* input_batch = EnsureBatch(batch_index);
+
+ if (input_batch->batches[input_index].has_value()) {
+ return Status::Invalid("Batch #", batch_index, " for input #", input_index,
+ " already received");
+ }
+ input_batch->batches[input_index] = std::move(batch);
+ if (++input_batch->num_ready == num_inputs_) {
+ input_batch->ready_fut.MarkFinished();
+ }
+ return Status::OK();
+}
+
+Status ExecNode::InputFinished(int32_t num_batches) {
+ auto lock = mutex_.Lock();
+
+ if (finish_at_ >= 0) {
+ return Status::Invalid("InputFinished already called");
+ }
+ finish_at_ = num_batches;
+ ReserveBatches(num_batches);
+
+ std::vector<Future<>> batch_futures;
+ for (int32_t i = 0; i < num_batches; ++i) {
+ auto* input_batch = EnsureBatch(i);
+ batch_futures[i] = input_batch->ready_fut;
+ }
+
+ // TODO lifetime
+ AllComplete(std::move(batch_futures))
+ .AddCallback([this](const Result<detail::Empty>& res) {
+ finished_fut_.MarkFinished(res.status());
+ });
+ return Status::OK();
+}
+
+Future<> ExecNode::RunAsync(int32_t batch_index, internal::Executor* executor) {
+ auto lock = mutex_.Lock();
+
+ ReserveBatches(batch_index + 1);
+ auto* input_batch = EnsureBatch(batch_index);
+
+ // TODO lifetime (take strong ref to ExecPlan?)
+ return executor->Transfer(input_batch->ready_fut)
Review comment:
I'm not sure what "root nodes" are in this context. You mean the sources?
Indeed, we may simply want to start executing as soon as all inputs are ready. Though this will depend on the node: some can execute as soon as one batch is received, some need the whole input to be received.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-804141148
> Hmm, right. But still, any output depends on the entire input, so it cannot be emitted on-the-fly while receiving partial input chunks.
Right, these kinds of operators (ones that have to exhaust their inputs before emitting an output) are often called "blocking" in the literature (see e.g. http://pages.cs.wisc.edu/~jignesh/publ/Quickstep.pdf or http://www.vldb.org/pvldb/vol11/p2209-kersten.pdf).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598665751
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
Review comment:
I don't think this parameter is important, at least at this stage. Could you clarify what "When all inputs are received for a given batch_index, the batch is ready for execution." means? In general, inputs from different parents won't necessarily correspond to each other.
For example, suppose that we are joining a 1,000,000 row input with a 100,000 row input. One input might yield 100 batches while the other might only yield 5 or 10. They may be of differing lengths, in an unpredictable order (since scans won't necessarily yield a deterministic order), and the batches won't correspond to each other.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-828652100
Note for readers: I'm worker on a new PR which will supersede this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-804052211
> Note: Hash aggregation does not need access to its entire input to start computing, and in the first iteration of this project vector functions will be entirely disallowed.
Hmm, right. But still, any output depends on the entire input, so it cannot be emitted on-the-fly while receiving partial input chunks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-803945598
> For example, you can generally filter batch N while filtering batch N+1 at the same time. Would there be a single ExecNode that is run twice? If so won't you have trouble tracking inputs?
There would be a single ExecNode that is run twice. Tracking the input is done through the `batch_index` (this is where you pass your N, N+1...). There is even a bit of logic implemented :-)
I don't think independent ExecNodes would work, since some operations (e.g. hash aggregation or any vector function) need access to the entire input before starting to compute their output.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598573870
##########
File path: cpp/src/arrow/engine/query_plan.h
##########
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecPlan;
+class QueryContext;
+class QueryNode;
+
+class ARROW_EXPORT QueryPlan {
Review comment:
As I answered above, "query plan" is the physical plan. "Exec plan" is the particular execution of this plan for a given set of inputs. Does that make sense? Do you want to suggest other names?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598572601
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
+
+ /// Mark the inputs finished after the given number of batches.
+ ///
+ /// This may be called before all inputs are received. This simply fixes
+ /// the total number of incoming batches so that the ExecNode knows when
+ /// it has received all input.
+ Status InputFinished(int32_t num_batches);
Review comment:
As the docstring says, this may or may not be called before all inputs are received. But it must be called at some point so that the node knows that input is finished.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-801355489
@bkietz @wesm Here is an initial stab at the exec node API. Only base classes are present.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598701694
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
Review comment:
> In general, inputs from different parents won't necessarily correspond to each other.
Ah, I see. This is a misunderstanding on my part, then. Sorry.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou closed pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou closed pull request #9742:
URL: https://github.com/apache/arrow/pull/9742
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-829465231
Closing in favour of #10204.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#issuecomment-804052486
> For example, if you have a “limit 1000” query, as soon as you have 1000 rows of output you shut down the ancestors.
Ok, I'll have to think about that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598372744
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
Review comment:
What is "batch_index"?
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
+
+ /// Mark the inputs finished after the given number of batches.
+ ///
+ /// This may be called before all inputs are received. This simply fixes
+ /// the total number of incoming batches so that the ExecNode knows when
+ /// it has received all input.
+ Status InputFinished(int32_t num_batches);
Review comment:
* In general, nodes will not know how many batches they are going to produce, so the situations where this API would be used seem rare to me
* When a node has multiple inputs (e.g. joins, unions), the parent nodes will finish producing outputs at different times. How are they supposed to independently communicate that they are done?
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
+
+ /// Mark the inputs finished after the given number of batches.
+ ///
+ /// This may be called before all inputs are received. This simply fixes
+ /// the total number of incoming batches so that the ExecNode knows when
+ /// it has received all input.
+ Status InputFinished(int32_t num_batches);
+
+ /// Schedule batch execution once all inputs are received for the given batch_index
+ ///
+ /// The returned Future is finished once execution of the batch is finished.
+ /// Note that execution doesn't necessarily mean that any outputs are produced.
+ /// Depending on the ExecNode type, outputs may be produced on the fly,
+ /// or only at the end when all inputs have been received.
+ Future<> RunAsync(int32_t batch_index, internal::Executor* executor);
Review comment:
I guess I don't understand what "batch_index" is yet
##########
File path: cpp/src/arrow/engine/query_plan.h
##########
@@ -0,0 +1,99 @@
+// 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.
Review comment:
I don't think that work on query planning is anticipated soon, only work on execution, so this could be put off later.
As a nit, I would also suggest calling this "logical_plan.h" to distinguish logical from physical execution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] wesm commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
wesm commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598669568
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
+
+ ExecPlan() = default;
+
+ const std::shared_ptr<const QueryPlan> query_plan_;
+ compute::ExecContext* context_;
+};
+
+class ARROW_EXPORT ExecNode {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecNode();
+
+ /// The query node this ExecNode is an instance of
+ const QueryNode& query_node() const { return *query_node_; }
+
+ /// This node's exec plan
+ ExecPlan* plan() { return plan_; }
+
+ /// Transfer input batch to ExecNode
+ ///
+ /// When all inputs are received for a given batch_index, the batch is ready
+ /// for execution.
+ Status InputReceived(int32_t input_index, int32_t batch_index,
+ compute::ExecBatch batch);
+
+ /// Mark the inputs finished after the given number of batches.
+ ///
+ /// This may be called before all inputs are received. This simply fixes
+ /// the total number of incoming batches so that the ExecNode knows when
+ /// it has received all input.
+ Status InputFinished(int32_t num_batches);
Review comment:
I would say to nix the "num_batches" argument, but otherwise yes `InputFinished(input_index)` sounds right
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #9742: [WIP] ARROW-11928: [C++] Execution engine API
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #9742:
URL: https://github.com/apache/arrow/pull/9742#discussion_r598579312
##########
File path: cpp/src/arrow/engine/exec_plan.h
##########
@@ -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.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "arrow/compute/type_fwd.h"
+#include "arrow/type_fwd.h"
+#include "arrow/util/future.h"
+#include "arrow/util/macros.h"
+#include "arrow/util/mutex.h"
+#include "arrow/util/optional.h"
+#include "arrow/util/type_fwd.h"
+#include "arrow/util/visibility.h"
+
+namespace arrow {
+namespace engine {
+
+class ExecNode;
+class QueryNode;
+class QueryPlan;
+
+class ARROW_EXPORT ExecPlan {
+ public:
+ using NodeVector = std::vector<ExecNode*>;
+
+ virtual ~ExecPlan() = default;
+
+ /// The query plan this ExecPlan is an instance of
+ const QueryPlan& query_plan() const { return *query_plan_; }
+
+ compute::ExecContext* context() { return context_; }
+
+ protected:
+ friend class QueryPlan;
Review comment:
The query plan is supposed to instantiate a corresponding exec plan when `QueryPlan::MakeExecPlan` is called. Presumably that will need access to non-public APIs or members, but this is all just a sketch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org