Skip to content

Scaled key fields (timestamp scale)

Scaling is a transform of one field in a typed key section of a columnar revision 5 block. A scaled field stores small numbers instead of large ones, for example timestamps that all fall on a multiple of some granularity.

A field is scaled when bit 0x80 of its how byte is set. The field description then carries two more values:

  • g: a varint, at least 2. The granularity.
  • base: a zvarint.

The decoded value is:

decoded = base + g x stored

The scale is applied after run-delta reconstruction. If the field’s how is run, the reader first rebuilds the stored values from the deltas, then applies base + g x stored. A field with how same is never scaled.

The result is the field value. The key bytes are then tag ‖ BE u64(value ^ 2^63).

Scaling applies to fields whose tag is 0x05 (timestamp) or 0x03 (integer). The scaled values go through the usual IntCol codecs, so a scaled column of small integers packs into few bits, see Packed integers and FOR.