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 class
TypeStrategies.ArrayTypeStrategy
Read and write a non-null ARRAY which is permitted to have null elements (all elements are always read and written with aNullableTypeStrategy
wrapper on theTypeStrategy
of theTypeSignature.getElementType()
.static class
TypeStrategies.DoubleTypeStrategy
Read and write non-null DOUBLE values.static class
TypeStrategies.FloatTypeStrategy
Read and write non-null FLOAT values.static class
TypeStrategies.LongTypeStrategy
Read and write non-null LONG values.static class
TypeStrategies.StringTypeStrategy
Read and write non-null UTF8 encoded String values.
-
Field Summary
Fields Modifier and Type Field Description static ConcurrentHashMap<String,TypeStrategy<?>>
COMPLEX_STRATEGIES
static TypeStrategies.DoubleTypeStrategy
DOUBLE
static TypeStrategies.FloatTypeStrategy
FLOAT
static TypeStrategies.LongTypeStrategy
LONG
static int
NULLABLE_DOUBLE_SIZE
static int
NULLABLE_FLOAT_SIZE
static int
NULLABLE_LONG_SIZE
static TypeStrategies.StringTypeStrategy
STRING
static int
VALUE_OFFSET
-
Constructor Summary
Constructors Constructor Description TypeStrategies()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkMaxSize(int available, int maxSizeBytes, TypeSignature<?> signature)
static TypeStrategy<?>
getComplex(String typeName)
Get anTypeStrategy
registered to someTypeSignature.getComplexTypeName()
.static boolean
isNullableNull(ByteBuffer buffer, int offset)
Checks if a 'nullable' value's null byte is set toNullHandling.IS_NULL_BYTE
.static double
readNotNullNullableDouble(ByteBuffer buffer, int offset)
Reads a non-null double value from aByteBuffer
at the supplied offset.static float
readNotNullNullableFloat(ByteBuffer buffer, int offset)
Reads a non-null float value from aByteBuffer
at the supplied offset.static long
readNotNullNullableLong(ByteBuffer buffer, int offset)
Reads a non-null long value from aByteBuffer
at the supplied offset.static void
registerComplex(String typeName, TypeStrategy<?> strategy)
hmm...static int
writeNotNullNullableDouble(ByteBuffer buffer, int offset, double value)
Write a non-null double value to aByteBuffer
at the supplied offset.static int
writeNotNullNullableFloat(ByteBuffer buffer, int offset, float value)
Write a non-null float value to aByteBuffer
at the supplied offset.static int
writeNotNullNullableLong(ByteBuffer buffer, int offset, long value)
Write a non-null long value to aByteBuffer
at the supplied offset.static int
writeNull(ByteBuffer buffer, int offset)
Clear and set the 'null' byte of a nullable value toNullHandling.IS_NULL_BYTE
to aByteBuffer
at 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 anTypeStrategy
registered to someTypeSignature.getComplexTypeName()
.
-
registerComplex
public static void registerComplex(String typeName, TypeStrategy<?> strategy)
hmm... this might look familiar... (see ComplexMetrics) Register a complex type name ->TypeStrategy
mapping. If the specified type name is already used and the suppliedTypeStrategy
is not of the same type as the existing value in the map for said key, anISE
is thrown.- Parameters:
strategy
- TheTypeStrategy
object 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_BYTE
to aByteBuffer
at 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 ofTypes
will always clear and set the null byte to eitherNullHandling.IS_NULL_BYTE
orNullHandling.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 aByteBuffer
at 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 aByteBuffer
at 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 aByteBuffer
at 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 aByteBuffer
at 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 aByteBuffer
at 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 aByteBuffer
at 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)
-
-