Skip to content

Commit

Permalink
Change Signature to use FullyQualifiedName
Browse files Browse the repository at this point in the history
  • Loading branch information
rongrong committed Sep 4, 2019
1 parent d8f34b0 commit 9622d26
Show file tree
Hide file tree
Showing 89 changed files with 406 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
package com.facebook.presto.metadata;

import com.facebook.presto.spi.function.OperatorType;
import com.facebook.presto.spi.relation.FullyQualifiedName;

import static com.facebook.presto.metadata.OperatorSignatureUtils.mangleOperatorName;
import static com.facebook.presto.metadata.StaticFunctionNamespace.DEFAULT_NAMESPACE;
import static com.facebook.presto.operator.scalar.JsonStringToArrayCast.JSON_STRING_TO_ARRAY_NAME;
import static com.facebook.presto.operator.scalar.JsonStringToMapCast.JSON_STRING_TO_MAP_NAME;
import static com.facebook.presto.operator.scalar.JsonStringToRowCast.JSON_STRING_TO_ROW_NAME;
Expand All @@ -24,23 +25,23 @@

public enum CastType
{
CAST(mangleOperatorName(OperatorType.CAST.name()), true),
SATURATED_FLOOR_CAST(mangleOperatorName(OperatorType.SATURATED_FLOOR_CAST.name()), true),
TRY_CAST(TRY_CAST_NAME, false),
JSON_TO_ARRAY_CAST(JSON_STRING_TO_ARRAY_NAME, false),
JSON_TO_MAP_CAST(JSON_STRING_TO_MAP_NAME, false),
JSON_TO_ROW_CAST(JSON_STRING_TO_ROW_NAME, false);
CAST(OperatorType.CAST.getFunctionName(), true),
SATURATED_FLOOR_CAST(OperatorType.SATURATED_FLOOR_CAST.getFunctionName(), true),
TRY_CAST(FullyQualifiedName.of(DEFAULT_NAMESPACE, TRY_CAST_NAME), false),
JSON_TO_ARRAY_CAST(FullyQualifiedName.of(DEFAULT_NAMESPACE, JSON_STRING_TO_ARRAY_NAME), false),
JSON_TO_MAP_CAST(FullyQualifiedName.of(DEFAULT_NAMESPACE, JSON_STRING_TO_MAP_NAME), false),
JSON_TO_ROW_CAST(FullyQualifiedName.of(DEFAULT_NAMESPACE, JSON_STRING_TO_ROW_NAME), false);

private final String castName;
private final FullyQualifiedName castName;
private final boolean isOperatorType;

CastType(String castName, boolean isOperatorType)
CastType(FullyQualifiedName castName, boolean isOperatorType)
{
this.castName = castName;
this.isOperatorType = isOperatorType;
}

public String getCastName()
public FullyQualifiedName getCastName()
{
return castName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.presto.spi.function.FunctionMetadata;
import com.facebook.presto.spi.function.FunctionMetadataManager;
import com.facebook.presto.spi.function.OperatorType;
import com.facebook.presto.spi.relation.FullyQualifiedName;
import com.facebook.presto.spi.type.TypeManager;
import com.facebook.presto.spi.type.TypeSignature;
import com.facebook.presto.sql.analyzer.FeaturesConfig;
Expand All @@ -33,6 +34,8 @@

import java.util.List;

import static com.facebook.presto.metadata.StaticFunctionNamespace.DEFAULT_NAMESPACE;

@ThreadSafe
public class FunctionManager
implements FunctionMetadataManager
Expand Down Expand Up @@ -76,7 +79,7 @@ public FunctionHandle resolveFunction(Session session, QualifiedName name, List<
// This is likely to be in terms of SQL path. Currently we still don't have support multiple function namespaces, nor
// SQL path. As a result, session is not used here. We still add this to distinguish the two versions of resolveFunction
// while the refactoring is on-going.
return staticFunctionNamespace.resolveFunction(name, parameterTypes);
return staticFunctionNamespace.resolveFunction(FullyQualifiedName.of(DEFAULT_NAMESPACE, name.getSuffix()), parameterTypes);
}

@Override
Expand Down Expand Up @@ -113,7 +116,7 @@ public FunctionHandle resolveOperator(OperatorType operatorType, List<TypeSignat
*/
public FunctionHandle lookupFunction(String name, List<TypeSignatureProvider> parameterTypes)
{
return staticFunctionNamespace.lookupFunction(QualifiedName.of(name), parameterTypes);
return staticFunctionNamespace.lookupFunction(FullyQualifiedName.of(DEFAULT_NAMESPACE, name), parameterTypes);
}

public FunctionHandle lookupCast(CastType castType, TypeSignature fromType, TypeSignature toType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import com.facebook.presto.spi.function.FunctionHandle;
import com.facebook.presto.spi.function.FunctionMetadata;
import com.facebook.presto.spi.relation.FullyQualifiedName;
import com.facebook.presto.sql.analyzer.TypeSignatureProvider;
import com.facebook.presto.sql.tree.QualifiedName;

import java.util.List;

Expand All @@ -26,7 +26,7 @@ public interface FunctionNamespace

List<SqlFunction> listFunctions();

FunctionHandle resolveFunction(QualifiedName name, List<TypeSignatureProvider> parameterTypes);
FunctionHandle resolveFunction(FullyQualifiedName name, List<TypeSignatureProvider> parameterTypes);

FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Optional;
import java.util.function.Function;

import static com.facebook.presto.metadata.OperatorSignatureUtils.mangleOperatorName;
import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty;
import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.BLOCK_AND_POSITION;
import static com.facebook.presto.operator.scalar.ScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL;
Expand Down Expand Up @@ -136,7 +135,7 @@ public static <T> Function<SpecializeContext, List<Object>> constant(T value)
private static boolean isOperator(Signature signature)
{
for (OperatorType operator : OperatorType.values()) {
if (signature.getName().equals(mangleOperatorName(operator))) {
if (signature.getName().equals(operator.getFunctionName())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
import com.facebook.presto.spi.function.OperatorType;
import com.facebook.presto.spi.function.Signature;
import com.facebook.presto.spi.function.TypeVariableConstraint;
import com.facebook.presto.spi.relation.FullyQualifiedName;
import com.facebook.presto.spi.type.TypeSignature;
import com.google.common.collect.ImmutableList;

import java.util.List;

import static com.facebook.presto.metadata.OperatorSignatureUtils.mangleOperatorName;
import static com.facebook.presto.metadata.StaticFunctionNamespace.DEFAULT_NAMESPACE;
import static com.facebook.presto.spi.function.FunctionKind.SCALAR;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;

public final class SignatureBuilder
{
private String name;
private FullyQualifiedName name;
private FunctionKind kind;
private List<TypeVariableConstraint> typeVariableConstraints = emptyList();
private List<LongVariableConstraint> longVariableConstraints = emptyList();
Expand All @@ -47,6 +48,12 @@ public static SignatureBuilder builder()
}

public SignatureBuilder name(String name)
{
this.name = FullyQualifiedName.of(DEFAULT_NAMESPACE, requireNonNull(name, "name is null"));
return this;
}

public SignatureBuilder name(FullyQualifiedName name)
{
this.name = requireNonNull(name, "name is null");
return this;
Expand All @@ -60,7 +67,7 @@ public SignatureBuilder kind(FunctionKind kind)

public SignatureBuilder operatorType(OperatorType operatorType)
{
this.name = mangleOperatorName(requireNonNull(operatorType, "operatorType is null"));
this.name = operatorType.getFunctionName();
this.kind = SCALAR;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import com.facebook.presto.spi.function.LongVariableConstraint;
import com.facebook.presto.spi.function.Signature;
import com.facebook.presto.spi.function.TypeVariableConstraint;
import com.facebook.presto.spi.relation.FullyQualifiedName;
import com.facebook.presto.spi.type.TypeManager;
import com.facebook.presto.spi.type.TypeSignature;
import com.google.common.collect.ImmutableList;

import java.util.List;

import static com.facebook.presto.metadata.StaticFunctionNamespace.DEFAULT_NAMESPACE;
import static com.facebook.presto.spi.function.FunctionKind.AGGREGATE;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
Expand Down Expand Up @@ -91,7 +93,7 @@ private static Signature createSignature(
requireNonNull(argumentTypes, "argumentTypes is null");
checkArgument(kind == AGGREGATE, "kind must be an aggregate");
return new Signature(
name,
FullyQualifiedName.of(DEFAULT_NAMESPACE, name),
kind,
ImmutableList.copyOf(typeVariableConstraints),
ImmutableList.copyOf(longVariableConstraints),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import java.util.List;

import static com.facebook.presto.metadata.OperatorSignatureUtils.mangleOperatorName;

public abstract class SqlOperator
extends SqlScalarFunction
{
Expand All @@ -33,7 +31,7 @@ protected SqlOperator(OperatorType operatorType, List<TypeVariableConstraint> ty
{
// TODO This should take Signature!
super(new Signature(
mangleOperatorName(operatorType),
operatorType.getFunctionName(),
FunctionKind.SCALAR,
typeVariableConstraints,
longVariableConstraints,
Expand Down
Loading

0 comments on commit 9622d26

Please sign in to comment.