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
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 (). 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
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-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteIndicator byte denoting that the numeric value succeeding it is not null.static final byteIndicator byte denoting that the numeric value succeeding it is null.static final byteIndicator byte denoting that the numeric value succeeding it is not null.static final byteIndicator byte denoting that the numeric value succeeding it is null. -
Constructor Summary
ConstructorsConstructorDescriptionNumericFieldWriter(BaseNullableColumnValueSelector selector, boolean forArray) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases resources held by this writer.abstract intabstract voidwriteNullToMemory(org.apache.datasketches.memory.WritableMemory memory, long position) Writes the default value for the type to the memory.abstract voidwriteSelectorToMemory(org.apache.datasketches.memory.WritableMemory memory, long position) Writes the value pointed by the selector to memory.longwriteTo(org.apache.datasketches.memory.WritableMemory memory, long position, long maxSize) Writes the current selection at the given memory position.
-
Field Details
-
NULL_BYTE
public static final byte NULL_BYTEIndicator 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:
-
NOT_NULL_BYTE
public static final byte NOT_NULL_BYTEIndicator byte denoting that the numeric value succeeding it is not null. This is used in the primitive writers- See Also:
-
ARRAY_ELEMENT_NULL_BYTE
public static final byte ARRAY_ELEMENT_NULL_BYTEIndicator 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:
-
ARRAY_ELEMENT_NOT_NULL_BYTE
public static final byte ARRAY_ELEMENT_NOT_NULL_BYTEIndicator 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:
-
-
Constructor Details
-
NumericFieldWriter
-
-
Method Details
-
writeTo
public long writeTo(org.apache.datasketches.memory.WritableMemory memory, long position, long maxSize) Description copied from interface:FieldWriterWrites the current selection at the given memory position.- Specified by:
writeToin 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:FieldWriterReleases resources held by this writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein 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
-