Search in sources :

Example 26 with TypeSignature

use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.

the class TestMySqlFunctionNamespaceManager method testReturnTypeTooLong.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Return type exceeds max length of 30000.*")
public void testReturnTypeTooLong() {
    TypeSignature returnType = parseTypeSignature(dummyString(30001));
    createFunction(createFunctionTangent(returnType), false);
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 27 with TypeSignature

use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.

the class SignatureBinder method appendConstraintSolversForArguments.

private boolean appendConstraintSolversForArguments(ImmutableList.Builder<TypeConstraintSolver> resultBuilder, List<? extends TypeSignatureProvider> actualTypes) {
    boolean variableArity = declaredSignature.isVariableArity();
    List<TypeSignature> formalTypeSignatures = declaredSignature.getArgumentTypes();
    if (variableArity) {
        if (actualTypes.size() < formalTypeSignatures.size() - 1) {
            return false;
        }
        formalTypeSignatures = expandVarargFormalTypeSignature(formalTypeSignatures, actualTypes.size());
    }
    if (formalTypeSignatures.size() != actualTypes.size()) {
        return false;
    }
    for (int i = 0; i < formalTypeSignatures.size(); i++) {
        if (!appendTypeRelationshipConstraintSolver(resultBuilder, formalTypeSignatures.get(i), actualTypes.get(i), allowCoercion)) {
            return false;
        }
    }
    return appendConstraintSolvers(resultBuilder, formalTypeSignatures, actualTypes, allowCoercion);
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) LongVariableConstraint(com.facebook.presto.spi.function.LongVariableConstraint) TypeVariableConstraint(com.facebook.presto.spi.function.TypeVariableConstraint)

Example 28 with TypeSignature

use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.

the class SignatureBinder method checkNoLiteralVariableUsageAcrossTypes.

private static void checkNoLiteralVariableUsageAcrossTypes(TypeSignature typeSignature, Map<String, TypeSignature> existingUsages) {
    List<TypeSignatureParameter> variables = typeSignature.getParameters().stream().filter(TypeSignatureParameter::isVariable).collect(toList());
    for (TypeSignatureParameter variable : variables) {
        TypeSignature existing = existingUsages.get(variable.getVariable());
        if (existing != null && !existing.equals(typeSignature)) {
            throw new UnsupportedOperationException("Literal parameters may not be shared across different types");
        }
        existingUsages.put(variable.getVariable(), typeSignature);
    }
    for (TypeSignatureParameter parameter : typeSignature.getParameters()) {
        if (parameter.isLongLiteral() || parameter.isVariable()) {
            continue;
        }
        checkNoLiteralVariableUsageAcrossTypes(parameter.getTypeSignatureOrNamedTypeSignature().get(), existingUsages);
    }
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter)

Example 29 with TypeSignature

use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.

the class SignatureBinder method appendConstraintSolvers.

private boolean appendConstraintSolvers(ImmutableList.Builder<TypeConstraintSolver> resultBuilder, TypeSignature formalTypeSignature, TypeSignatureProvider actualTypeSignatureProvider, boolean allowCoercion) {
    if (FunctionType.NAME.equals(formalTypeSignature.getBase())) {
        List<TypeSignature> formalTypeParameterTypeSignatures = formalTypeSignature.getTypeParametersAsTypeSignatures();
        resultBuilder.add(new FunctionSolver(getLambdaArgumentTypeSignatures(formalTypeSignature), formalTypeParameterTypeSignatures.get(formalTypeParameterTypeSignatures.size() - 1), actualTypeSignatureProvider));
        return true;
    }
    if (actualTypeSignatureProvider.hasDependency()) {
        return false;
    }
    if (formalTypeSignature.getParameters().isEmpty()) {
        TypeVariableConstraint typeVariableConstraint = typeVariableConstraints.get(formalTypeSignature.getBase());
        if (typeVariableConstraint == null) {
            return true;
        }
        Type actualType = functionAndTypeManager.getType(actualTypeSignatureProvider.getTypeSignature());
        resultBuilder.add(new TypeParameterSolver(formalTypeSignature.getBase(), actualType, typeVariableConstraint));
        return true;
    }
    Type actualType = functionAndTypeManager.getType(actualTypeSignatureProvider.getTypeSignature());
    if (isTypeWithLiteralParameters(formalTypeSignature)) {
        resultBuilder.add(new TypeWithLiteralParametersSolver(formalTypeSignature, actualType));
        return true;
    }
    List<TypeSignatureProvider> actualTypeParametersTypeSignatureProvider;
    if (UNKNOWN.equals(actualType)) {
        actualTypeParametersTypeSignatureProvider = Collections.nCopies(formalTypeSignature.getParameters().size(), new TypeSignatureProvider(UNKNOWN.getTypeSignature()));
    } else {
        actualTypeParametersTypeSignatureProvider = fromTypes(actualType.getTypeParameters());
    }
    ImmutableList.Builder<TypeSignature> formalTypeParameterTypeSignatures = ImmutableList.builder();
    for (TypeSignatureParameter formalTypeParameter : formalTypeSignature.getParameters()) {
        Optional<TypeSignature> typeSignature = formalTypeParameter.getTypeSignatureOrNamedTypeSignature();
        if (!typeSignature.isPresent()) {
            throw new UnsupportedOperationException("Types with both type parameters and literal parameters at the same time are not supported");
        }
        formalTypeParameterTypeSignatures.add(typeSignature.get());
    }
    return appendConstraintSolvers(resultBuilder, formalTypeParameterTypeSignatures.build(), actualTypeParametersTypeSignatureProvider, allowCoercion && isCovariantTypeBase(formalTypeSignature.getBase()));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TypeVariableConstraint(com.facebook.presto.spi.function.TypeVariableConstraint) TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) TypeSignature(com.facebook.presto.common.type.TypeSignature) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) Type(com.facebook.presto.common.type.Type) FunctionType(com.facebook.presto.common.type.FunctionType) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter)

Example 30 with TypeSignature

use of com.facebook.presto.common.type.TypeSignature in project presto by prestodb.

the class SignatureBinder method applyBoundVariables.

public static Type applyBoundVariables(FunctionAndTypeManager functionAndTypeManager, TypeSignature typeSignature, BoundVariables boundVariables) {
    String baseType = typeSignature.getBase();
    if (boundVariables.containsTypeVariable(baseType)) {
        checkState(typeSignature.getParameters().isEmpty(), "Type parameters cannot have parameters");
        Type type = boundVariables.getTypeVariable(baseType);
        if (type instanceof TypeWithName) {
            return ((TypeWithName) type).getType();
        }
        return type;
    }
    List<TypeSignatureParameter> parameters = typeSignature.getParameters().stream().map(typeSignatureParameter -> applyBoundVariables(typeSignatureParameter, boundVariables)).collect(toList());
    return functionAndTypeManager.getParameterizedType(baseType, parameters);
}
Also used : StandardTypes(com.facebook.presto.common.type.StandardTypes) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) LongVariableConstraint(com.facebook.presto.spi.function.LongVariableConstraint) HashMap(java.util.HashMap) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) TypeSignature(com.facebook.presto.common.type.TypeSignature) HashSet(java.util.HashSet) TypeCalculation.calculateLiteralValue(com.facebook.presto.type.TypeCalculation.calculateLiteralValue) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toMap(java.util.stream.Collectors.toMap) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ParameterKind(com.facebook.presto.common.type.ParameterKind) Type(com.facebook.presto.common.type.Type) TypeWithName(com.facebook.presto.common.type.TypeWithName) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) VerifyException(com.google.common.base.VerifyException) ImmutableSet(com.google.common.collect.ImmutableSet) TypeVariableConstraint(com.facebook.presto.spi.function.TypeVariableConstraint) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) FunctionType(com.facebook.presto.common.type.FunctionType) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) UNKNOWN(com.facebook.presto.common.type.UnknownType.UNKNOWN) Collectors.toList(java.util.stream.Collectors.toList) Signature(com.facebook.presto.spi.function.Signature) Function.identity(java.util.function.Function.identity) TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) Optional(java.util.Optional) Collections(java.util.Collections) Type(com.facebook.presto.common.type.Type) FunctionType(com.facebook.presto.common.type.FunctionType) TypeWithName(com.facebook.presto.common.type.TypeWithName) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter)

Aggregations

TypeSignature (com.facebook.presto.common.type.TypeSignature)60 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)25 Signature (com.facebook.presto.spi.function.Signature)20 NamedTypeSignature (com.facebook.presto.common.type.NamedTypeSignature)19 ImmutableList (com.google.common.collect.ImmutableList)19 List (java.util.List)17 PrestoException (com.facebook.presto.spi.PrestoException)15 Type (com.facebook.presto.common.type.Type)14 Test (org.testng.annotations.Test)14 TypeSignatureParameter (com.facebook.presto.common.type.TypeSignatureParameter)13 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)13 Objects.requireNonNull (java.util.Objects.requireNonNull)12 RowFieldName (com.facebook.presto.common.type.RowFieldName)10 StandardTypes (com.facebook.presto.common.type.StandardTypes)9 Optional (java.util.Optional)9 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)8 DecimalType (com.facebook.presto.common.type.DecimalType)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 RowType (com.facebook.presto.common.type.RowType)7 ArrayType (com.facebook.presto.common.type.ArrayType)6