| 1144 | |
| 1145 | template <FirstOrLast first_or_last> |
| 1146 | HashAggregateKernel MakeFirstOrLastKernel(HashAggregateFunction* first_last_func) { |
| 1147 | HashAggregateKernel kernel; |
| 1148 | kernel.init = [first_last_func]( |
| 1149 | KernelContext* ctx, |
| 1150 | const KernelInitArgs& args) -> Result<std::unique_ptr<KernelState>> { |
| 1151 | std::vector<TypeHolder> inputs = args.inputs; |
| 1152 | ARROW_ASSIGN_OR_RAISE(auto kernel, first_last_func->DispatchExact(args.inputs)); |
| 1153 | KernelInitArgs new_args{kernel, inputs, args.options}; |
| 1154 | return kernel->init(ctx, new_args); |
| 1155 | }; |
| 1156 | |
| 1157 | kernel.signature = |
| 1158 | KernelSignature::Make({InputType::Any(), Type::UINT32}, OutputType(FirstType)); |
| 1159 | kernel.resize = HashAggregateResize; |
| 1160 | kernel.consume = HashAggregateConsume; |
| 1161 | kernel.merge = HashAggregateMerge; |
| 1162 | kernel.finalize = [](KernelContext* ctx, Datum* out) { |
| 1163 | ARROW_ASSIGN_OR_RAISE(Datum temp, |
| 1164 | checked_cast<GroupedAggregator*>(ctx->state())->Finalize()); |
| 1165 | *out = temp.array_as<StructArray>()->field(static_cast<uint8_t>(first_or_last)); |
| 1166 | return Status::OK(); |
| 1167 | }; |
| 1168 | kernel.ordered = true; |
| 1169 | return kernel; |
| 1170 | } |
| 1171 | |
| 1172 | struct GroupedFirstLastFactory { |
| 1173 | template <typename T> |