Search in sources :

Example 1 with TypeParameter

use of com.facebook.presto.spi.type.TypeParameter in project presto by prestodb.

the class MapParametricType method createType.

@Override
public Type createType(List<TypeParameter> parameters) {
    checkArgument(parameters.size() == 2, "Expected two parameters, got %s", parameters);
    TypeParameter firstParameter = parameters.get(0);
    TypeParameter secondParameter = parameters.get(1);
    checkArgument(firstParameter.getKind() == ParameterKind.TYPE && secondParameter.getKind() == ParameterKind.TYPE, "Expected key and type to be types, got %s", parameters);
    return new MapType(firstParameter.getType(), secondParameter.getType());
}
Also used : TypeParameter(com.facebook.presto.spi.type.TypeParameter)

Example 2 with TypeParameter

use of com.facebook.presto.spi.type.TypeParameter in project presto by prestodb.

the class TypeRegistry method instantiateParametricType.

private Type instantiateParametricType(TypeSignature signature) {
    List<TypeParameter> parameters = new ArrayList<>();
    for (TypeSignatureParameter parameter : signature.getParameters()) {
        TypeParameter typeParameter = TypeParameter.of(parameter, this);
        if (typeParameter == null) {
            return null;
        }
        parameters.add(typeParameter);
    }
    ParametricType parametricType = parametricTypes.get(signature.getBase().toLowerCase(Locale.ENGLISH));
    if (parametricType == null) {
        return null;
    }
    try {
        Type instantiatedType = parametricType.createType(parameters);
        //checkState(instantiatedType.equalsSignature(signature), "Instantiated parametric type name (%s) does not match expected name (%s)", instantiatedType, signature);
        return instantiatedType;
    } catch (IllegalArgumentException e) {
        // TODO: check whether a type constructor actually exists rather than failing when it doesn't. This will be possible in the next version of the type system
        return null;
    }
}
Also used : TypeParameter(com.facebook.presto.spi.type.TypeParameter) CharType.createCharType(com.facebook.presto.spi.type.CharType.createCharType) DecimalType(com.facebook.presto.spi.type.DecimalType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) DecimalType.createDecimalType(com.facebook.presto.spi.type.DecimalType.createDecimalType) Type(com.facebook.presto.spi.type.Type) ParametricType(com.facebook.presto.spi.type.ParametricType) CharType(com.facebook.presto.spi.type.CharType) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType) TypeSignatureParameter(com.facebook.presto.spi.type.TypeSignatureParameter) ArrayList(java.util.ArrayList) ParametricType(com.facebook.presto.spi.type.ParametricType)

Example 3 with TypeParameter

use of com.facebook.presto.spi.type.TypeParameter in project presto by prestodb.

the class VarcharParametricType method createType.

@Override
public Type createType(List<TypeParameter> parameters) {
    if (parameters.isEmpty()) {
        return createUnboundedVarcharType();
    }
    if (parameters.size() != 1) {
        throw new IllegalArgumentException("Expected exactly one parameter for VARCHAR");
    }
    TypeParameter parameter = parameters.get(0);
    if (!parameter.isLongLiteral()) {
        throw new IllegalArgumentException("VARCHAR length must be a number");
    }
    long length = parameter.getLongLiteral();
    if (length == VarcharType.UNBOUNDED_LENGTH) {
        return VarcharType.createUnboundedVarcharType();
    }
    if (length < 0 || length > VarcharType.MAX_LENGTH) {
        throw new IllegalArgumentException("Invalid VARCHAR length " + length);
    }
    return VarcharType.createVarcharType((int) length);
}
Also used : TypeParameter(com.facebook.presto.spi.type.TypeParameter)

Aggregations

TypeParameter (com.facebook.presto.spi.type.TypeParameter)3 CharType (com.facebook.presto.spi.type.CharType)1 CharType.createCharType (com.facebook.presto.spi.type.CharType.createCharType)1 DecimalType (com.facebook.presto.spi.type.DecimalType)1 DecimalType.createDecimalType (com.facebook.presto.spi.type.DecimalType.createDecimalType)1 ParametricType (com.facebook.presto.spi.type.ParametricType)1 Type (com.facebook.presto.spi.type.Type)1 TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)1 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)1 ArrayList (java.util.ArrayList)1