Package org.apache.pinot.common.utils
Enum PinotDataType
- java.lang.Object
-
- java.lang.Enum<PinotDataType>
-
- org.apache.pinot.common.utils.PinotDataType
-
- All Implemented Interfaces:
Serializable,Comparable<PinotDataType>,java.lang.constant.Constable
public enum PinotDataType extends Enum<PinotDataType>
ThePinotDataTypeenum represents the data type of a value in a row from recordReader and provides utility methods to convert value across types if applicable.We don't use
PinotDataTypeto maintain type information, but use it to help organize the data and useFieldSpec.DataTypeto maintain type information separately across various readers.NOTE:
- We will silently lose information if a conversion causes us to do so (e.g. DOUBLE to INT)
- We will throw exception if a conversion is not possible (e.g. BOOLEAN to INT).
- We will throw exception if the conversion throws exception (e.g. "foo" -> INT)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
-
Enum Constant Summary
Enum Constants Enum Constant Description BIG_DECIMALBOOLEANWhen converting from BOOLEAN to other types: - Numeric types: - true -> 1 - false -> 0 - String: - true -> "true" - false -> "false" When converting to BOOLEAN from other types: - Numeric types: - 0 -> false - Others -> true - String: - "true" (case-insensitive) -> true - "1" -> true (for backward-compatibility where we used to use integer 1 to represent true) - Others -> falseBOOLEAN_ARRAYBYTEBYTE_ARRAYBYTESBYTES_ARRAYCHARACTERCHARACTER_ARRAYCOLLECTIONDOUBLEDOUBLE_ARRAYFLOATFLOAT_ARRAYINTEGERINTEGER_ARRAYJSONLONGLONG_ARRAYOBJECTOBJECT_ARRAYPRIMITIVE_DOUBLE_ARRAYPRIMITIVE_FLOAT_ARRAYPRIMITIVE_INT_ARRAYPRIMITIVE_LONG_ARRAYSHORTSHORT_ARRAYSTRINGSTRING_ARRAYTIMESTAMPWhen converting from TIMESTAMP to other types: - LONG/DOUBLE: millis since epoch value - String: SQL timestamp format (e.g.TIMESTAMP_ARRAY
-
Method Summary
Modifier and Type Method Description Objectconvert(Object value, PinotDataType sourceType)static PinotDataTypegetMultiValueType(Class<?> cls)static PinotDataTypegetPinotDataTypeForExecution(DataSchema.ColumnDataType columnDataType)Returns thePinotDataTypefor the givenDataSchema.ColumnDataTypefor query execution purpose.static PinotDataTypegetPinotDataTypeForIngestion(FieldSpec fieldSpec)Returns thePinotDataTypefor the givenFieldSpecfor data ingestion purpose.PinotDataTypegetSingleValueType()static PinotDataTypegetSingleValueType(Class<?> cls)booleanisSingleValue()BigDecimaltoBigDecimal(Object value)booleantoBoolean(Object value)boolean[]toBooleanArray(Object value)byte[]toBytes(Object value)byte[][]toBytesArray(Object value)doubletoDouble(Object value)Double[]toDoubleArray(Object value)floattoFloat(Object value)Float[]toFloatArray(Object value)inttoInt(Object value)NOTE: override toInt(), toLong(), toFloat(), toDouble(), toBoolean(), toTimestamp(), toString(), and toBytes() for single-value types.Integer[]toIntegerArray(Object value)ObjecttoInternal(Object value)Converts to the internal representation of the value.StringtoJson(Object value)longtoLong(Object value)Long[]toLongArray(Object value)double[]toPrimitiveDoubleArray(Object value)float[]toPrimitiveFloatArray(Object value)int[]toPrimitiveIntArray(Object value)long[]toPrimitiveLongArray(Object value)StringtoString(Object value)String[]toStringArray(Object value)TimestamptoTimestamp(Object value)Timestamp[]toTimestampArray(Object value)static PinotDataTypevalueOf(String name)Returns the enum constant of this type with the specified name.static PinotDataType[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
BOOLEAN
public static final PinotDataType BOOLEAN
When converting from BOOLEAN to other types: - Numeric types: - true -> 1 - false -> 0 - String: - true -> "true" - false -> "false" When converting to BOOLEAN from other types: - Numeric types: - 0 -> false - Others -> true - String: - "true" (case-insensitive) -> true - "1" -> true (for backward-compatibility where we used to use integer 1 to represent true) - Others -> false
-
BYTE
public static final PinotDataType BYTE
-
CHARACTER
public static final PinotDataType CHARACTER
-
SHORT
public static final PinotDataType SHORT
-
INTEGER
public static final PinotDataType INTEGER
-
LONG
public static final PinotDataType LONG
-
FLOAT
public static final PinotDataType FLOAT
-
DOUBLE
public static final PinotDataType DOUBLE
-
BIG_DECIMAL
public static final PinotDataType BIG_DECIMAL
-
TIMESTAMP
public static final PinotDataType TIMESTAMP
When converting from TIMESTAMP to other types: - LONG/DOUBLE: millis since epoch value - String: SQL timestamp format (e.g. "2021-01-01 01:01:01.001") When converting to TIMESTAMP from other types: - LONG/DOUBLE: read long value as millis since epoch - String: - SQL timestamp format (e.g. "2021-01-01 01:01:01.001") - Millis since epoch value (e.g. "1609491661001")
-
STRING
public static final PinotDataType STRING
-
JSON
public static final PinotDataType JSON
-
BYTES
public static final PinotDataType BYTES
-
OBJECT
public static final PinotDataType OBJECT
-
BYTE_ARRAY
public static final PinotDataType BYTE_ARRAY
-
CHARACTER_ARRAY
public static final PinotDataType CHARACTER_ARRAY
-
SHORT_ARRAY
public static final PinotDataType SHORT_ARRAY
-
PRIMITIVE_INT_ARRAY
public static final PinotDataType PRIMITIVE_INT_ARRAY
-
INTEGER_ARRAY
public static final PinotDataType INTEGER_ARRAY
-
PRIMITIVE_LONG_ARRAY
public static final PinotDataType PRIMITIVE_LONG_ARRAY
-
LONG_ARRAY
public static final PinotDataType LONG_ARRAY
-
PRIMITIVE_FLOAT_ARRAY
public static final PinotDataType PRIMITIVE_FLOAT_ARRAY
-
FLOAT_ARRAY
public static final PinotDataType FLOAT_ARRAY
-
PRIMITIVE_DOUBLE_ARRAY
public static final PinotDataType PRIMITIVE_DOUBLE_ARRAY
-
DOUBLE_ARRAY
public static final PinotDataType DOUBLE_ARRAY
-
BOOLEAN_ARRAY
public static final PinotDataType BOOLEAN_ARRAY
-
TIMESTAMP_ARRAY
public static final PinotDataType TIMESTAMP_ARRAY
-
STRING_ARRAY
public static final PinotDataType STRING_ARRAY
-
BYTES_ARRAY
public static final PinotDataType BYTES_ARRAY
-
COLLECTION
public static final PinotDataType COLLECTION
-
OBJECT_ARRAY
public static final PinotDataType OBJECT_ARRAY
-
-
Method Detail
-
values
public static PinotDataType[] values()
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static PinotDataType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
toInt
public int toInt(Object value)
NOTE: override toInt(), toLong(), toFloat(), toDouble(), toBoolean(), toTimestamp(), toString(), and toBytes() for single-value types.
-
toLong
public long toLong(Object value)
-
toFloat
public float toFloat(Object value)
-
toDouble
public double toDouble(Object value)
-
toBigDecimal
public BigDecimal toBigDecimal(Object value)
-
toBoolean
public boolean toBoolean(Object value)
-
toBytes
public byte[] toBytes(Object value)
-
toPrimitiveIntArray
public int[] toPrimitiveIntArray(Object value)
-
toPrimitiveLongArray
public long[] toPrimitiveLongArray(Object value)
-
toPrimitiveFloatArray
public float[] toPrimitiveFloatArray(Object value)
-
toPrimitiveDoubleArray
public double[] toPrimitiveDoubleArray(Object value)
-
toBytesArray
public byte[][] toBytesArray(Object value)
-
toBooleanArray
public boolean[] toBooleanArray(Object value)
-
convert
public Object convert(Object value, PinotDataType sourceType)
-
toInternal
public Object toInternal(Object value)
Converts to the internal representation of the value.- BOOLEAN -> int
- TIMESTAMP -> long
-
isSingleValue
public boolean isSingleValue()
-
getSingleValueType
public PinotDataType getSingleValueType()
-
getSingleValueType
public static PinotDataType getSingleValueType(Class<?> cls)
-
getMultiValueType
public static PinotDataType getMultiValueType(Class<?> cls)
-
getPinotDataTypeForIngestion
public static PinotDataType getPinotDataTypeForIngestion(FieldSpec fieldSpec)
Returns thePinotDataTypefor the givenFieldSpecfor data ingestion purpose. Returns object array type for multi-valued types.
-
getPinotDataTypeForExecution
public static PinotDataType getPinotDataTypeForExecution(DataSchema.ColumnDataType columnDataType)
Returns thePinotDataTypefor the givenDataSchema.ColumnDataTypefor query execution purpose. Returns primitive array type for multi-valued types.
-
-