Class NumericArrayFieldWriter

  • All Implemented Interfaces:
    Closeable, AutoCloseable, FieldWriter

    public class NumericArrayFieldWriter
    extends Object
    implements FieldWriter
    Writes the values of the type ARRAY where X is a numeric type to row based frames. The format of the array written is as follows:

    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 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. Since NULL_ROW and ARRAY_TERMINATOR will only occur at different locations, therefore there is no clash in keeping both's values at 0x00
        See Also:
        Constant Field Values
    • 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 interface FieldWriter
        Parameters:
        memory - memory region in little-endian order
        position - position to write
        maxSize - maximum number of bytes to write
        Returns:
        number of bytes written, or -1 if "maxSize" was not enough memory