Skip to content

Commit

Permalink
Add static imports for type constants
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Aug 31, 2022
1 parent 8c81e72 commit 8ff56b1
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.trino.spi.TrinoException;
import io.trino.spi.type.NamedTypeSignature;
import io.trino.spi.type.RowFieldName;
import io.trino.spi.type.StandardTypes;
import io.trino.spi.type.Type;
import io.trino.spi.type.TypeSignature;
import io.trino.spi.type.TypeSignatureParameter;
Expand Down Expand Up @@ -48,6 +47,12 @@
import static io.trino.spi.StandardErrorCode.TYPE_MISMATCH;
import static io.trino.spi.type.StandardTypes.INTERVAL_DAY_TO_SECOND;
import static io.trino.spi.type.StandardTypes.INTERVAL_YEAR_TO_MONTH;
import static io.trino.spi.type.StandardTypes.ROW;
import static io.trino.spi.type.StandardTypes.TIME;
import static io.trino.spi.type.StandardTypes.TIMESTAMP;
import static io.trino.spi.type.StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
import static io.trino.spi.type.StandardTypes.TIME_WITH_TIME_ZONE;
import static io.trino.spi.type.StandardTypes.VARCHAR;
import static io.trino.spi.type.TypeSignatureParameter.namedTypeParameter;
import static io.trino.spi.type.TypeSignatureParameter.numericParameter;
import static io.trino.spi.type.TypeSignatureParameter.typeParameter;
Expand Down Expand Up @@ -103,7 +108,7 @@ private static TypeSignature toTypeSignature(GenericDataType type, Set<String> t
{
ImmutableList.Builder<TypeSignatureParameter> parameters = ImmutableList.builder();

if (type.getName().getValue().equalsIgnoreCase(StandardTypes.VARCHAR) && type.getArguments().isEmpty()) {
if (type.getName().getValue().equalsIgnoreCase(VARCHAR) && type.getArguments().isEmpty()) {
// We treat VARCHAR specially because currently, the unbounded VARCHAR type is modeled in the system as a VARCHAR(n) with a "magic" length
// TODO: Eventually, we should split the types into VARCHAR and VARCHAR(n)
return VarcharType.VARCHAR.getTypeSignature();
Expand Down Expand Up @@ -148,7 +153,7 @@ private static TypeSignature toTypeSignature(RowDataType type, Set<String> typeV
toTypeSignature(field.getType(), typeVariables))))
.collect(toImmutableList());

return new TypeSignature(StandardTypes.ROW, parameters);
return new TypeSignature(ROW, parameters);
}

private static TypeSignature toTypeSignature(IntervalDayTimeDataType type)
Expand All @@ -172,18 +177,18 @@ private static TypeSignature toTypeSignature(DateTimeDataType type, Set<String>
switch (type.getType()) {
case TIMESTAMP:
if (withTimeZone) {
base = StandardTypes.TIMESTAMP_WITH_TIME_ZONE;
base = TIMESTAMP_WITH_TIME_ZONE;
}
else {
base = StandardTypes.TIMESTAMP;
base = TIMESTAMP;
}
break;
case TIME:
if (withTimeZone) {
base = StandardTypes.TIME_WITH_TIME_ZONE;
base = TIME_WITH_TIME_ZONE;
}
else {
base = StandardTypes.TIME;
base = TIME;
}
break;
default:
Expand Down Expand Up @@ -230,39 +235,39 @@ static DataType toDataType(TypeSignature typeSignature)
return new IntervalDayTimeDataType(Optional.empty(), IntervalDayTimeDataType.Field.YEAR, IntervalDayTimeDataType.Field.MONTH);
case INTERVAL_DAY_TO_SECOND:
return new IntervalDayTimeDataType(Optional.empty(), IntervalDayTimeDataType.Field.DAY, IntervalDayTimeDataType.Field.SECOND);
case StandardTypes.TIMESTAMP_WITH_TIME_ZONE:
case TIMESTAMP_WITH_TIME_ZONE:
return new DateTimeDataType(
Optional.empty(),
DateTimeDataType.Type.TIMESTAMP,
true,
typeSignature.getParameters().stream()
.findAny()
.map(TypeSignatureTranslator::toTypeParameter));
case StandardTypes.TIMESTAMP:
case TIMESTAMP:
return new DateTimeDataType(
Optional.empty(),
DateTimeDataType.Type.TIMESTAMP,
false,
typeSignature.getParameters().stream()
.findAny()
.map(TypeSignatureTranslator::toTypeParameter));
case StandardTypes.TIME_WITH_TIME_ZONE:
case TIME_WITH_TIME_ZONE:
return new DateTimeDataType(
Optional.empty(),
DateTimeDataType.Type.TIME,
true,
typeSignature.getParameters().stream()
.findAny()
.map(TypeSignatureTranslator::toTypeParameter));
case StandardTypes.TIME:
case TIME:
return new DateTimeDataType(
Optional.empty(),
DateTimeDataType.Type.TIME,
false,
typeSignature.getParameters().stream()
.findAny()
.map(TypeSignatureTranslator::toTypeParameter));
case StandardTypes.ROW:
case ROW:
return new RowDataType(
Optional.empty(),
typeSignature.getParameters().stream()
Expand All @@ -271,7 +276,7 @@ static DataType toDataType(TypeSignature typeSignature)
parameter.getNamedTypeSignature().getFieldName().map(fieldName -> new Identifier(fieldName.getName(), requiresDelimiting(fieldName.getName()))),
toDataType(parameter.getNamedTypeSignature().getTypeSignature())))
.collect(toImmutableList()));
case StandardTypes.VARCHAR:
case VARCHAR:
return new GenericDataType(
Optional.empty(),
new Identifier(typeSignature.getBase(), false),
Expand Down

0 comments on commit 8ff56b1

Please sign in to comment.