| 123 | } |
| 124 | |
| 125 | Result<std::unique_ptr<substrait::AggregateRel>> CreateAgg(Id function_id, |
| 126 | const std::vector<int>& keys, |
| 127 | std::vector<int> arg_idxs, |
| 128 | const DataType& output_type, |
| 129 | ExtensionSet* ext_set) { |
| 130 | auto agg = std::make_unique<substrait::AggregateRel>(); |
| 131 | |
| 132 | if (!keys.empty()) { |
| 133 | substrait::AggregateRel::Grouping* grouping = agg->add_groupings(); |
| 134 | for (int key : keys) { |
| 135 | substrait::Expression* key_expr = grouping->add_grouping_expressions(); |
| 136 | CreateDirectReference(key, key_expr); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | substrait::AggregateRel::Measure* measure_wrapper = agg->add_measures(); |
| 141 | auto agg_func = std::make_unique<substrait::AggregateFunction>(); |
| 142 | ARROW_ASSIGN_OR_RAISE(uint32_t function_anchor, ext_set->EncodeFunction(function_id)); |
| 143 | |
| 144 | agg_func->set_function_reference(function_anchor); |
| 145 | |
| 146 | for (int arg_idx : arg_idxs) { |
| 147 | substrait::FunctionArgument* arg = agg_func->add_arguments(); |
| 148 | auto arg_expr = std::make_unique<substrait::Expression>(); |
| 149 | CreateDirectReference(arg_idx, arg_expr.get()); |
| 150 | arg->set_allocated_value(arg_expr.release()); |
| 151 | } |
| 152 | |
| 153 | agg_func->set_phase(substrait::AggregationPhase::AGGREGATION_PHASE_INITIAL_TO_RESULT); |
| 154 | agg_func->set_invocation( |
| 155 | substrait::AggregateFunction::AggregationInvocation:: |
| 156 | AggregateFunction_AggregationInvocation_AGGREGATION_INVOCATION_ALL); |
| 157 | |
| 158 | ARROW_ASSIGN_OR_RAISE( |
| 159 | std::unique_ptr<substrait::Type> output_type_substrait, |
| 160 | ToProto(output_type, /*nullable=*/true, ext_set, kPlanBuilderConversionOptions)); |
| 161 | agg_func->set_allocated_output_type(output_type_substrait.release()); |
| 162 | measure_wrapper->set_allocated_measure(agg_func.release()); |
| 163 | |
| 164 | return agg; |
| 165 | } |
| 166 | |
| 167 | std::unique_ptr<substrait::Version> CreateTestVersion() { |
| 168 | auto version = std::make_unique<substrait::Version>(); |
no test coverage detected