Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Change StandardTypes to be a enum class #16246 #16257

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ArrayType

public ArrayType(Type elementType)
{
super(new TypeSignature(ARRAY, TypeSignatureParameter.of(elementType.getTypeSignature())), Block.class);
super(new TypeSignature(ARRAY.getEnumValue(), TypeSignatureParameter.of(elementType.getTypeSignature())), Block.class);
this.elementType = requireNonNull(elementType, "elementType is null");
}

Expand Down Expand Up @@ -216,6 +216,6 @@ public List<Type> getTypeParameters()
@Override
public String getDisplayName()
{
return ARRAY + "(" + elementType.getDisplayName() + ")";
return ARRAY.getEnumValue() + "(" + elementType.getDisplayName() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private BigintEnumParametricType() {}
@Override
public String getName()
{
return StandardTypes.BIGINT_ENUM;
return StandardTypes.BIGINT_ENUM.getEnumValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class BigintEnumType

public BigintEnumType(LongEnumMap enumMap)
{
super(new TypeSignature(StandardTypes.BIGINT_ENUM, TypeSignatureParameter.of(enumMap)));
super(new TypeSignature(StandardTypes.BIGINT_ENUM.getEnumValue(), TypeSignatureParameter.of(enumMap)));
this.enumMap = enumMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class BigintType

private BigintType()
{
super(parseTypeSignature(StandardTypes.BIGINT));
super(parseTypeSignature(StandardTypes.BIGINT.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class BooleanType

private BooleanType()
{
super(parseTypeSignature(StandardTypes.BOOLEAN), boolean.class);
super(parseTypeSignature(StandardTypes.BOOLEAN.getEnumValue()), boolean.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private CharType(long length)
{
super(
new TypeSignature(
StandardTypes.CHAR,
StandardTypes.CHAR.getEnumValue(),
singletonList(TypeSignatureParameter.of(length))),
Slice.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class DateType

private DateType()
{
super(parseTypeSignature(StandardTypes.DATE));
super(parseTypeSignature(StandardTypes.DATE.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static DecimalType createDecimalType()

DecimalType(int precision, int scale, Class<?> javaType)
{
super(new TypeSignature(StandardTypes.DECIMAL, buildTypeParameters(precision, scale)), javaType);
super(new TypeSignature(StandardTypes.DECIMAL.getEnumValue(), buildTypeParameters(precision, scale)), javaType);
this.precision = precision;
this.scale = scale;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class DoubleType

private DoubleType()
{
super(parseTypeSignature(StandardTypes.DOUBLE), double.class);
super(parseTypeSignature(StandardTypes.DOUBLE.getEnumValue()), double.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class HyperLogLogType
@JsonCreator
public HyperLogLogType()
{
super(parseTypeSignature(StandardTypes.HYPER_LOG_LOG), Slice.class);
super(parseTypeSignature(StandardTypes.HYPER_LOG_LOG.getEnumValue()), Slice.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class IntegerType

private IntegerType()
{
super(parseTypeSignature(StandardTypes.INTEGER));
super(parseTypeSignature(StandardTypes.INTEGER.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class JsonType

public JsonType()
{
super(new TypeSignature(StandardTypes.JSON), Slice.class);
super(new TypeSignature(StandardTypes.JSON.getEnumValue()), Slice.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public MapType(
MethodHandle keyBlockEquals,
MethodHandle keyBlockHashCode)
{
super(new TypeSignature(StandardTypes.MAP,
super(new TypeSignature(StandardTypes.MAP.getEnumValue(),
TypeSignatureParameter.of(keyType.getTypeSignature()),
TypeSignatureParameter.of(valueType.getTypeSignature())),
Block.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class P4HyperLogLogType
@JsonCreator
public P4HyperLogLogType()
{
super(parseTypeSignature(StandardTypes.P4_HYPER_LOG_LOG), Slice.class);
super(parseTypeSignature(StandardTypes.P4_HYPER_LOG_LOG.getEnumValue()), Slice.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class QuantileDigestParametricType
@Override
public String getName()
{
return StandardTypes.QDIGEST;
return StandardTypes.QDIGEST.getEnumValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class QuantileDigestType
{
QuantileDigestType(Type type)
{
super(QDIGEST, type);
super(QDIGEST.getEnumValue(), type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class RealType

private RealType()
{
super(parseTypeSignature(StandardTypes.REAL));
super(parseTypeSignature(StandardTypes.REAL.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static TypeSignature makeSignature(List<Field> fields)
.map(field -> TypeSignatureParameter.of(new NamedTypeSignature(field.getName().map(name -> new RowFieldName(name, false)), field.getType().getTypeSignature())))
.collect(Collectors.toList());

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

@Override
Expand All @@ -118,7 +118,7 @@ public String getDisplayName()
{
// Convert to standard sql name
StringBuilder result = new StringBuilder();
result.append(ROW).append('(');
result.append(ROW.getEnumValue()).append('(');
for (Field field : fields) {
String typeDisplayName = field.getType().getDisplayName();
if (field.getName().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class SmallintType

private SmallintType()
{
super(parseTypeSignature(StandardTypes.SMALLINT), long.class);
super(parseTypeSignature(StandardTypes.SMALLINT.getEnumValue()), long.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,52 @@
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableSet;

public final class StandardTypes
public enum StandardTypes
{
public static final String BIGINT = "bigint";
public static final String INTEGER = "integer";
public static final String SMALLINT = "smallint";
public static final String TINYINT = "tinyint";
public static final String BOOLEAN = "boolean";
public static final String DATE = "date";
public static final String DECIMAL = "decimal";
public static final String REAL = "real";
public static final String DOUBLE = "double";
public static final String HYPER_LOG_LOG = "HyperLogLog";
public static final String QDIGEST = "qdigest";
public static final String TDIGEST = "tdigest";
public static final String P4_HYPER_LOG_LOG = "P4HyperLogLog";
public static final String INTERVAL_DAY_TO_SECOND = "interval day to second";
public static final String INTERVAL_YEAR_TO_MONTH = "interval year to month";
public static final String TIMESTAMP = "timestamp";
public static final String TIMESTAMP_WITH_TIME_ZONE = "timestamp with time zone";
public static final String TIME = "time";
public static final String TIME_WITH_TIME_ZONE = "time with time zone";
public static final String VARBINARY = "varbinary";
public static final String VARCHAR = "varchar";
public static final String CHAR = "char";
public static final String ROW = "row";
public static final String ARRAY = "array";
public static final String MAP = "map";
public static final String JSON = "json";
public static final String IPADDRESS = "ipaddress";
public static final String IPPREFIX = "ipprefix";
public static final String GEOMETRY = "Geometry";
public static final String BING_TILE = "BingTile";
public static final String BIGINT_ENUM = "BigintEnum";
public static final String VARCHAR_ENUM = "VarcharEnum";
BIGINT("bigint"),
INTEGER("integer"),
SMALLINT("smallint"),
TINYINT("tinyint"),
BOOLEAN("boolean"),
DATE("date"),
DECIMAL("decimal"),
REAL("real"),
DOUBLE("double"),
HYPER_LOG_LOG("HyperLogLog"),
QDIGEST("qdigest"),
TDIGEST("tdigest"),
P4_HYPER_LOG_LOG("P4HyperLogLog"),
INTERVAL_DAY_TO_SECOND("interval day to second"),
INTERVAL_YEAR_TO_MONTH("interval year to month"),
TIMESTAMP("timestamp"),
TIMESTAMP_WITH_TIME_ZONE("timestamp with time zone"),
TIME("time"),
TIME_WITH_TIME_ZONE("time with time zone"),
VARBINARY("varbinary"),
VARCHAR("varchar"),
CHAR("char"),
ROW("row"),
ARRAY("array"),
MAP("map"),
JSON("json"),
IPADDRESS("ipaddress"),
IPPREFIX("ipprefix"),
GEOMETRY("Geometry"),
BING_TILE("BingTile"),
BIGINT_ENUM("BigintEnum"),
VARCHAR_ENUM("VarcharEnum");

private StandardTypes() {}
private final String enumValue;

public static final Set<String> PARAMETRIC_TYPES = unmodifiableSet(new HashSet<>(asList(
StandardTypes(String enumValue) {
this.enumValue = enumValue;
}

public String getEnumValue(){
return enumValue;
}

public static final Set<StandardTypes> PARAMETRIC_TYPES = unmodifiableSet(new HashSet<>(asList(
VARCHAR,
CHAR,
DECIMAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TDigestParametricType
@Override
public String getName()
{
return StandardTypes.TDIGEST;
return StandardTypes.TDIGEST.getEnumValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class TDigestType
{
TDigestType(Type type)
{
super(TDIGEST, type);
super(TDIGEST.getEnumValue(), type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class TimeType

private TimeType()
{
super(parseTypeSignature(StandardTypes.TIME));
super(parseTypeSignature(StandardTypes.TIME.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class TimeWithTimeZoneType

private TimeWithTimeZoneType()
{
super(parseTypeSignature(StandardTypes.TIME_WITH_TIME_ZONE));
super(parseTypeSignature(StandardTypes.TIME_WITH_TIME_ZONE.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class TimestampType

private TimestampType()
{
super(parseTypeSignature(StandardTypes.TIMESTAMP));
super(parseTypeSignature(StandardTypes.TIMESTAMP.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class TimestampWithTimeZoneType

private TimestampWithTimeZoneType()
{
super(parseTypeSignature(StandardTypes.TIMESTAMP_WITH_TIME_ZONE));
super(parseTypeSignature(StandardTypes.TIMESTAMP_WITH_TIME_ZONE.getEnumValue()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class TinyintType

private TinyintType()
{
super(parseTypeSignature(StandardTypes.TINYINT), long.class);
super(parseTypeSignature(StandardTypes.TINYINT.getEnumValue()), long.class);
}

@Override
Expand Down