Class NumericArrayFieldWriter
- All Implemented Interfaces:
Closeable,AutoCloseable,FieldWriter
Format:
- 1 Byte - NULL_ROW or NON_NULL_ROW denoting 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 steps
For each value in the non-null array:
- 1 Byte - NumericFieldWriter.ARRAY_ELEMENT_NULL_BYTE or NumericFieldWriter.ARRAY_ELEMENT_NOT_NULL_BYTE
denothing whether the proceeding value is null or not.
- ElementSize Bytes - The encoded value of the element
Once 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
FieldsModifier and TypeFieldDescriptionstatic final byteMarks the end of the array.static final byteDenotes that the array is non nullstatic final byteDenotes that the array itself is null -
Constructor Summary
ConstructorsConstructorDescriptionNumericArrayFieldWriter(ColumnValueSelector selector, NumericFieldWriterFactory writerFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases resources held by this writer.static NumericArrayFieldWritergetDoubleArrayFieldWriter(ColumnValueSelector selector, FrameType frameType) Returns the writer for ARRAYstatic NumericArrayFieldWritergetFloatArrayFieldWriter(ColumnValueSelector selector, FrameType frameType) 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 Details
-
NULL_ROW
public static final byte NULL_ROWDenotes that the array itself is null- See Also:
-
NON_NULL_ROW
public static final byte NON_NULL_ROWDenotes that the array is non null- See Also:
-
ARRAY_TERMINATOR
public static final byte ARRAY_TERMINATORMarks 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:
-
-
Constructor Details
-
NumericArrayFieldWriter
public NumericArrayFieldWriter(ColumnValueSelector selector, NumericFieldWriterFactory writerFactory)
-
-
Method Details
-
getLongArrayFieldWriter
Returns the writer for ARRAY -
getFloatArrayFieldWriter
public static NumericArrayFieldWriter getFloatArrayFieldWriter(ColumnValueSelector selector, FrameType frameType) Returns the writer for ARRAY -
getDoubleArrayFieldWriter
public static NumericArrayFieldWriter getDoubleArrayFieldWriter(ColumnValueSelector selector, FrameType frameType) 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
-