Skip to content

Commit 673c80f

Browse files
pramodsatyaaditi-pandit
authored andcommitted
[native] Detect companion functions from velox function metadata
1 parent 391541a commit 673c80f

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

presto-native-execution/presto_cpp/main/types/FunctionMetadata.cpp

+2-27
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,6 @@ const std::vector<std::string> getFunctionNameParts(
5757
return parts;
5858
}
5959

60-
// TODO: Remove this function later and retrieve companion function information
61-
// from velox. Approaches for this under discussion here:
62-
// https://github.com/facebookincubator/velox/discussions/11011.
63-
// A function name is a companion function's if the name is an existing
64-
// aggregation function name followed by specific suffixes.
65-
bool isCompanionFunctionName(
66-
const std::string& name,
67-
const std::unordered_map<std::string, exec::AggregateFunctionEntry>&
68-
aggregateFunctions) {
69-
auto suffixOffset = name.rfind("_partial");
70-
if (suffixOffset == std::string::npos) {
71-
suffixOffset = name.rfind("_merge_extract");
72-
}
73-
if (suffixOffset == std::string::npos) {
74-
suffixOffset = name.rfind("_merge");
75-
}
76-
if (suffixOffset == std::string::npos) {
77-
suffixOffset = name.rfind("_extract");
78-
}
79-
if (suffixOffset == std::string::npos) {
80-
return false;
81-
}
82-
return aggregateFunctions.count(name.substr(0, suffixOffset)) > 0;
83-
}
84-
8560
const protocol::AggregationFunctionMetadata getAggregationFunctionMetadata(
8661
const std::string& name,
8762
const AggregateFunctionSignature& signature) {
@@ -287,7 +262,7 @@ json getFunctionsMetadata() {
287262
// Skip internal functions. They don't have any prefix.
288263
if (kBlockList.count(name) != 0 ||
289264
name.find("$internal$") != std::string::npos ||
290-
isCompanionFunctionName(name, aggregateFunctions)) {
265+
getScalarMetadata(name).companionFunction) {
291266
continue;
292267
}
293268

@@ -299,7 +274,7 @@ json getFunctionsMetadata() {
299274

300275
// Get metadata for all registered aggregate functions in velox.
301276
for (const auto& entry : aggregateFunctions) {
302-
if (!isCompanionFunctionName(entry.first, aggregateFunctions)) {
277+
if (!aggregateFunctions.at(entry.first).metadata.companionFunction) {
303278
const auto name = entry.first;
304279
const auto parts = getFunctionNameParts(name);
305280
const auto schema = parts[1];

0 commit comments

Comments
 (0)