MCPcopy Create free account
hub / github.com/apache/arrow / EncodeSubstraitCall

Function EncodeSubstraitCall

cpp/src/arrow/engine/substrait/expression_internal.cc:1255–1292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1253}
1254
1255Result<std::unique_ptr<substrait::Expression::ScalarFunction>> EncodeSubstraitCall(
1256 const SubstraitCall& call, ExtensionSet* ext_set,
1257 const ConversionOptions& conversion_options) {
1258 ARROW_ASSIGN_OR_RAISE(uint32_t anchor, ext_set->EncodeFunction(call.id()));
1259 auto scalar_fn = std::make_unique<substrait::Expression::ScalarFunction>();
1260 scalar_fn->set_function_reference(anchor);
1261 ARROW_ASSIGN_OR_RAISE(
1262 std::unique_ptr<substrait::Type> output_type,
1263 ToProto(*call.output_type(), call.output_nullable(), ext_set, conversion_options));
1264 scalar_fn->set_allocated_output_type(output_type.release());
1265
1266 for (int i = 0; i < call.size(); i++) {
1267 substrait::FunctionArgument* arg = scalar_fn->add_arguments();
1268 if (call.HasEnumArg(i)) {
1269 ARROW_ASSIGN_OR_RAISE(std::string_view enum_val, call.GetEnumArg(i));
1270 arg->set_enum_(std::string(enum_val));
1271 } else if (call.HasValueArg(i)) {
1272 ARROW_ASSIGN_OR_RAISE(compute::Expression value_arg, call.GetValueArg(i));
1273 ARROW_ASSIGN_OR_RAISE(std::unique_ptr<substrait::Expression> value_expr,
1274 ToProto(value_arg, ext_set, conversion_options));
1275 arg->set_allocated_value(value_expr.release());
1276 } else {
1277 return Status::Invalid("Call reported having ", call.size(),
1278 " arguments but no argument could be found at index ", i);
1279 }
1280 }
1281
1282 for (const auto& option : call.options()) {
1283 substrait::FunctionOption* fn_option = scalar_fn->add_options();
1284 fn_option->set_name(option.first);
1285 for (const auto& opt_val : option.second) {
1286 std::string* pref = fn_option->add_preference();
1287 *pref = opt_val;
1288 }
1289 }
1290
1291 return scalar_fn;
1292}
1293
1294Result<std::vector<std::unique_ptr<substrait::Expression>>> DatumToLiterals(
1295 const Datum& datum, ExtensionSet* ext_set,

Callers 1

ToProtoFunction · 0.85

Calls 8

HasEnumArgMethod · 0.80
HasValueArgMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
ToProtoFunction · 0.70
InvalidFunction · 0.50
releaseMethod · 0.45
sizeMethod · 0.45
optionsMethod · 0.45

Tested by

no test coverage detected