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

Function DecodeBasicAggregate

cpp/src/arrow/engine/substrait/extension_set.cc:1047–1110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1045}
1046
1047ExtensionIdRegistry::SubstraitAggregateToArrow DecodeBasicAggregate(
1048 const std::string& arrow_function_name) {
1049 return [arrow_function_name](const SubstraitCall& call) -> Result<compute::Aggregate> {
1050 std::string fixed_arrow_func;
1051 if (call.is_hash()) {
1052 fixed_arrow_func = "hash_";
1053 }
1054
1055 switch (call.size()) {
1056 case 0: {
1057 if (call.id().name == "count") {
1058 fixed_arrow_func += "count_all";
1059 return compute::Aggregate{std::move(fixed_arrow_func), ""};
1060 }
1061 return Status::Invalid("Expected aggregate call ", call.id().uri, "#",
1062 call.id().name, " to have at least one argument");
1063 }
1064 default: {
1065 // Handles all arity > 0
1066
1067 std::shared_ptr<compute::FunctionOptions> options = nullptr;
1068 if (arrow_function_name == "stddev" || arrow_function_name == "variance") {
1069 // See the following URL for the spec of stddev and variance:
1070 // https://github.com/substrait-io/substrait/blob/
1071 // 73228b4112d79eb1011af0ebb41753ce23ca180c/
1072 // extensions/functions_arithmetic.yaml#L1240
1073 auto maybe_dist = call.GetOption("distribution");
1074 if (maybe_dist) {
1075 auto& prefs = **maybe_dist;
1076 if (prefs.size() != 1) {
1077 return Status::Invalid("expected a single preference for ",
1078 arrow_function_name, " but got ", prefs.size());
1079 }
1080 int ddof;
1081 if (prefs[0] == "POPULATION") {
1082 ddof = 1;
1083 } else if (prefs[0] == "SAMPLE") {
1084 ddof = 0;
1085 } else {
1086 return Status::Invalid("unknown distribution preference ", prefs[0]);
1087 }
1088 options = std::make_shared<compute::VarianceOptions>(ddof);
1089 }
1090 }
1091 fixed_arrow_func += arrow_function_name;
1092
1093 std::vector<FieldRef> target;
1094 for (int i = 0; i < call.size(); i++) {
1095 ARROW_ASSIGN_OR_RAISE(compute::Expression arg, call.GetValueArg(i));
1096 const FieldRef* arg_ref = arg.field_ref();
1097 if (!arg_ref) {
1098 return Status::Invalid("Expected an aggregate call ", call.id().uri, "#",
1099 call.id().name, " to have a direct reference");
1100 }
1101 // Copy arg_ref here because field_ref() return const FieldRef*
1102 target.emplace_back(*arg_ref);
1103 }
1104 return compute::Aggregate{std::move(fixed_arrow_func),

Callers 2

extension_set.ccFile · 0.85

Calls 6

GetOptionMethod · 0.80
field_refMethod · 0.80
emplace_backMethod · 0.80
InvalidFunction · 0.50
sizeMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected