icexelloss commented on code in PR #34912:
URL: https://github.com/apache/arrow/pull/34912#discussion_r1173127725
##########
cpp/src/arrow/compute/kernels/hash_aggregate.cc:
##########
@@ -1695,6 +1692,384 @@ struct GroupedMinMaxFactory {
InputType argument_type;
};
+// ----------------------------------------------------------------------
+// FirstLast implementation
+
+template <typename Type, typename Enable = void>
+struct GroupedFirstLastImpl final : public GroupedAggregator {
+ using CType = typename TypeTraits<Type>::CType;
+ using GetSet = GroupedValueTraits<Type>;
+ using ArrType =
+ typename std::conditional<is_boolean_type<Type>::value, uint8_t,
CType>::type;
+
+ Status Init(ExecContext* ctx, const KernelInitArgs& args) override {
+ options_ = *checked_cast<const ScalarAggregateOptions*>(args.options);
+
+ firsts_ = TypedBufferBuilder<CType>(ctx->memory_pool());
+ lasts_ = TypedBufferBuilder<CType>(ctx->memory_pool());
+ has_values_ = TypedBufferBuilder<bool>(ctx->memory_pool());
+ has_nulls_ = TypedBufferBuilder<bool>(ctx->memory_pool());
+ return Status::OK();
+ }
+
+ Status Resize(int64_t new_num_groups) override {
+ auto added_groups = new_num_groups - num_groups_;
+ num_groups_ = new_num_groups;
+ // Reusing AntiExtrema as uninitialized value here because it doesn't
+ // matter what the value is. We never output the uninitialized
+ // first/last value.
+ RETURN_NOT_OK(firsts_.Append(added_groups,
AntiExtrema<CType>::anti_min()));
+ RETURN_NOT_OK(lasts_.Append(added_groups, AntiExtrema<CType>::anti_max()));
+ RETURN_NOT_OK(has_values_.Append(added_groups, false));
+ RETURN_NOT_OK(has_nulls_.Append(added_groups, false));
+ return Status::OK();
+ }
+
+ Status Consume(const ExecSpan& batch) override {
Review Comment:
(Consume, Merge and Finalize)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]