Search in sources :

Example 11 with TypeSignatureParameter

use of io.prestosql.spi.type.TypeSignatureParameter in project hetu-core by openlookeng.

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.isComparableRequired(), typeVariableConstraint.isOrderableRequired(), Optional.ofNullable(typeVariableConstraint.getVariadicBound())));
        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 = TypeSignatureProvider.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(io.prestosql.spi.function.TypeVariableConstraint) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) Type(io.prestosql.spi.type.Type) FunctionType(io.prestosql.spi.type.FunctionType) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter)

Example 12 with TypeSignatureParameter

use of io.prestosql.spi.type.TypeSignatureParameter in project hetu-core by openlookeng.

the class TypeUtil method parametricType.

private static Type parametricType(TypeManager typeManager, TypeSignature typeSignature) {
    String typeName = typeSignature.getBase().toLowerCase(Locale.ENGLISH);
    ParametricType parametricType = PARAMETRIC_TYPE_MAP.get(typeName);
    if (parametricType != null) {
        List<TypeParameter> parameters = new ArrayList<>();
        for (TypeSignatureParameter parameter : typeSignature.getParameters()) {
            TypeParameter typeParameter = TypeParameter.of(parameter, typeManager);
            parameters.add(typeParameter);
        }
        return parametricType.createType(typeManager, parameters);
    }
    return null;
}
Also used : TypeParameter(io.prestosql.spi.type.TypeParameter) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) ArrayList(java.util.ArrayList) ParametricType(io.prestosql.spi.type.ParametricType)

Aggregations

TypeSignatureParameter (io.prestosql.spi.type.TypeSignatureParameter)12 NamedTypeSignature (io.prestosql.spi.type.NamedTypeSignature)7 Type (io.prestosql.spi.type.Type)7 ImmutableList (com.google.common.collect.ImmutableList)6 PrestoException (io.prestosql.spi.PrestoException)5 VarcharType (io.prestosql.spi.type.VarcharType)5 ArrayList (java.util.ArrayList)5 CharType (io.prestosql.spi.type.CharType)4 DecimalType (io.prestosql.spi.type.DecimalType)4 TypeSignature (io.prestosql.spi.type.TypeSignature)4 RowFieldName (io.prestosql.spi.type.RowFieldName)3 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)3 Optional (java.util.Optional)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)2 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1