Skip to main content

Module histogram

Module histogram 

Source
Expand description

Native histogram sample column encoding 8.

One chunk holds a whole struct column of a block, laid out child by child. Every child is encoded with the nullable XOR codec of encoding 5: floats keep their bit patterns, integers are ZigZag-mapped first, and a list is its nullable lengths followed by its flattened items. The chunk header names the child count and each child’s kind, so a reader decodes the chunk only against the exact struct type it was written for.

child_count   u8
child_kinds   u8 x child_count       1 Float64, 2 Int32, 3 Int64, 4 Timestamp(ms),
                                     0x10 | kind for a list
list_items    uvarint                items of all valid lists in the chunk
validity      ceil(rows / 8) bytes   only when the struct has null rows
child 0 .. child 17, in struct order:
  scalar      section(rows values)
  list        section(rows lengths), then section(items), omitted if it has no items
section(n)    null_count uvarint; unless all n are null: byte_length uvarint and an
              encoding 5 body

The header records kinds, not names, so children of one kind are told apart by position alone. The struct order, from NATIVE_HISTOGRAM_FIELD_NAMES:

 0 schema                  Int32           9 negative_span_lengths   List<Int32>
 1 zero_threshold          Float64        10 count_i64               Int64
 2 sum                     Float64        11 zero_count_i64          Int64
 3 reset_hint              Int32          12 positive_buckets_i64    List<Int64>
 4 start_timestamp         Timestamp(ms)  13 negative_buckets_i64    List<Int64>
 5 custom_values           List<Float64>  14 count_f64               Float64
 6 positive_span_offsets   List<Int32>    15 zero_count_f64          Float64
 7 positive_span_lengths   List<Int32>    16 positive_buckets_f64    List<Float64>
 8 negative_span_offsets   List<Int32>    17 negative_buckets_f64    List<Float64>

The part-file layout around the chunk is in docs/formats/mito-samples.md, “Native histogram encoding 8”.

Structs§

ChunkBound 🔒
The encoded size bound of a chunk that is still being filled, so a writer can cut a block before its histogram chunk would exceed CHUNK_LIMIT.

Enums§

Child 🔒
Scalar 🔒
A child value type and its lossless u64 mapping.
Values 🔒
Typed access to one child’s values as their u64 mapping.

Constants§

CHILD_FRAMING_BOUND 🔒
Upper bound of one child’s framing: its kind byte and the count/length varints of at most two nullable sections.
DECODED_VALUE_BYTES 🔒
Memory a reader retains per decoded value: the decoded Option<u64>, its Arrow value and offset, and a copy of both when the block is narrowed to the selected rows.
ENCODING 🔒
Sample column encoding ID of a native histogram struct chunk.
HEADER_BOUND 🔒
Upper bound of the chunk header besides child framing and struct validity: the child count and the list item count.
ROW_FRAMING_BOUND 🔒
Upper bound of one row’s framing: its struct validity bit.
VALUE_BOUND 🔒
Upper bound of one encoded value, its validity bit included: a full varint plus a bitmap byte, which also covers a section’s 8-byte first value.

Functions§

check_array_sample_sizes 🔒
Requires every row of a native histogram column to fit a chunk on its own.
check_sample_size 🔒
Requires one sample with children struct children and list_items bucket list items to fit a chunk on its own, which is what lets the writers place every accepted sample.
decode 🔒
Decodes a chunk written by encode as data_type, which must be the struct type the chunk was written for. nulls is the descriptor’s struct-level null count.
decoded_bytes 🔒
Memory the reader must account for before decoding a chunk of rows rows.
encode 🔒
Encodes a native histogram struct column. All rows are encoded, null rows included, and the struct validity is kept apart from the children’s own validity.
layout 🔒
list_items 🔒
Items of the valid lists of array[row].
list_value_count 🔒
Reads the chunk’s total list item count. A writer cuts chunks by ChunkBound, which charges every item VALUE_BOUND bytes, so a larger count is corrupt rather than merely large.
put_nullable 🔒
Writes values as a null count followed, unless every value is null, by the byte length and body of encoding 5.
row_bytes 🔒
Upper bound of the bytes one row adds to a chunk: one value per child, which covers a list’s length, one value per list item, and its struct validity bit.
take_nullable 🔒
Reads count values written by put_nullable. The caller bounds count.