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());
}
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;
}
}
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);
}
Aggregations