Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language function manager cleanup #21151

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private ResolvedFunction resolveBuiltin(CatalogFunctionBinding functionBinding)
functionBinder,
GlobalSystemConnector.CATALOG_HANDLE,
functionBinding.functionBinding(),
functionBinding.functionMetadata(),
functionBinding.boundFunctionMetadata(),
dependencies,
catalogSchemaFunctionName -> {
// builtin functions can only depend on other builtin functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,19 @@ public String toString()
}
}

record CatalogFunctionBinding(CatalogHandle catalogHandle, FunctionMetadata functionMetadata, FunctionBinding functionBinding)
/**
* Represents a function that has been bound to actual types.
*
* @param catalogHandle handle to the catalog containing the function
* @param boundFunctionMetadata metadata for the function with type parameters replaced with actual types
* @param functionBinding function binding containing function id, signature, and bound type parameters
*/
record CatalogFunctionBinding(CatalogHandle catalogHandle, FunctionMetadata boundFunctionMetadata, FunctionBinding functionBinding)
{
CatalogFunctionBinding
{
requireNonNull(catalogHandle, "catalogHandle is null");
requireNonNull(functionMetadata, "functionMetadata is null");
requireNonNull(boundFunctionMetadata, "boundFunctionMetadata is null");
requireNonNull(functionBinding, "functionBinding is null");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ public ScalarFunctionImplementation getScalarFunctionImplementation(ResolvedFunc

private ScalarFunctionImplementation getScalarFunctionImplementationInternal(ResolvedFunction resolvedFunction, InvocationConvention invocationConvention)
{
FunctionDependencies functionDependencies = getFunctionDependencies(resolvedFunction);

ScalarFunctionImplementation scalarFunctionImplementation;
if (isTrinoSqlLanguageFunction(resolvedFunction.getFunctionId())) {
scalarFunctionImplementation = languageFunctionProvider.specialize(this, resolvedFunction, functionDependencies, invocationConvention);
scalarFunctionImplementation = languageFunctionProvider.specialize(resolvedFunction.getFunctionId(), invocationConvention, this);
}
else {
FunctionDependencies functionDependencies = getFunctionDependencies(resolvedFunction);
scalarFunctionImplementation = getFunctionProvider(resolvedFunction).getScalarFunctionImplementation(
resolvedFunction.getFunctionId(),
resolvedFunction.getSignature(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.trino.spi.function.FunctionDependencyDeclaration.CastDependency;
import io.trino.spi.function.FunctionDependencyDeclaration.FunctionDependency;
import io.trino.spi.function.FunctionDependencyDeclaration.OperatorDependency;
import io.trino.spi.function.FunctionId;
import io.trino.spi.function.FunctionKind;
import io.trino.spi.function.FunctionMetadata;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -120,7 +121,7 @@ public ResolvedFunction resolveFunction(Session session, QualifiedName name, Lis
catalogSchemaFunctionName -> metadata.getFunctions(session, catalogSchemaFunctionName),
accessControl);

FunctionMetadata functionMetadata = catalogFunctionBinding.functionMetadata();
FunctionMetadata functionMetadata = catalogFunctionBinding.boundFunctionMetadata();
if (functionMetadata.isDeprecated()) {
warningCollector.add(new TrinoWarning(DEPRECATED_FUNCTION, "Use of deprecated function: %s: %s".formatted(name, functionMetadata.getDescription())));
}
Expand All @@ -131,22 +132,20 @@ public ResolvedFunction resolveFunction(Session session, QualifiedName name, Lis
private ResolvedFunction resolve(Session session, CatalogFunctionBinding functionBinding, AccessControl accessControl)
{
if (isTrinoSqlLanguageFunction(functionBinding.functionBinding().getFunctionId())) {
Set<ResolvedFunction> dependencies = languageFunctionManager.getDependencies(session, functionBinding.functionBinding().getFunctionId(), accessControl);
FunctionId resolvedFunctionId = languageFunctionManager.analyzeAndPlan(
session,
functionBinding.functionBinding().getFunctionId(),
accessControl);

ResolvedFunction resolvedFunction = new ResolvedFunction(
return new ResolvedFunction(
functionBinding.functionBinding().getBoundSignature(),
functionBinding.catalogHandle(),
functionBinding.functionBinding().getFunctionId(),
functionBinding.functionMetadata().getKind(),
functionBinding.functionMetadata().isDeterministic(),
functionBinding.functionMetadata().getFunctionNullability(),
resolvedFunctionId,
functionBinding.boundFunctionMetadata().getKind(),
functionBinding.boundFunctionMetadata().isDeterministic(),
functionBinding.boundFunctionMetadata().getFunctionNullability(),
ImmutableMap.of(),
dependencies);

// For SQL language functions, register the resolved function with the function manager,
// allowing the resolved function to be used later to retrieve the implementation.
languageFunctionManager.registerResolvedFunction(session, resolvedFunction);
return resolvedFunction;
ImmutableSet.of());
}

FunctionDependencyDeclaration dependencies = metadata.getFunctionDependencies(
Expand All @@ -161,7 +160,7 @@ private ResolvedFunction resolve(Session session, CatalogFunctionBinding functio
functionBinder,
functionBinding.catalogHandle(),
functionBinding.functionBinding(),
functionBinding.functionMetadata(),
functionBinding.boundFunctionMetadata(),
dependencies,
catalogSchemaFunctionName -> metadata.getFunctions(session, catalogSchemaFunctionName),
catalogFunctionBinding -> resolve(session, catalogFunctionBinding, accessControl));
Expand Down
Loading