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

Remove unnecessary QualifiedFunctionName #19074

Merged
merged 1 commit into from
Sep 18, 2023
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 @@ -23,13 +23,13 @@
import io.trino.spi.function.CatalogSchemaFunctionName;
import io.trino.spi.function.FunctionMetadata;
import io.trino.spi.function.FunctionNullability;
import io.trino.spi.function.QualifiedFunctionName;
import io.trino.spi.function.Signature;
import io.trino.spi.type.Type;
import io.trino.spi.type.TypeManager;
import io.trino.sql.SqlPathElement;
import io.trino.sql.analyzer.TypeSignatureProvider;
import io.trino.sql.tree.Identifier;
import io.trino.sql.tree.QualifiedName;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -68,7 +68,7 @@ public FunctionResolver(Metadata metadata, TypeManager typeManager)
this.typeManager = requireNonNull(typeManager, "typeManager is null");
}

boolean isAggregationFunction(Session session, QualifiedFunctionName name, Function<CatalogSchemaFunctionName, Collection<CatalogFunctionMetadata>> candidateLoader)
boolean isAggregationFunction(Session session, QualifiedName name, Function<CatalogSchemaFunctionName, Collection<CatalogFunctionMetadata>> candidateLoader)
{
for (CatalogSchemaFunctionName catalogSchemaFunctionName : toPath(session, name)) {
Collection<CatalogFunctionMetadata> candidates = candidateLoader.apply(catalogSchemaFunctionName);
Expand All @@ -82,7 +82,7 @@ boolean isAggregationFunction(Session session, QualifiedFunctionName name, Funct
return false;
}

boolean isWindowFunction(Session session, QualifiedFunctionName name, Function<CatalogSchemaFunctionName, Collection<CatalogFunctionMetadata>> candidateLoader)
boolean isWindowFunction(Session session, QualifiedName name, Function<CatalogSchemaFunctionName, Collection<CatalogFunctionMetadata>> candidateLoader)
{
for (CatalogSchemaFunctionName catalogSchemaFunctionName : toPath(session, name)) {
Collection<CatalogFunctionMetadata> candidates = candidateLoader.apply(catalogSchemaFunctionName);
Expand Down Expand Up @@ -158,7 +158,7 @@ private static boolean possibleExactCastMatch(Signature signature, Signature dec

CatalogFunctionBinding resolveFunction(
Session session,
QualifiedFunctionName name,
QualifiedName name,
List<TypeSignatureProvider> parameterTypes,
Function<CatalogSchemaFunctionName, Collection<CatalogFunctionMetadata>> candidateLoader)
{
Expand Down Expand Up @@ -231,28 +231,32 @@ private Optional<CatalogFunctionBinding> match(List<TypeSignatureProvider> param
return matchFunctionWithCoercion(candidates, parameterTypes);
}

public static List<CatalogSchemaFunctionName> toPath(Session session, QualifiedFunctionName name)
public static List<CatalogSchemaFunctionName> toPath(Session session, QualifiedName name)
{
if (name.getCatalogName().isPresent()) {
return ImmutableList.of(new CatalogSchemaFunctionName(name.getCatalogName().orElseThrow(), name.getSchemaName().orElseThrow(), name.getFunctionName()));
List<String> parts = name.getParts();
if (parts.size() > 3) {
throw new TrinoException(FUNCTION_NOT_FOUND, "Invalid function name: " + name);
}
if (parts.size() == 3) {
return ImmutableList.of(new CatalogSchemaFunctionName(parts.get(0), parts.get(1), parts.get(2)));
}

if (name.getSchemaName().isPresent()) {
if (parts.size() == 2) {
String currentCatalog = session.getCatalog()
.orElseThrow(() -> new TrinoException(MISSING_CATALOG_NAME, "Session default catalog must be set to resolve a partial function name: " + name));
return ImmutableList.of(new CatalogSchemaFunctionName(currentCatalog, name.getSchemaName().orElseThrow(), name.getFunctionName()));
return ImmutableList.of(new CatalogSchemaFunctionName(currentCatalog, parts.get(0), parts.get(1)));
}

ImmutableList.Builder<CatalogSchemaFunctionName> names = ImmutableList.builder();

// global namespace
names.add(builtinFunctionName(name.getFunctionName()));
names.add(builtinFunctionName(parts.get(0)));

// add resolved path items
for (SqlPathElement sqlPathElement : session.getPath().getParsedPath()) {
String catalog = sqlPathElement.getCatalog().map(Identifier::getCanonicalValue).or(session::getCatalog)
.orElseThrow(() -> new TrinoException(MISSING_CATALOG_NAME, "Session default catalog must be set to resolve a partial function name: " + name));
names.add(new CatalogSchemaFunctionName(catalog, sqlPathElement.getSchema().getCanonicalValue(), name.getFunctionName()));
names.add(new CatalogSchemaFunctionName(catalog, sqlPathElement.getSchema().getCanonicalValue(), parts.get(0)));
}
return names.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
import io.trino.spi.function.FunctionId;
import io.trino.spi.function.FunctionMetadata;
import io.trino.spi.function.OperatorType;
import io.trino.spi.function.QualifiedFunctionName;
import io.trino.spi.function.SchemaFunctionName;
import io.trino.spi.function.Signature;
import io.trino.spi.predicate.TupleDomain;
Expand Down Expand Up @@ -2308,7 +2307,7 @@ public ResolvedFunction resolveFunction(Session session, QualifiedName name, Lis

CatalogFunctionBinding catalogFunctionBinding = functionResolver.resolveFunction(
session,
toQualifiedFunctionName(name),
name,
parameterTypes,
catalogSchemaFunctionName -> getFunctions(session, catalogSchemaFunctionName));
return resolve(session, catalogFunctionBinding);
Expand Down Expand Up @@ -2344,20 +2343,6 @@ public ResolvedFunction resolveOperator(OperatorType operatorType, List<? extend
}
}

// this is only public for TableFunctionRegistry, which is effectively part of MetadataManager but for some reason is a separate class
public static QualifiedFunctionName toQualifiedFunctionName(QualifiedName qualifiedName)
{
List<String> parts = qualifiedName.getParts();
checkArgument(parts.size() <= 3, "Function name can only have 3 parts: " + qualifiedName);
if (parts.size() == 3) {
return QualifiedFunctionName.of(parts.get(0), parts.get(1), parts.get(2));
}
if (parts.size() == 2) {
return QualifiedFunctionName.of(parts.get(0), parts.get(1));
}
return QualifiedFunctionName.of(parts.get(0));
}

@Override
public ResolvedFunction getCoercion(OperatorType operatorType, Type fromType, Type toType)
{
Expand Down Expand Up @@ -2559,15 +2544,15 @@ public boolean isAggregationFunction(Session session, QualifiedName name)
{
return functionDecoder.fromQualifiedName(name)
.map(function -> function.getFunctionKind() == AGGREGATE)
.orElseGet(() -> functionResolver.isAggregationFunction(session, toQualifiedFunctionName(name), catalogSchemaFunctionName -> getFunctions(session, catalogSchemaFunctionName)));
.orElseGet(() -> functionResolver.isAggregationFunction(session, name, catalogSchemaFunctionName -> getFunctions(session, catalogSchemaFunctionName)));
}

@Override
public boolean isWindowFunction(Session session, QualifiedName name)
{
return functionDecoder.fromQualifiedName(name)
.map(function -> function.getFunctionKind() == WINDOW)
.orElseGet(() -> functionResolver.isWindowFunction(session, toQualifiedFunctionName(name), catalogSchemaFunctionName -> getFunctions(session, catalogSchemaFunctionName)));
.orElseGet(() -> functionResolver.isWindowFunction(session, name, catalogSchemaFunctionName -> getFunctions(session, catalogSchemaFunctionName)));
}

private Collection<CatalogFunctionMetadata> getFunctions(Session session, CatalogSchemaFunctionName name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@
import static io.trino.SystemSessionProperties.getMaxGroupingSets;
import static io.trino.SystemSessionProperties.isLegacyMaterializedViewGracePeriod;
import static io.trino.metadata.FunctionResolver.toPath;
import static io.trino.metadata.MetadataManager.toQualifiedFunctionName;
import static io.trino.metadata.MetadataUtil.createQualifiedObjectName;
import static io.trino.metadata.MetadataUtil.getRequiredCatalogHandle;
import static io.trino.spi.StandardErrorCode.AMBIGUOUS_NAME;
Expand Down Expand Up @@ -1778,7 +1777,7 @@ else if (argument.getPartitionBy().isPresent()) {

private Optional<TableFunctionMetadata> resolveTableFunction(TableFunctionInvocation node)
{
for (CatalogSchemaFunctionName name : toPath(session, toQualifiedFunctionName(node.getName()))) {
for (CatalogSchemaFunctionName name : toPath(session, node.getName())) {
CatalogHandle catalogHandle = getRequiredCatalogHandle(metadata, session, node, name.getCatalogName());
Optional<ConnectorTableFunction> resolved = tableFunctionRegistry.resolve(catalogHandle, name.getSchemaFunctionName());
if (resolved.isPresent()) {
Expand Down

This file was deleted.

Loading