use of io.trino.sql.tree.GenericDataType in project trino by trinodb.
the class TypeSignatureTranslator method toTypeSignature.
private static TypeSignature toTypeSignature(GenericDataType type, Set<String> typeVariables) {
ImmutableList.Builder<TypeSignatureParameter> parameters = ImmutableList.builder();
if (type.getName().getValue().equalsIgnoreCase(StandardTypes.VARCHAR) && type.getArguments().isEmpty()) {
// TODO: Eventually, we should split the types into VARCHAR and VARCHAR(n)
return VarcharType.VARCHAR.getTypeSignature();
}
checkArgument(!typeVariables.contains(type.getName().getValue()), "Base type name cannot be a type variable");
for (DataTypeParameter parameter : type.getArguments()) {
if (parameter instanceof NumericParameter) {
String value = ((NumericParameter) parameter).getValue();
try {
parameters.add(numericParameter(Long.parseLong(value)));
} catch (NumberFormatException e) {
throw semanticException(TYPE_MISMATCH, parameter, "Invalid type parameter: %s", value);
}
} else if (parameter instanceof TypeParameter) {
DataType value = ((TypeParameter) parameter).getValue();
if (value instanceof GenericDataType && ((GenericDataType) value).getArguments().isEmpty() && typeVariables.contains(((GenericDataType) value).getName().getValue())) {
parameters.add(typeVariable(((GenericDataType) value).getName().getValue()));
} else {
parameters.add(typeParameter(toTypeSignature(value, typeVariables)));
}
} else {
throw new UnsupportedOperationException("Unsupported type parameter kind: " + parameter.getClass().getName());
}
}
return new TypeSignature(canonicalize(type.getName()), parameters.build());
}
Aggregations