Skip to content

Commit c94c8a2

Browse files
committed
Review comment
1 parent 9aba879 commit c94c8a2

File tree

2 files changed

+10
-61
lines changed

2 files changed

+10
-61
lines changed

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

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ json buildWindowMetadata(
265265

266266
} // namespace
267267

268-
json getFunctionsMetadata() {
268+
json getFunctionsMetadata(const std::optional<std::string>& catalog) {
269269
json j;
270270

271271
// Get metadata for all registered scalar functions in velox.
@@ -285,60 +285,8 @@ json getFunctionsMetadata() {
285285
}
286286

287287
const auto parts = getFunctionNameParts(name);
288-
const auto schema = parts[1];
289-
const auto function = parts[2];
290-
j[function] = buildScalarMetadata(name, schema, entry.second);
291-
}
292-
293-
// Get metadata for all registered aggregate functions in velox.
294-
for (const auto& entry : aggregateFunctions) {
295-
if (!aggregateFunctions.at(entry.first).metadata.companionFunction) {
296-
const auto name = entry.first;
297-
const auto parts = getFunctionNameParts(name);
298-
const auto schema = parts[1];
299-
const auto function = parts[2];
300-
j[function] =
301-
buildAggregateMetadata(name, schema, entry.second.signatures);
302-
}
303-
}
304-
305-
// Get metadata for all registered window functions in velox. Skip aggregates
306-
// as they have been processed.
307-
const auto& functions = exec::windowFunctions();
308-
for (const auto& entry : functions) {
309-
if (aggregateFunctions.count(entry.first) == 0) {
310-
const auto name = entry.first;
311-
const auto parts = getFunctionNameParts(entry.first);
312-
const auto schema = parts[1];
313-
const auto function = parts[2];
314-
j[function] = buildWindowMetadata(name, schema, entry.second.signatures);
315-
}
316-
}
317-
318-
return j;
319-
}
320-
321-
json getFunctionsMetadata(const std::string& catalog) {
322-
json j;
323-
324-
// Get metadata for all registered scalar functions in velox.
325-
const auto signatures = getFunctionSignatures();
326-
static const std::unordered_set<std::string> kBlockList = {
327-
"row_constructor", "in", "is_null"};
328-
// Exclude aggregate companion functions (extract aggregate companion
329-
// functions are registered as vector functions).
330-
const auto aggregateFunctions = exec::aggregateFunctions().copy();
331-
for (const auto& entry : signatures) {
332-
const auto name = entry.first;
333-
// Skip internal functions. They don't have any prefix.
334-
if (kBlockList.count(name) != 0 ||
335-
name.find("$internal$") != std::string::npos ||
336-
getScalarMetadata(name).companionFunction) {
337-
continue;
338-
}
339-
340-
const auto parts = getFunctionNameParts(name);
341-
if (parts[0] != catalog) {
288+
// Skip if catalog filter is specified and doesn't match
289+
if (catalog.has_value() && parts[0] != catalog.value()) {
342290
continue;
343291
}
344292
const auto schema = parts[1];
@@ -351,7 +299,8 @@ json getFunctionsMetadata(const std::string& catalog) {
351299
if (!aggregateFunctions.at(entry.first).metadata.companionFunction) {
352300
const auto name = entry.first;
353301
const auto parts = getFunctionNameParts(name);
354-
if (parts[0] != catalog) {
302+
// Skip if catalog filter is specified and doesn't match
303+
if (catalog.has_value() && parts[0] != catalog.value()) {
355304
continue;
356305
}
357306
const auto schema = parts[1];
@@ -368,7 +317,8 @@ json getFunctionsMetadata(const std::string& catalog) {
368317
if (aggregateFunctions.count(entry.first) == 0) {
369318
const auto name = entry.first;
370319
const auto parts = getFunctionNameParts(entry.first);
371-
if (parts[0] != catalog) {
320+
// Skip if catalog filter is specified and doesn't match
321+
if (catalog.has_value() && parts[0] != catalog.value()) {
372322
continue;
373323
}
374324
const auto schema = parts[1];

presto-native-execution/presto_cpp/main/functions/FunctionMetadata.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
#pragma once
1616

17+
#include <optional>
1718
#include "presto_cpp/external/json/nlohmann/json.hpp"
1819

1920
namespace facebook::presto {
2021

2122
// Returns metadata for all registered functions as json.
22-
nlohmann::json getFunctionsMetadata();
23-
24-
// Returns metadata for all registered functions filtered by catalog as json.
25-
nlohmann::json getFunctionsMetadata(const std::string& catalog);
23+
nlohmann::json getFunctionsMetadata(
24+
const std::optional<std::string>& catalog = std::nullopt);
2625

2726
} // namespace facebook::presto

0 commit comments

Comments
 (0)