advanced28 min studyLesson 293 in Engineering

Small residuals, fixed-width arithmetic, and bit packing

Derive delta residual widths, handle specified wraparound correctly, and distinguish a teaching sequence from a valid format block.

On this page

What you’ll understand

  • Calculate deltas, a block minimum, and nonnegative residual widths.
  • Explain why fixed-width overflow semantics belong to the format contract.
  • Distinguish encoding blocks and miniblocks from pages, row groups, and generic compression.

A monotonically increasing integer sequence can contain large absolute values and tiny differences. Delta encoding changes the representation so the smaller quantity becomes the one stored repeatedly. Bit packing then removes unused high bits. These transformations are lossless only when arithmetic, block boundaries, padding, and value counts are defined precisely. A mathematically plausible decoder can still be incompatible if its programming language treats overflow differently from the file format.

Subtract a predictable part before packing

For a sequence of integers, preserve the first value and form differences between consecutive values. A block can then choose its minimum delta as a reference and store nonnegative residuals relative to that minimum. If every delta equals the same step, all residuals are zero, requiring no residual payload bits in the ideal case. The step and framing still require representation. This is different from dictionary encoding: a steadily increasing timestamp column may have almost every absolute value distinct while its deltas remain highly predictable.

Parquet DELTA_BINARY_PACKED supports its specified INT32 and INT64 streams and uses blocks subdivided into miniblocks with their own bit widths. The block header, reference deltas, and counts establish how values are reconstructed. Actual block sizes have format constraints, so a four-number classroom example is an arithmetic illustration, not a literal valid tiny Parquet block. A reader must stop at the declared value count rather than expose padding as real rows. Byte-array delta-length and prefix encodings are related but have different layouts and supported types; their names do not make them interchangeable.

di=xi−xi−1,m=min⁡idi,ri=di−md_i=x_i-x_{i-1},\qquad m=\min_i d_i,\qquad r_i=d_i-m
For this first derivation, integer arithmetic is exact and residuals r_i are nonnegative. A miniblock's ideal bit width is ceil(log2(1+max r_i)); an all-zero residual block needs zero residual bits. Values and deltas have the integer column's units.↔ Scroll wide equations horizontally.

Overflow behavior is part of lossless decoding

Fixed-width integers complicate the exact-arithmetic derivation. Parquet specifies two's-complement wrapping behavior for the relevant delta subtractions and inverse additions when overflow occurs. Implementations must arrange that behavior deliberately in languages where signed overflow is undefined or where integers have unbounded precision. An unsigned-domain implementation can preserve bit patterns, but must still apply the required signed interpretation at the correct stages. Simply enabling a compiler optimization and hoping signed subtraction wraps is not a portable encoding strategy.

An outlier can increase the width needed for its miniblock without forcing every value in the entire file to use that width. That adaptability trades compactness against headers, decoding branches, vectorization opportunities, and implementation complexity. Original integer-compression research shows why decoder throughput matters alongside compression ratio; do not copy historical performance numbers to a different CPU or distribution. Test boundaries near minimum and maximum representable values, negative steps, constant deltas, short final blocks, and changing miniblock widths. Round-trip tests should check exact bit patterns and declared row counts.

bits⁡w(xi)=(bits⁡w(xi−1)+bits⁡w(di)) mod 2w\operatorname{bits}_w(x_i)=\bigl(\operatorname{bits}_w(x_{i-1})+\operatorname{bits}_w(d_i)\bigr)\bmod 2^w
This illustrates reconstruction of w-bit patterns under specified modular addition. It does not replace the format's complete signed minimum-delta and residual rules. w is the physical integer bit width, not a user-selected arbitrary modulus in a real Parquet file.↔ Scroll wide equations horizontally.

Validate a representation rather than guessing from sorted data

Sorting often reduces changes between neighbors, but delta encoding can still help unsorted data when differences have a narrow local distribution. Conversely, a monotone sequence with wildly varying gaps may compress less effectively than expected. Inspect actual encoded pages and decode cost with representative gaps, nulls, and groups. Nulls are carried through structural information rather than invented integer values in the nonnull stream. Preserve the relationship between that stream and the reconstructed rows; a decoder that produces the right integers at wrong row positions is still incorrect.

The modular lab isolates wrapping with a small visible modulus. Reset, set both modulus m=16 and additive step a=3, predict residue zero initially and residue three after one Step, then inspect it. Each Step advances half a second and one addition because n=floor(2t). Further steps produce six and nine before wrapping eventually. The sixteen-element cycle is a four-bit arithmetic analogy, not a DELTA_BINARY_PACKED encoder; the lab has no minimum-delta selection, miniblocks, page headers, or INT32 overflow test. Changing controls retains elapsed time, so Reset before a separate comparison.

Pack the residuals of a nearly regular sequence

For the teaching sequence 1,000, 1,003, 1,007, 1,010, compute deltas and residuals. Estimate their ideal residual bit count, explicitly excluding actual Parquet block framing and padding.

  1. The three deltas are 3, 4, and 3 in the column's units. Their minimum is three.

  2. Subtract that minimum to obtain residuals zero, one, zero. The maximum residual is one, so one bit per residual suffices: three payload bits in this teaching calculation.

  3. Reconstruct from the first value: 1,000 + 3 + 0 = 1,003; then add 3 + 1 to reach 1,007; then add 3 + 0 to reach 1,010. A real encoded block also stores framing, the first value, reference information, and format-constrained padding.

The result

Small residuals explain the opportunity, while three bits alone are not a complete encoded representation or a valid four-value Parquet block layout.

Explore the model

Interactive lab

Interactive lab · modular

Inspect wraparound without undefined arithmetic

Reset, set both m=16 and additive step a=3, predict r0=0 and r1=3, then Step once. Each half-second Step advances one addition; Play advances two per second. Reset and re-enter both controls before another case because edits retain elapsed time. This modular-addition model is not a Parquet delta encoder or a signed-overflow checker.

Inspect wraparound without undefined arithmeticAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forLossless reconstruction depends on explicitly specified arithmetic and framing, not just on recognizing a small difference.

Check your understanding

Why can an otherwise plausible delta decoder fail when ported to a language where signed overflow is undefined?

Try it yourself

A teaching sequence is 50, 55, 61, 66, 74. Find its deltas, minimum delta, residuals, and ideal fixed width for those residuals before headers or padding.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Subtract neighbors, then subtract the smallest delta from every delta.

Compare with the solution

Deltas are 5, 6, 5, and 8. The minimum is five, giving residuals zero, one, zero, and three. Two bits represent residual values zero through three, so the ideal four-residual payload is eight bits. This is only the arithmetic component, not the complete byte count of a valid format block.

Take it with you

  • Delta references expose small residuals that can be packed with few bits.
  • Fixed-width overflow and padding rules are required for exact interoperable reconstruction.
  • Compression ratio, decoder throughput, and row/structural alignment need separate verification.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.