Package org.apache.druid.frame.field
Class NumericFieldWriter
- java.lang.Object
-
- org.apache.druid.frame.field.NumericFieldWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,FieldWriter
- Direct Known Subclasses:
DoubleFieldWriter
,FloatFieldWriter
,LongFieldWriter
public abstract class NumericFieldWriter extends Object implements FieldWriter
FieldWriter for numeric datatypes. The parent class does the null handling for the underlying data, while the individual subclasses write the individual element (long, float or double type). This also allows for a clean reuse of the readers and writers between the numeric types and also allowing the array writers (NumericArrayFieldWriter
) to use these methods directly without duplication Format: - 1 byte: Whether the following value is null or not. Take a look at the note on the indicator bytes. - X bytes: Encoded value of the selector, or the default value if it is null. X denotes the size of the numeric value Indicator bytes for denoting whether the element is null or not null changes depending on whether the writer is used to write the data for individual value (like LONG) or for an element of an array (like ARRAY). This is because array support for the numeric types was added later and by then the field writers for individual fields were using 0x00 to denote the null byte, which is reserved for denoting the array end when we are writing the elements as part of the array instead. (0x00 is used for array end because it helps in preserving the byte comparison property of the numeric array field writers). Therefore, to preserve backward and forward compatibility, the individual element's writers were left unchanged, while the array's element's writers used 0x01 and 0x02 to denote null and non-null byte respectively Values produced by the writer are sortable without decoding
-
-
Field Summary
Fields Modifier and Type Field Description static byte
ARRAY_ELEMENT_NOT_NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is not null.static byte
ARRAY_ELEMENT_NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is null.static byte
NOT_NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is not null.static byte
NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is null.
-
Constructor Summary
Constructors Constructor Description NumericFieldWriter(BaseNullableColumnValueSelector selector, boolean forArray)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Releases resources held by this writer.abstract int
getNumericSizeBytes()
abstract void
writeNullToMemory(org.apache.datasketches.memory.WritableMemory memory, long position)
Writes the default value for the type to the memory.abstract void
writeSelectorToMemory(org.apache.datasketches.memory.WritableMemory memory, long position)
Writes the value pointed by the selector to memory.long
writeTo(org.apache.datasketches.memory.WritableMemory memory, long position, long maxSize)
Writes the current selection at the given memory position.
-
-
-
Field Detail
-
NULL_BYTE
public static final byte NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is null. This is used in the primitive writers. NULL_BYTE < NOT_NULL_BYTE to preserve the ordering while doing byte comparison- See Also:
- Constant Field Values
-
NOT_NULL_BYTE
public static final byte NOT_NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is not null. This is used in the primitive writers- See Also:
- Constant Field Values
-
ARRAY_ELEMENT_NULL_BYTE
public static final byte ARRAY_ELEMENT_NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is null. This is used while writing the individual elements writers of an array. ARRAY_ELEMENT_NULL_BYTE < ARRAY_ELEMENT_NOT_NULL_BYTE to preserve the ordering while doing byte comparison- See Also:
- Constant Field Values
-
ARRAY_ELEMENT_NOT_NULL_BYTE
public static final byte ARRAY_ELEMENT_NOT_NULL_BYTE
Indicator byte denoting that the numeric value succeeding it is not null. This is used while writing the individual elements writers of an array- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NumericFieldWriter
public NumericFieldWriter(BaseNullableColumnValueSelector selector, boolean forArray)
-
-
Method Detail
-
writeTo
public long writeTo(org.apache.datasketches.memory.WritableMemory memory, long position, long maxSize)
Description copied from interface:FieldWriter
Writes the current selection at the given memory position.- Specified by:
writeTo
in interfaceFieldWriter
- Parameters:
memory
- memory region in little-endian orderposition
- position to writemaxSize
- maximum number of bytes to write- Returns:
- number of bytes written, or -1 if "maxSize" was not enough memory
-
close
public void close()
Description copied from interface:FieldWriter
Releases resources held by this writer.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFieldWriter
-
getNumericSizeBytes
public abstract int getNumericSizeBytes()
- Returns:
- The size in bytes of the numeric datatype that the implementation of this writer occupies
-
writeSelectorToMemory
public abstract void writeSelectorToMemory(org.apache.datasketches.memory.WritableMemory memory, long position)
Writes the value pointed by the selector to memory. The caller should ensure that the selector gives out the correct primitive type
-
writeNullToMemory
public abstract void writeNullToMemory(org.apache.datasketches.memory.WritableMemory memory, long position)
Writes the default value for the type to the memory. For long, it is 0L, for double, it is 0.0d etc. Useful mainly when the SQL incompatible mode is turned off, and maintains the fact that the size of the numeric field written doesn't vary irrespective of whether the value is null
-
-