Package org.apache.druid.segment.column
Class TypeStrategies
- java.lang.Object
-
- org.apache.druid.segment.column.TypeStrategies
-
public class TypeStrategies extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeStrategies.ArrayTypeStrategyRead and write a non-null ARRAY which is permitted to have null elements (all elements are always read and written with aNullableTypeStrategywrapper on theTypeStrategyof theTypeSignature.getElementType().static classTypeStrategies.DoubleTypeStrategyRead and write non-null DOUBLE values.static classTypeStrategies.FloatTypeStrategyRead and write non-null FLOAT values.static classTypeStrategies.LongTypeStrategyRead and write non-null LONG values.static classTypeStrategies.StringTypeStrategyRead and write non-null UTF8 encoded String values.
-
Field Summary
Fields Modifier and Type Field Description static ConcurrentHashMap<String,TypeStrategy<?>>COMPLEX_STRATEGIESstatic TypeStrategies.DoubleTypeStrategyDOUBLEstatic TypeStrategies.FloatTypeStrategyFLOATstatic TypeStrategies.LongTypeStrategyLONGstatic intNULLABLE_DOUBLE_SIZEstatic intNULLABLE_FLOAT_SIZEstatic intNULLABLE_LONG_SIZEstatic TypeStrategies.StringTypeStrategySTRINGstatic intVALUE_OFFSET
-
Constructor Summary
Constructors Constructor Description TypeStrategies()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckMaxSize(int available, int maxSizeBytes, TypeSignature<?> signature)static TypeStrategy<?>getComplex(String typeName)Get anTypeStrategyregistered to someTypeSignature.getComplexTypeName().static booleanisNullableNull(ByteBuffer buffer, int offset)Checks if a 'nullable' value's null byte is set toNullHandling.IS_NULL_BYTE.static doublereadNotNullNullableDouble(ByteBuffer buffer, int offset)Reads a non-null double value from aByteBufferat the supplied offset.static floatreadNotNullNullableFloat(ByteBuffer buffer, int offset)Reads a non-null float value from aByteBufferat the supplied offset.static longreadNotNullNullableLong(ByteBuffer buffer, int offset)Reads a non-null long value from aByteBufferat the supplied offset.static voidregisterComplex(String typeName, TypeStrategy<?> strategy)hmm...static intwriteNotNullNullableDouble(ByteBuffer buffer, int offset, double value)Write a non-null double value to aByteBufferat the supplied offset.static intwriteNotNullNullableFloat(ByteBuffer buffer, int offset, float value)Write a non-null float value to aByteBufferat the supplied offset.static intwriteNotNullNullableLong(ByteBuffer buffer, int offset, long value)Write a non-null long value to aByteBufferat the supplied offset.static intwriteNull(ByteBuffer buffer, int offset)Clear and set the 'null' byte of a nullable value toNullHandling.IS_NULL_BYTEto aByteBufferat the supplied position.
-
-
-
Field Detail
-
VALUE_OFFSET
public static final int VALUE_OFFSET
- See Also:
- Constant Field Values
-
NULLABLE_LONG_SIZE
public static final int NULLABLE_LONG_SIZE
- See Also:
- Constant Field Values
-
NULLABLE_DOUBLE_SIZE
public static final int NULLABLE_DOUBLE_SIZE
- See Also:
- Constant Field Values
-
NULLABLE_FLOAT_SIZE
public static final int NULLABLE_FLOAT_SIZE
- See Also:
- Constant Field Values
-
LONG
public static final TypeStrategies.LongTypeStrategy LONG
-
FLOAT
public static final TypeStrategies.FloatTypeStrategy FLOAT
-
DOUBLE
public static final TypeStrategies.DoubleTypeStrategy DOUBLE
-
STRING
public static final TypeStrategies.StringTypeStrategy STRING
-
COMPLEX_STRATEGIES
public static final ConcurrentHashMap<String,TypeStrategy<?>> COMPLEX_STRATEGIES
-
-
Method Detail
-
getComplex
@Nullable public static TypeStrategy<?> getComplex(String typeName)
Get anTypeStrategyregistered to someTypeSignature.getComplexTypeName().
-
registerComplex
public static void registerComplex(String typeName, TypeStrategy<?> strategy)
hmm... this might look familiar... (see ComplexMetrics) Register a complex type name ->TypeStrategymapping. If the specified type name is already used and the suppliedTypeStrategyis not of the same type as the existing value in the map for said key, anISEis thrown.- Parameters:
strategy- TheTypeStrategyobject to be associated with the 'type' in the map.
-
writeNull
public static int writeNull(ByteBuffer buffer, int offset)
Clear and set the 'null' byte of a nullable value toNullHandling.IS_NULL_BYTEto aByteBufferat the supplied position. This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs) Nullable types are stored with a leading byte to indicate if the value is null, followed by the value bytes (if not null) layout: | null (byte) | value |- Returns:
- number of bytes written (always 1)
-
isNullableNull
public static boolean isNullableNull(ByteBuffer buffer, int offset)
Checks if a 'nullable' value's null byte is set toNullHandling.IS_NULL_BYTE. This method will mask the value of the null byte to only check if the null bit is set, meaning that the higher bits can be utilized for flags as necessary (e.g. using high bits to indicate if the value has been set or not for aggregators). Note that writing nullable values with the methods ofTypeswill always clear and set the null byte to eitherNullHandling.IS_NULL_BYTEorNullHandling.IS_NOT_NULL_BYTE, losing any flag bits. layout: | null (byte) | value |
-
writeNotNullNullableLong
public static int writeNotNullNullableLong(ByteBuffer buffer, int offset, long value)
Write a non-null long value to aByteBufferat the supplied offset. The first byte is always cleared and set toNullHandling.IS_NOT_NULL_BYTE, the long value is written in the next 8 bytes. layout: | null (byte) | long | This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs)- Returns:
- number of bytes written (always 9)
-
readNotNullNullableLong
public static long readNotNullNullableLong(ByteBuffer buffer, int offset)
Reads a non-null long value from aByteBufferat the supplied offset. This method should only be called if and only ifisNullableNull(java.nio.ByteBuffer, int)for the same offset returns false. layout: | null (byte) | long | This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs)
-
writeNotNullNullableDouble
public static int writeNotNullNullableDouble(ByteBuffer buffer, int offset, double value)
Write a non-null double value to aByteBufferat the supplied offset. The first byte is always cleared and set toNullHandling.IS_NOT_NULL_BYTE, the double value is written in the next 8 bytes. layout: | null (byte) | double | This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs)- Returns:
- number of bytes written (always 9)
-
readNotNullNullableDouble
public static double readNotNullNullableDouble(ByteBuffer buffer, int offset)
Reads a non-null double value from aByteBufferat the supplied offset. This method should only be called if and only ifisNullableNull(java.nio.ByteBuffer, int)for the same offset returns false. layout: | null (byte) | double | This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs)
-
writeNotNullNullableFloat
public static int writeNotNullNullableFloat(ByteBuffer buffer, int offset, float value)
Write a non-null float value to aByteBufferat the supplied offset. The first byte is always cleared and set toNullHandling.IS_NOT_NULL_BYTE, the float value is written in the next 4 bytes. layout: | null (byte) | float | This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs)- Returns:
- number of bytes written (always 5)
-
readNotNullNullableFloat
public static float readNotNullNullableFloat(ByteBuffer buffer, int offset)
Reads a non-null float value from aByteBufferat the supplied offset. This method should only be called if and only ifisNullableNull(java.nio.ByteBuffer, int)for the same offset returns false. layout: | null (byte) | float | This method does not change the buffer position, limit, or mark, because it does not expect to own the buffer given to it (i.e. buffer aggs)
-
checkMaxSize
public static void checkMaxSize(int available, int maxSizeBytes, TypeSignature<?> signature)
-
-