Skip to content

Commit

Permalink
Support retrieving function metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsatya committed Mar 26, 2024
1 parent 3aa020d commit bfea9ca
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions velox/expression/VectorFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ std::optional<std::vector<FunctionSignaturePtr>> getVectorFunctionSignatures(
});
}

std::optional<VectorFunctionMetadata> getVectorFunctionMetadata(
const std::string& name) {
return applyToVectorFunctionEntry<VectorFunctionMetadata>(
name,
[&](const auto& /*name*/, const auto& entry) { return entry.metadata; });
}

TypePtr resolveVectorFunction(
const std::string& functionName,
const std::vector<TypePtr>& argTypes) {
Expand Down
5 changes: 5 additions & 0 deletions velox/expression/VectorFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class SimpleFunctionAdapterFactory {
std::optional<std::vector<FunctionSignaturePtr>> getVectorFunctionSignatures(
const std::string& name);

/// Returns metadata corresponding to function with the specified name. Returns
/// std::nullopt if there is no function with the specified name.
std::optional<VectorFunctionMetadata> getVectorFunctionMetadata(
const std::string& name);

/// Given name of vector function and argument types, returns
/// the return type if function exists and have a signature that binds to the
/// input types otherwise returns nullptr.
Expand Down
9 changes: 9 additions & 0 deletions velox/functions/CoverageUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

namespace facebook::velox::functions {

// Returns sorted list of scalar function names available in Velox.
std::vector<std::string> getSortedScalarNames();

// Returns sorted list of aggregate function names available in Velox.
std::vector<std::string> getSortedAggregateNames();

// Returns sorted list of window function names available in Velox.
std::vector<std::string> getSortedWindowNames();

// Print a rst format string which contains all Presto/Spark scalar
// functions and aggragate functions. This function will read
// all_scalar_functions.txt and all_aggregate_functions.txt from certain path.
Expand Down
19 changes: 19 additions & 0 deletions velox/functions/FunctionRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,23 @@ resolveVectorFunctionWithMetadata(
return exec::resolveVectorFunctionWithMetadata(functionName, argTypes);
}

exec::VectorFunctionMetadata getFunctionMetadata(
const std::string& functionName) {
auto simpleFunctionMetadata =
exec::simpleFunctions().getFunctionSignaturesAndMetadata(functionName);
if (simpleFunctionMetadata.size()) {
// Functions like abs are registered as simple functions for primitive
// types, and as a vector function for complex types like DECIMAL. So do not
// throw an error if function metadata is not found in simple function
// signature map.
return simpleFunctionMetadata.back().first;
}

auto vectorFunctionMetadata = exec::getVectorFunctionMetadata(functionName);
if (vectorFunctionMetadata.has_value()) {
return vectorFunctionMetadata.value();
}
VELOX_USER_FAIL("Metadata not found for scalar function {}", functionName);
}

} // namespace facebook::velox
4 changes: 4 additions & 0 deletions velox/functions/FunctionRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ resolveVectorFunctionWithMetadata(
/// Clears the function registry.
void clearFunctionRegistry();

/// Get the function metadata corresponding to functionName.
exec::VectorFunctionMetadata getFunctionMetadata(
const std::string& functionName);

} // namespace facebook::velox

0 comments on commit bfea9ca

Please sign in to comment.