Class NumericArrayFieldWriter
- java.lang.Object
-
- org.apache.druid.frame.field.NumericArrayFieldWriter
-
- All Implemented Interfaces:
Closeable,AutoCloseable,FieldWriter
public class NumericArrayFieldWriter extends Object implements FieldWriter
Writes the values of the type ARRAYwhere X is a numeric type to row based frames. The format of the array written is as follows: Format: - 1 Byte -
NULL_ROWorNON_NULL_ROWdenoting whether the array itself is null - If the array is null, then the writer stops here - If the array is not null, then it proceeds to the following stepsFor each value in the non-null array: - 1 Byte -
NumericFieldWriter.ARRAY_ELEMENT_NULL_BYTEorNumericFieldWriter.ARRAY_ELEMENT_NOT_NULL_BYTEdenothing whether the proceeding value is null or not. - ElementSize Bytes - The encoded value of the elementOnce all the values in the non-null arrays are over, writes
ARRAY_TERMINATOR. This is to aid the byte comparison, and also let the reader know that the number of elements in the array are over.The format doesn't add the number of elements in the array at the beginning, so that the serialization of the arrays are byte-by-byte comparable.
Examples: 1. null | Bytes | Value | Interpretation | |--------|-------|-----------------------------| | 1 | 0x00 | Denotes that the array null |
2. [] (empty array) | Bytes | Value | Interpretation | |--------|----- -|------------------------------------| | 1 | 0x01 | Denotes that the array is not null | | 2 | 0x00 | End of the array |
3. [5L, null, 6L] | Bytes | Value | Interpretation | |---------|--------------|-----------------------------------------------------------------------------------| | 1 | 0x01 | Denotes that the array is not null | | 2 | 0x02 | Denotes that the next element is not null | | 3-10 | transform(5) | Representation of 5 | | 11 | 0x01 | Denotes that the next element is null | | 12-19 | transform(0) | Representation of 0 (default value, the reader will ignore it if SqlCompatible mode is on | | 20 | 0x02 | Denotes that the next element is not null | | 21-28 | transform(6) | Representation of 6 | | 29 | 0x00 | End of array |
-
-
Field Summary
Fields Modifier and Type Field Description static byteARRAY_TERMINATORMarks the end of the array.static byteNON_NULL_ROWDenotes that the array is non nullstatic byteNULL_ROWDenotes that the array itself is null
-
Constructor Summary
Constructors Constructor Description NumericArrayFieldWriter(ColumnValueSelector selector, NumericFieldWriterFactory writerFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases resources held by this writer.static NumericArrayFieldWritergetDoubleArrayFieldWriter(ColumnValueSelector selector)Returns the writer for ARRAYstatic NumericArrayFieldWritergetFloatArrayFieldWriter(ColumnValueSelector selector)Returns the writer for ARRAYstatic NumericArrayFieldWritergetLongArrayFieldWriter(ColumnValueSelector selector)Returns the writer for ARRAYlongwriteTo(org.apache.datasketches.memory.WritableMemory memory, long position, long maxSize)Writes the current selection at the given memory position.
-
-
-
Field Detail
-
NULL_ROW
public static final byte NULL_ROW
Denotes that the array itself is null- See Also:
- Constant Field Values
-
NON_NULL_ROW
public static final byte NON_NULL_ROW
Denotes that the array is non null- See Also:
- Constant Field Values
-
ARRAY_TERMINATOR
public static final byte ARRAY_TERMINATOR
Marks the end of the array. SinceNULL_ROWandARRAY_TERMINATORwill only occur at different locations, therefore there is no clash in keeping both's values at 0x00- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NumericArrayFieldWriter
public NumericArrayFieldWriter(ColumnValueSelector selector, NumericFieldWriterFactory writerFactory)
-
-
Method Detail
-
getLongArrayFieldWriter
public static NumericArrayFieldWriter getLongArrayFieldWriter(ColumnValueSelector selector)
Returns the writer for ARRAY
-
getFloatArrayFieldWriter
public static NumericArrayFieldWriter getFloatArrayFieldWriter(ColumnValueSelector selector)
Returns the writer for ARRAY
-
getDoubleArrayFieldWriter
public static NumericArrayFieldWriter getDoubleArrayFieldWriter(ColumnValueSelector selector)
Returns the writer for ARRAY
-
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
-
-