You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ildipo (via GitHub)" <gi...@apache.org> on 2023/06/07 18:00:51 UTC
[GitHub] [arrow] ildipo opened a new pull request, #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
ildipo opened a new pull request, #35980:
URL: https://github.com/apache/arrow/pull/35980
### Rationale for this change
Add basic window aggregation functionalities to Acero.
### What changes are included in this PR?
Existing Acero aggregation (scalar and group-by) sources have been refactored into separate files with no changes.
New window aware scalar and group-by aggregation are added.
### Are these changes tested?
Window specific basic tests are included.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on a diff in pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1226771801
##########
cpp/src/arrow/acero/options.h:
##########
@@ -297,6 +297,26 @@ class ARROW_ACERO_EXPORT ProjectNodeOptions : public ExecNodeOptions {
std::vector<std::string> names;
};
+/// windows proceed left to right
+class ARROW_ACERO_EXPORT WindowAggregateArgs {
Review Comment:
Revert 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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ildipo commented on a diff in pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "ildipo (via GitHub)" <gi...@apache.org>.
ildipo commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1221989239
##########
cpp/src/arrow/acero/CMakeLists.txt:
##########
@@ -29,7 +29,11 @@ endmacro()
set(ARROW_ACERO_SRCS
accumulation_queue.cc
- aggregate_node.cc
Review Comment:
`aggregate_node.cc` was split into `scalar_aggregate_node.cc`, `groupby_aggregate_node.cc` and `aggregate_internal.cc` - the existing code was moved as-is
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1581277008
:warning: GitHub issue #35979 **has been automatically assigned in GitHub** to PR creator.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1589477546
@westonpace I plan to merge this later Today if you don't have objections.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1587922766
LGTM. cc @westonpace in case you want to take a look. (Should be pretty straight forward)
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1587843060
@ildipo LGTM. Minor comments on the substrait file (since we don't change it probably better not to leave untouched)
Lint issue probably need:
```
archery lint --cmake-format
```
Do you mind also updating the title and description to better reflect the reduced change set?
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1582830154
@icexelloss happy to meet in person and go over the high level design. Just from a glance it looks like the aggregate node was split into the scalar and group-by cases with common parts put into aggregate_internal (I'm guessing to help share code between the aggregate cases and the window aggregates). Then two new window nodes were added. It seems that both of these nodes rely on the InputReceived being called in a sorted order in the same way that the asof join node does?
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on a diff in pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1226770800
##########
cpp/src/arrow/acero/aggregate_internal.h:
##########
@@ -0,0 +1,582 @@
+// 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.
+
+// This API is EXPERIMENTAL.
+
+#pragma once
+
+#include <forward_list>
+#include <mutex>
+#include <sstream>
+#include <thread>
+#include <unordered_map>
+#include <unordered_set>
+
+#include "arrow/acero/aggregate_node.h"
+#include "arrow/acero/exec_plan.h"
+#include "arrow/acero/options.h"
+#include "arrow/acero/query_context.h"
+#include "arrow/acero/util.h"
+#include "arrow/compute/exec.h"
+#include "arrow/compute/exec_internal.h"
+#include "arrow/compute/registry.h"
+#include "arrow/compute/row/grouper.h"
+#include "arrow/datum.h"
+#include "arrow/result.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/thread_pool.h"
+#include "arrow/util/tracing_internal.h"
+
+// This file implements both regular and segmented group-by aggregation, which is a
+// generalization of ordered aggregation in which the key columns are not required to be
+// ordered.
+//
+// In (regular) group-by aggregation, the input rows are partitioned into groups using a
+// set of columns called keys, where in a given group each row has the same values for
+// these columns. In segmented group-by aggregation, a second set of columns called
+// segment-keys is used to refine the partitioning. However, segment-keys are different in
+// that they partition only consecutive rows into a single group. Such a partition of
+// consecutive rows is called a segment group. For example, consider a column X with
+// values [A, A, B, A] at row-indices [0, 1, 2]. A regular group-by aggregation with keys
+// [X] yields a row-index partitioning [[0, 1, 3], [2]] whereas a segmented-group-by
+// aggregation with segment-keys [X] yields [[0, 1], [2], [3]].
+//
+// The implementation first segments the input using the segment-keys, then groups by the
+// keys. When a segment group end is reached while scanning the input, output is pushed
+// and the accumulating state is cleared. If no segment-keys are given, then the entire
+// input is taken as one segment group. One batch per segment group is sent to output.
+
+namespace arrow {
+
+using internal::checked_cast;
+
+using compute::ExecSpan;
+using compute::ExecValue;
+using compute::Function;
+using compute::FunctionOptions;
+using compute::Grouper;
+using compute::HashAggregateKernel;
+using compute::Kernel;
+using compute::KernelContext;
+using compute::KernelInitArgs;
+using compute::KernelState;
+using compute::RowSegmenter;
+using compute::ScalarAggregateKernel;
+using compute::Segment;
+
+namespace acero {
+namespace aggregate {
+
+template <typename KernelType>
+struct AggregateNodeArgs {
+ std::shared_ptr<Schema> output_schema;
+ std::vector<int> grouping_key_field_ids;
+ std::vector<int> segment_key_field_ids;
+ std::unique_ptr<RowSegmenter> segmenter;
+ std::vector<std::vector<int>> target_fieldsets;
+ std::vector<Aggregate> aggregates;
+ std::vector<const KernelType*> kernels;
+ std::vector<std::vector<TypeHolder>> kernel_intypes;
+ std::vector<std::vector<std::unique_ptr<KernelState>>> states;
+ std::optional<WindowAggregateArgs> window_args;
+};
+
+std::vector<TypeHolder> ExtendWithGroupIdType(const std::vector<TypeHolder>& in_types);
+
+Result<const HashAggregateKernel*> GetKernel(ExecContext* ctx, const Aggregate& aggregate,
+ const std::vector<TypeHolder>& in_types);
+
+Result<std::unique_ptr<KernelState>> InitKernel(const HashAggregateKernel* kernel,
+ ExecContext* ctx,
+ const Aggregate& aggregate,
+ const std::vector<TypeHolder>& in_types);
+
+Result<std::vector<const HashAggregateKernel*>> GetKernels(
+ ExecContext* ctx, const std::vector<Aggregate>& aggregates,
+ const std::vector<std::vector<TypeHolder>>& in_types);
+
+Result<std::vector<std::unique_ptr<KernelState>>> InitKernels(
+ const std::vector<const HashAggregateKernel*>& kernels, ExecContext* ctx,
+ const std::vector<Aggregate>& aggregates,
+ const std::vector<std::vector<TypeHolder>>& in_types);
+
+Result<FieldVector> ResolveKernels(
+ const std::vector<Aggregate>& aggregates,
+ const std::vector<const HashAggregateKernel*>& kernels,
+ const std::vector<std::unique_ptr<KernelState>>& states, ExecContext* ctx,
+ const std::vector<std::vector<TypeHolder>>& types);
+
+void AggregatesToString(std::stringstream* ss, const Schema& input_schema,
+ const std::vector<Aggregate>& aggs,
+ const std::vector<std::vector<int>>& target_fieldsets,
+ int indent = 0);
+
+// Extract segments from a batch and run the given handler on them. Note that the
+// handle may be called on open segments which are not yet finished. Typically a
+// handler should accumulate those open segments until a closed segment is reached.
+template <typename BatchHandler>
+Status HandleSegments(RowSegmenter* segmenter, const ExecBatch& batch,
+ const std::vector<int>& ids, const BatchHandler& handle_batch) {
+ int64_t offset = 0;
+ ARROW_ASSIGN_OR_RAISE(auto segment_exec_batch, batch.SelectValues(ids));
+ ExecSpan segment_batch(segment_exec_batch);
+
+ while (true) {
+ ARROW_ASSIGN_OR_RAISE(compute::Segment segment,
+ segmenter->GetNextSegment(segment_batch, offset));
+ if (segment.offset >= segment_batch.length) break; // condition of no-next-segment
+ ARROW_RETURN_NOT_OK(handle_batch(batch, segment));
+ offset = segment.offset + segment.length;
+ }
+ return Status::OK();
+}
+
+/// @brief Extract values of segment keys from a segment batch
+/// @param[out] values_ptr Vector to store the extracted segment key values
+/// @param[in] input_batch Segment batch. Must have the a constant value for segment key
+/// @param[in] field_ids Segment key field ids
+Status ExtractSegmenterValues(std::vector<Datum>* values_ptr,
+ const ExecBatch& input_batch,
+ const std::vector<int>& field_ids);
+
+Result<std::vector<Datum>> ExtractValues(const ExecBatch& input_batch,
+ const std::vector<int>& field_ids);
+
+void PlaceFields(ExecBatch& batch, size_t base, std::vector<Datum>& values);
+
+class ScalarAggregateNode : public ExecNode, public TracedNode {
+ public:
+ ScalarAggregateNode(ExecPlan* plan, std::vector<ExecNode*> inputs,
+ std::shared_ptr<Schema> output_schema,
+ std::unique_ptr<RowSegmenter> segmenter,
+ std::vector<int> segment_field_ids,
+ std::vector<std::vector<int>> target_fieldsets,
+ std::vector<Aggregate> aggs,
+ std::vector<const ScalarAggregateKernel*> kernels,
+ std::vector<std::vector<TypeHolder>> kernel_intypes,
+ std::vector<std::vector<std::unique_ptr<KernelState>>> states)
+ : ExecNode(plan, std::move(inputs), {"target"},
+ /*output_schema=*/std::move(output_schema)),
+ TracedNode(this),
+ segmenter_(std::move(segmenter)),
+ segment_field_ids_(std::move(segment_field_ids)),
+ target_fieldsets_(std::move(target_fieldsets)),
+ aggs_(std::move(aggs)),
+ kernels_(std::move(kernels)),
+ kernel_intypes_(std::move(kernel_intypes)),
+ states_(std::move(states)) {}
+
+ static Result<AggregateNodeArgs<ScalarAggregateKernel>> MakeAggregateNodeArgs(
+ const std::shared_ptr<Schema>& input_schema, const std::vector<FieldRef>& keys,
+ const std::vector<FieldRef>& segment_keys, const std::vector<Aggregate>& aggs,
+ ExecContext* exec_ctx, size_t concurrency, bool is_cpu_parallel);
+
+ static Result<ExecNode*> Make(ExecPlan* plan, std::vector<ExecNode*> inputs,
+ const ExecNodeOptions& options);
+
+ const char* kind_name() const override { return "ScalarAggregateNode"; }
+
+ Status DoConsume(const ExecSpan& batch, size_t thread_index);
+
+ Status InputReceived(ExecNode* input, ExecBatch batch) override;
+
+ Status InputFinished(ExecNode* input, int total_batches) override;
+
+ Status StartProducing() override {
+ NoteStartProducing(ToStringExtra(0));
+ return Status::OK();
+ }
+
+ void PauseProducing(ExecNode* output, int32_t counter) override {
+ inputs_[0]->PauseProducing(this, counter);
+ }
+
+ void ResumeProducing(ExecNode* output, int32_t counter) override {
+ inputs_[0]->ResumeProducing(this, counter);
+ }
+
+ Status StopProducingImpl() override { return Status::OK(); }
+
+ protected:
+ std::string ToStringExtra(int indent) const override;
+
+ private:
+ Status ResetKernelStates();
+
+ Status OutputResult(bool is_last);
+
+ // A segmenter for the segment-keys
+ std::unique_ptr<RowSegmenter> segmenter_;
+ // Field indices corresponding to the segment-keys
+ const std::vector<int> segment_field_ids_;
+ // Holds the value of segment keys of the most recent input batch
+ // The values are updated everytime an input batch is processed
+ std::vector<Datum> segmenter_values_;
+
+ const std::vector<std::vector<int>> target_fieldsets_;
+ const std::vector<Aggregate> aggs_;
+ const std::vector<const ScalarAggregateKernel*> kernels_;
+
+ // Input type holders for each kernel, used for state initialization
+ std::vector<std::vector<TypeHolder>> kernel_intypes_;
+ std::vector<std::vector<std::unique_ptr<KernelState>>> states_;
+
+ AtomicCounter input_counter_;
+ /// \brief Total number of output batches produced
+ int total_output_batches_ = 0;
+};
+
+class GroupByNode : public ExecNode, public TracedNode {
+ public:
+ GroupByNode(ExecNode* input, std::shared_ptr<Schema> output_schema,
+ std::vector<int> key_field_ids, std::vector<int> segment_key_field_ids,
+ std::unique_ptr<RowSegmenter> segmenter,
+ std::vector<std::vector<TypeHolder>> agg_src_types,
+ std::vector<std::vector<int>> agg_src_fieldsets,
+ std::vector<Aggregate> aggs,
+ std::vector<const HashAggregateKernel*> agg_kernels)
+ : ExecNode(input->plan(), {input}, {"groupby"}, std::move(output_schema)),
+ TracedNode(this),
+ segmenter_(std::move(segmenter)),
+ key_field_ids_(std::move(key_field_ids)),
+ segment_key_field_ids_(std::move(segment_key_field_ids)),
+ agg_src_types_(std::move(agg_src_types)),
+ agg_src_fieldsets_(std::move(agg_src_fieldsets)),
+ aggs_(std::move(aggs)),
+ agg_kernels_(std::move(agg_kernels)) {}
+
+ Status Init() override;
+
+ static Result<AggregateNodeArgs<HashAggregateKernel>> MakeAggregateNodeArgs(
+ const std::shared_ptr<Schema>& input_schema, const std::vector<FieldRef>& keys,
+ const std::vector<FieldRef>& segment_keys, const std::vector<Aggregate>& aggs,
+ ExecContext* ctx, const bool is_cpu_parallel);
+
+ static Result<ExecNode*> Make(ExecPlan* plan, std::vector<ExecNode*> inputs,
+ const ExecNodeOptions& options);
+
+ Status ResetKernelStates();
+
+ const char* kind_name() const override { return "GroupByNode"; }
+
+ Status Consume(ExecSpan batch);
+
+ Status Merge();
+
+ Result<ExecBatch> Finalize();
+
+ Status OutputNthBatch(int64_t n);
+
+ Status OutputResult(bool is_last);
+
+ Status InputReceived(ExecNode* input, ExecBatch batch) override;
+
+ Status InputFinished(ExecNode* input, int total_batches) override;
+
+ Status StartProducing() override {
+ NoteStartProducing(ToStringExtra(0));
+ local_states_.resize(plan_->query_context()->max_concurrency());
+ return Status::OK();
+ }
+
+ void PauseProducing(ExecNode* output, int32_t counter) override {
+ // TODO(ARROW-16260)
+ // Without spillover there is no way to handle backpressure in this node
+ }
+
+ void ResumeProducing(ExecNode* output, int32_t counter) override {
+ // TODO(ARROW-16260)
+ // Without spillover there is no way to handle backpressure in this node
+ }
+
+ Status StopProducingImpl() override { return Status::OK(); }
+
+ protected:
+ std::string ToStringExtra(int indent) const override;
+
+ private:
+ struct ThreadLocalState {
+ std::unique_ptr<Grouper> grouper;
+ std::vector<std::unique_ptr<KernelState>> agg_states;
+ };
+
+ ThreadLocalState* GetLocalState() {
+ size_t thread_index = plan_->query_context()->GetThreadIndex();
+ return &local_states_[thread_index];
+ }
+
+ Status InitLocalStateIfNeeded(ThreadLocalState* state);
+
+ int output_batch_size() const {
+ int result =
+ static_cast<int>(plan_->query_context()->exec_context()->exec_chunksize());
+ if (result < 0) {
+ result = 32 * 1024;
+ }
+ return result;
+ }
+
+ int output_task_group_id_;
+ /// \brief A segmenter for the segment-keys
+ std::unique_ptr<RowSegmenter> segmenter_;
+ /// \brief Holds values of the current batch that were selected for the segment-keys
+ std::vector<Datum> segmenter_values_;
+
+ const std::vector<int> key_field_ids_;
+ /// \brief Field indices corresponding to the segment-keys
+ const std::vector<int> segment_key_field_ids_;
+ /// \brief Types of input fields per aggregate
+ const std::vector<std::vector<TypeHolder>> agg_src_types_;
+ const std::vector<std::vector<int>> agg_src_fieldsets_;
+ const std::vector<Aggregate> aggs_;
+ const std::vector<const HashAggregateKernel*> agg_kernels_;
+
+ AtomicCounter input_counter_;
+ /// \brief Total number of output batches produced
+ int total_output_batches_ = 0;
+
+ std::vector<ThreadLocalState> local_states_;
+ ExecBatch out_data_;
+};
+
+class WindowGroupByNode : public ExecNode, public TracedNode {
+ public:
+ WindowGroupByNode(ExecNode* input, std::shared_ptr<Schema> output_schema,
+ std::vector<int> key_field_ids,
+ std::vector<int> segment_key_field_ids,
+ std::unique_ptr<RowSegmenter> segmenter,
+ std::vector<std::vector<TypeHolder>> agg_src_types,
+ std::vector<std::vector<int>> agg_src_fieldsets,
+ std::vector<Aggregate> aggs,
+ std::vector<const HashAggregateKernel*> agg_kernels,
+ std::optional<WindowAggregateArgs> window_args)
+ : ExecNode(input->plan(), {input}, {"groupby"}, std::move(output_schema)),
+ TracedNode(this),
+ segmenter_(std::move(segmenter)),
+ key_field_ids_(std::move(key_field_ids)),
+ segment_key_field_ids_(std::move(segment_key_field_ids)),
+ agg_src_types_(std::move(agg_src_types)),
+ agg_src_fieldsets_(std::move(agg_src_fieldsets)),
+ aggs_(std::move(aggs)),
+ agg_kernels_(std::move(agg_kernels)),
+ window_args(window_args),
+ left_inclusive(window_args->left_inclusive ? "greater_equal" : "greater"),
+ right_inclusive(window_args->right_inclusive ? "greater" : "greater_equal"),
+ left(window_args->left_boundary),
+ right(window_args->right_boundary) {}
+
+ static Result<AggregateNodeArgs<HashAggregateKernel>> MakeAggregateNodeArgs(
+ const std::shared_ptr<Schema>& input_schema, const std::vector<FieldRef>& keys,
+ const std::vector<FieldRef>& segment_keys, const std::vector<Aggregate>& aggs,
+ ExecContext* ctx, const std::optional<WindowAggregateArgs> window_args);
+
+ static Result<ExecNode*> Make(ExecPlan* plan, std::vector<ExecNode*> inputs,
+ const ExecNodeOptions& options);
+
+ const char* kind_name() const override { return "WindowGroupByNode"; }
+
+ Status InputReceived(ExecNode* input, ExecBatch batch) override;
+
+ Status InputFinished(ExecNode* input, int total_batches) override;
+
+ Status StartProducing() override {
+ NoteStartProducing(ToStringExtra(0));
+ return Status::OK();
+ }
+
+ void PauseProducing(ExecNode* output, int32_t counter) override {
+ // Without spillover there is no way to handle backpressure in this node
+ inputs_[0]->PauseProducing(this, counter);
+ }
+
+ void ResumeProducing(ExecNode* output, int32_t counter) override {
+ // Without spillover there is no way to handle backpressure in this node
+ inputs_[0]->ResumeProducing(this, counter);
+ }
+
+ Status StopProducingImpl() override { return Status::OK(); }
+
+ protected:
+ std::string ToStringExtra(int indent) const override;
+
+ private:
+ Status OutputResult(bool flush = false);
+
+ Status Consume(KernelContext ctx, ExecSpan& run_batch);
+
+ Status Finalize(KernelContext ctx, ExecBatch& batch, std::size_t base);
+
+ Status InitStatesVector(KernelContext& kernel_ctx);
+
+ Result<std::pair<uint32_t, uint32_t>> FindLeftIndex(const Datum& data,
+ ExecContext* ctx);
+ Result<std::pair<uint32_t, uint32_t>> FindRightIndex(const Datum& data,
+ ExecContext* ctx, bool flush);
+
+ /// \brief A segmenter for the segment-keys
+ std::unique_ptr<RowSegmenter> segmenter_;
+ /// \brief Holds values of the current batch that were selected for the segment-keys
+ std::vector<Datum> segmenter_values_;
+
+ const std::vector<int> key_field_ids_;
+ /// \brief Field indices corresponding to the segment-keys
+ const std::vector<int> segment_key_field_ids_;
+ /// \brief Types of input fields per aggregate
+ const std::vector<std::vector<TypeHolder>> agg_src_types_;
+ const std::vector<std::vector<int>> agg_src_fieldsets_;
+ const std::vector<Aggregate> aggs_;
+ const std::vector<const HashAggregateKernel*> agg_kernels_;
+ std::unique_ptr<Grouper> grouper;
+ std::vector<std::vector<std::unique_ptr<KernelState>>> states_;
+
+ // Window content(s)
+ std::vector<ExecBatch> window_batches;
+ std::vector<std::vector<Datum>> window_segment_values;
+ std::vector<std::vector<Segment>> window_segments;
+
+ // Window parameters
+ std::optional<WindowAggregateArgs> window_args;
+ const std::string left_inclusive;
+ const std::string right_inclusive;
+ const Datum left;
+ const Datum right;
+
+ // current row info
+ Datum current_datum;
+ bool current_done{false};
+ std::pair<uint32_t, uint32_t> current_index;
+
+ /// \brief Total number of output batches produced
+ int total_output_batches_ = 0;
+};
+
+class WindowScalarNode : public ExecNode, public TracedNode {
Review Comment:
Remove 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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1581289518
Thanks @ildipo!
@westonpace Since this is a fairly large PR I think it would be beneficial if reviewers get an understanding of high level design in some way (maybe a meeting? Or some shared doc?). WDYT?
Also @ianmcook IIRC you also mentioned interested in reviewing windowing design/functionality
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1590069333
@westonpace Since I didn't hear from you I went ahead and merged this. (No changes to external headers so we should be fine).
But let me know in case you have some more comments we can do it as a follow up.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ildipo commented on a diff in pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "ildipo (via GitHub)" <gi...@apache.org>.
ildipo commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1221990383
##########
cpp/src/arrow/acero/scalar_aggregate_node.cc:
##########
@@ -0,0 +1,322 @@
+// Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
All of this was inside `aggregate_node.cc`
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1593734792
Conbench analyzed the 7 benchmark runs on commit `dadf6659`.
There were 4 benchmark results indicating a performance regression:
- Commit Run at [2023-06-15 12:17:18Z](http://conbench.ursa.dev/compare/runs/c59b3bd9b77a430d9a340a2d4cd4c339...253976876cee466991f492d4a4806324/)
- [source=cpp-micro, suite=arrow-decimal-benchmark](http://conbench.ursa.dev/compare/benchmarks/0648ab64b9277f0f8000dd4ce7cad791...0648b023cbf77e7380005d91bda9d3e6)
- [params=32768/10000, source=cpp-micro, suite=arrow-compute-vector-sort-benchmark](http://conbench.ursa.dev/compare/benchmarks/0648ab66445d7ecc80006cdb47c09671...0648b0258f59758480002a77ae5a45ff)
- and 2 more (see the report linked below)
The [full Conbench report](https://github.com/apache/arrow/runs/14304545838) has more details.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ildipo commented on pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "ildipo (via GitHub)" <gi...@apache.org>.
ildipo commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1587456367
I decided to split this into 2 to simplify review.
This now contains only refactoring and the additional options in the relations but not the window implementation.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ildipo commented on a diff in pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "ildipo (via GitHub)" <gi...@apache.org>.
ildipo commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1221989749
##########
cpp/src/arrow/acero/aggregate_internal.cc:
##########
@@ -0,0 +1,276 @@
+// Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
All of this was inside `aggregate_node.cc`
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ildipo commented on pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "ildipo (via GitHub)" <gi...@apache.org>.
ildipo commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1582947248
@westonpace that is correct
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] ildipo commented on a diff in pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "ildipo (via GitHub)" <gi...@apache.org>.
ildipo commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1221990089
##########
cpp/src/arrow/acero/groupby_aggregate_node.cc:
##########
@@ -0,0 +1,447 @@
+// Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
All of this was inside `aggregate_node.cc`
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #35980: GH-35979: [C++] Acero - Add basic scalar and group-by window aggregation
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #35980:
URL: https://github.com/apache/arrow/pull/35980#issuecomment-1587471999
@ildipo I am in favor of splitting up aggregate code to make it more reusable. +1 for the refactoring. It looks like there are still some windowing related changes in this PR though.
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on a diff in pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on code in PR #35980:
URL: https://github.com/apache/arrow/pull/35980#discussion_r1227065794
##########
cpp/proto/substrait/extension_rels.proto:
##########
@@ -69,3 +69,4 @@ message SegmentedAggregateRel {
// A list of one or more aggregate expressions along with an optional filter.
repeated substrait.AggregateRel.Measure measures = 3;
}
+
Review Comment:
Nit: revert this change? (Since we don't touch this file at all probably cleaner if we don't leave a new line change)
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss merged pull request #35980: GH-35979: [C++] Refactor Acero scalar and hash aggregation into separate files
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss merged PR #35980:
URL: https://github.com/apache/arrow/pull/35980
--
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.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org