Typed key section
The typed key section is the key part of a columnar revision 5 block (SPEC V730). It replaces the four key fields of the base layout: shared, suffix, restart offsets and key body.
It is used only in stable columnar files (layer 2 or higher), and only when it is smaller. The conditions are on the revision 5 page.
Layout
Section titled “Layout”| Field | Encoding | Meaning |
|---|---|---|
len |
count(65535) |
Every key has exactly this length, at least 9 |
nf |
count(len/9), at least 1 |
Number of fields |
nf x field |
see below | Field descriptions |
| rest | BytesCol (n) |
Each key with its field bytes removed |
| streams | one IntCol (n) per field whose how is not SAME, in field order |
The field values |
Field description
Section titled “Field description”| Field | Encoding | Meaning |
|---|---|---|
| offset | count(len) |
Strictly increasing, non-overlapping, and off + 9 <= len |
| tag | u8 | 0x03 (integer) or 0x05 (timestamp) |
| how | u8 | Coding of the field, see below |
| source | count(j-1), only if how is SAME |
Source field, an earlier field index |
g |
varint, only if how has bit 0x80 |
Granularity, at least 2 |
base |
zvarint, only if how has bit 0x80 |
Base |
The how byte
Section titled “The how byte”The low bits give the coding.
| Low bits | Name | Meaning |
|---|---|---|
| 0 | plain | The stream holds the field values |
| 1 | run | The value is a delta against the previous row when all earlier fields equal the previous row’s |
| 2 | same | Identical to an earlier field on every row. It has 0 bytes and is never scaled. |
Bit 0x80 means scaled: decoded value = base + g x stored, applied after run-delta reconstruction. See Scaled key fields.
Rebuilding a key
Section titled “Rebuilding a key”The key bytes of a field are tag ‖ BE u64(value ^ 2^63). A reader puts these 9 bytes at the field offset and fills the other positions from rest. Every key in the block has the same tag at each field offset.
Writer behaviour
Section titled “Writer behaviour”Field offsets are chosen by dynamic programming to maximise the number of fields. Each stream is an IntCol, so it uses the integer codecs.