DELTA
DELTA stores an integer stream as a few absolute values and the differences between neighbours. It is codec id 2 in IntCol only. It is not available in Flat.
Layout
Section titled “Layout”| Field | Encoding | Meaning |
|---|---|---|
| count | varint | n, the number of values. n >= 1 is required. |
| codec | u8 | 2 |
| samples | Flat | ceil(n/64) absolute values, at indices 0, 64, 128, … |
| deltas | Flat | n - 1 wrapping differences between neighbours |
Each Flat here has its own count, codec byte and body, see Column container types.
How to decode
Section titled “How to decode”- Read
count(at least 1), the codec byte (2), the samples Flat and the deltas Flat. - Value 0 is sample 0.
- For
ifrom 1, valueiis valuei - 1plusdeltas[i - 1], with 64-bit wrapping arithmetic. - The sample at index
64 kis the absolute value of the stream at that index, so a reader can start from the nearest earlier sample instead of from index 0.
Illustration
Section titled “Illustration”Derived by hand, not from a real file. The values 10, 13, 16, 19 give one sample (ceil(4/64) = 1) of 10 and the 3 deltas 3, 3, 3.
04 02 count 4, codec DELTA01 00 14 samples: Flat, count 1, CONST, v = 1003 00 06 deltas: Flat, count 3, CONST, v = 3Decoded: 10, 13, 16, 19.
Checks
Section titled “Checks”n >= 1.- The samples Flat has
ceil(n/64)values and the deltas Flat hasn - 1. - The arithmetic wraps; it does not fail on overflow.
When writers pick it
Section titled “When writers pick it”See How writers choose a codec.
Related
Section titled “Related”- RLE and Integer DICT
- FOR and CONST
- Column codecs