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


##########
cpp/src/arrow/engine/substrait/expression_internal.cc:
##########
@@ -41,6 +41,70 @@ namespace internal {
 using ::arrow::internal::make_unique;
 }  // namespace internal
 
+Status DecodeArg(const substrait::FunctionArgument& arg, int idx, 
SubstraitCall* call,
+                 const ExtensionSet& ext_set,
+                 const ConversionOptions& conversion_options) {
+  if (arg.has_enum_()) {
+    const substrait::FunctionArgument::Enum& enum_val = arg.enum_();
+    if (enum_val.has_specified()) {
+      call->SetEnumArg(static_cast<uint32_t>(idx), enum_val.specified());
+    } else {
+      call->SetEnumArg(idx, util::nullopt);
+    }
+  } else if (arg.has_value()) {
+    ARROW_ASSIGN_OR_RAISE(compute::Expression expr,
+                          FromProto(arg.value(), ext_set, conversion_options));
+    call->SetValueArg(idx, std::move(expr));
+  } else if (arg.has_type()) {
+    return Status::NotImplemented("Type arguments not currently supported");
+  } else {
+    return Status::NotImplemented("Unrecognized function argument class");
+  }
+  return Status::OK();
+}
+
+Result<SubstraitCall> DecodeScalarFunction(
+    Id id, const substrait::Expression::ScalarFunction& scalar_fn,
+    const ExtensionSet& ext_set, const ConversionOptions& conversion_options) {
+  ARROW_ASSIGN_OR_RAISE(auto output_type_and_nullable,
+                        FromProto(scalar_fn.output_type(), ext_set, 
conversion_options));
+  SubstraitCall call(id, output_type_and_nullable.first, 
output_type_and_nullable.second);
+  for (int i = 0; i < scalar_fn.arguments_size(); i++) {
+    ARROW_RETURN_NOT_OK(
+        DecodeArg(scalar_fn.arguments(i), i, &call, ext_set, 
conversion_options));
+  }
+  return std::move(call);
+}
+
+Result<SubstraitCall> FromProto(const substrait::AggregateFunction& func, bool 
is_hash,
+                                const ExtensionSet& ext_set,
+                                const ConversionOptions& conversion_options) {
+  if (func.phase() != 
substrait::AggregationPhase::AGGREGATION_PHASE_INITIAL_TO_RESULT) {
+    return Status::NotImplemented(
+        "Unsupported aggregation phase.  Only INITIAL_TO_RESULT is supported");

Review Comment:
   That's a good idea.  I recall someone mentioning something about protobuf 
descriptors.  I'll see if I can figure out a good way to get this string value.



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