cleanup DataType enum
@@ -375,18 +375,44 @@ public abstract class FieldSpec implements Comparable<FieldSpec>, Serializable {
public enum DataType {
// LIST is for complex lists which is different from multi-value column of primitives
// STRUCT, MAP and LIST are composable to form a COMPLEX field
- INT,
- LONG,
- FLOAT,
- DOUBLE,
- BOOLEAN /* Stored as INT */,
- TIMESTAMP /* Stored as LONG */,
- STRING,
- JSON /* Stored as STRING */,
- BYTES,
- STRUCT,
- MAP,
- LIST;
+ INT(Integer.BYTES, true, true),
+ LONG(Long.BYTES, true, true),
+ FLOAT(Float.BYTES, true, true),
+ DOUBLE(Double.BYTES, true, true),
+ BOOLEAN(INT, false, true),
+ TIMESTAMP(LONG, false, true),
+ STRING(false, true),
+ JSON(STRING, false, false),
+ BYTES(false, false),
+ STRUCT(false, false),
+ MAP(false, false),
+ LIST(false, false);
+
+ private final DataType _storedType;
+ private final int _size;
+ private final boolean _sortable;
+ private final boolean _numeric;
+
+ DataType(boolean numeric, boolean sortable) {
+ _storedType = this;
+ _size = -1;
+ _sortable = sortable;
+ _numeric = numeric;
+ }
+
+ DataType(DataType storedType, boolean numeric, boolean sortable) {
+ _storedType = storedType;
+ _size = storedType._size;
+ _sortable = sortable;
+ _numeric = numeric;
+ }
+
+ DataType(int size, boolean numeric, boolean sortable) {
+ _storedType = this;
+ _size = size;
+ _sortable = sortable;
+ _numeric = numeric;
+ }
/**
* Returns the data type stored in Pinot.
@@ -395,16 +421,7 @@ public abstract class FieldSpec implements Comparable<FieldSpec>, Serializable {
* <p>Stored type should be used when reading the physical stored values from Dictionary, Forward Index etc.
*/
public DataType getStoredType() {
- switch (this) {
- case BOOLEAN:
- return INT;
- case TIMESTAMP:
- return LONG;
- case JSON:
- return STRING;
- default:
- return this;
- }
+ return _storedType;
}
/**
@@ -412,34 +429,24 @@ public abstract class FieldSpec implements Comparable<FieldSpec>, Serializable {
* {@code false} otherwise.
*/
public boolean isFixedWidth() {
- return this.ordinal() < STRING.ordinal();
+ return _size >= 0;
}
/**
* Returns the number of bytes needed to store the data type.
*/
public int size() {
- switch (this) {
- case INT:
- case BOOLEAN:
- return Integer.BYTES;
- case LONG:
- case TIMESTAMP:
- return Long.BYTES;
- case FLOAT:
- return Float.BYTES;
- case DOUBLE:
- return Double.BYTES;
- default:
- throw new IllegalStateException("Cannot get number of bytes for: " + this);
+ if (_size >= 0) {
+ return _size;
}
+ throw new IllegalStateException("Cannot get number of bytes for: " + this);
}
/**
* Returns {@code true} if the data type is numeric (INT, LONG, FLOAT, DOUBLE), {@code false} otherwise.
*/
public boolean isNumeric() {
- return this == INT || this == LONG || this == FLOAT || this == DOUBLE;
+ return _numeric;
}
/**
@@ -508,7 +515,7 @@ public abstract class FieldSpec implements Comparable<FieldSpec>, Serializable {
* Checks whether the data type can be a sorted column.
*/
public boolean canBeASortedColumn() {
- return this != BYTES && this != JSON && this != STRUCT && this != MAP && this != LIST;
+ return _sortable;
}
}
