westonpace commented on code in PR #13914:
URL: https://github.com/apache/arrow/pull/13914#discussion_r966505178


##########
cpp/src/arrow/engine/substrait/relation_internal.cc:
##########
@@ -399,17 +506,45 @@ Result<DeclarationInfo> FromProto(const substrait::Rel& 
rel, const ExtensionSet&
               ExtensionIdRegistry::SubstraitAggregateToArrow converter,
               
ext_set.registry()->GetSubstraitAggregateToArrow(aggregate_call.id()));
           ARROW_ASSIGN_OR_RAISE(compute::Aggregate arrow_agg, 
converter(aggregate_call));
+
+          // find aggregate field ids from schema
+          const auto field_ref = arrow_agg.target;
+          ARROW_ASSIGN_OR_RAISE(auto match, field_ref.FindOne(*input_schema));
+          agg_src_field_ids[measure_id] = match[0];
+
           aggregates.push_back(std::move(arrow_agg));
         } else {
           return Status::Invalid("substrait::AggregateFunction not provided");
         }
       }
+      FieldVector output_fields;
+      output_fields.reserve(key_field_ids.size() + agg_src_field_ids.size());
+      // extract aggregate fields to output schema
+      for (int id = 0; id < static_cast<int>(agg_src_field_ids.size()); id++) {
+        output_fields.emplace_back(input_schema->field(agg_src_field_ids[id]));
+      }
+      // extract key fields to output schema
+      for (int id = 0; id < static_cast<int>(key_field_ids.size()); id++) {
+        output_fields.emplace_back(input_schema->field(key_field_ids[id]));
+      }

Review Comment:
   Another PR is fine but I wouldn't consider the output order from Acero to be 
too static.  Fixing it up to output things in the order Substrait expects would 
be nice so we can at least avoid the project node in some cases (when a direct 
emit).  It'll be a breaking change and probably cause some slight heartburn to 
our existing tests but we should probably fix it while we still have the 
opportunity.



-- 
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]

Reply via email to