advanced30 min studyLesson 298 in Engineering

Preserve nulls, empty lists, and repetition without row objects

Trace definition/repetition levels and contrast them with Arrow offsets and validity while preserving nested semantics exactly.

On this page

What you’ll understand

  • Distinguish null lists, empty lists, null elements, and present elements.
  • Derive definition and repetition levels for one explicit three-level list schema.
  • Explain why Parquet levels and Arrow offsets/validity represent structure differently.

Flattening nested records into independent value arrays loses information unless structure is carried alongside them. The numbers seven and eight do not tell us whether they came from two rows, one list, or lists containing missing elements. Nested columnar representations preserve those relationships without materializing a complete row object for every record. The essential goal is lossless semantics, including the differences between absence, emptiness, and repeated occurrences.

Missing and empty are different states

A null list means the list value is absent; an empty list is present but contains no elements. A present list can itself contain null elements if the element type is optional. These states can produce different results for length, null tests, and unnesting, so replacing all of them with an empty value stream is incorrect. Define the schema's optional and repeated nodes before constructing an example. An encoded leaf stream must provide enough structural evidence to reassemble the intended parent rows and containers.

In the Dremel-style approach used by Parquet, a definition level describes how far the optional/repeated path is defined, while a repetition level identifies the repeated ancestor at which a subsequent occurrence continues. A repetition level of zero begins a new top-level record. Their maximum values come from the schema, not from the largest list observed in one batch. Physical nonnull leaf values are stored only when the required path is fully defined; structural entries can still exist for null or empty states that contribute no physical value.

dmax⁡=#(optional or repeated nodes on the leaf path),rmax⁡=#(repeated nodes on that path)d_{\max}=\#(\text{optional or repeated nodes on the leaf path}),\qquad r_{\max}=\#(\text{repeated nodes on that path})
These counts describe the stated Parquet/Dremel structural path from the required root to one leaf. Levels are dimensionless integers. An optional three-level list with a repeated entry group and optional element has d_max=3 and r_max=1.↔ Scroll wide equations horizontally.

Derive one schema instead of memorizing a level table

Use a required root containing optional group tags annotated as LIST; tags contains repeated group list; list contains optional int32 element. The optional list contributes the first definition level, the repeated entry the second, and the optional element the third. Thus a null tags list has definition zero; a present empty list has definition one; a null element in a present entry has definition two; and an actual integer has definition three. Only the last state contributes an integer to the physical value stream.

For this single repeated ancestor, repetition zero starts a row and repetition one continues the same row's list. More deeply nested repeated paths need more levels, so do not apply this small table universally. Decode levels and leaf values together, using the schema and declared counts, then reconstruct or directly evaluate the required operation. Test lists spanning page boundaries and empty/null parents as well as simple nonempty arrays. A value-count mismatch can shift all later rows even if every integer decoder output is individually correct.

Nphysical values=∑j=1Nlevel entries1{dj=dmax⁡}N_{\rm physical\ values}=\sum_{j=1}^{N_{\rm level\ entries}}\mathbf{1}\{d_j=d_{\max}\}
For this optional INT32 leaf stream, each fully defined level entry contributes one physical integer. Lower-definition entries carry structural absence instead. Level-entry count, physical-value count, and top-level row count are different dimensionless counts.↔ Scroll wide equations horizontally.

In-memory arrays can preserve the same meaning differently

Arrow's ordinary variable-size List layout uses parent validity, offsets into a child array, and the child's own validity/value representation. Equal neighboring offsets can describe an empty present list; a parent validity bit distinguishes a null list, whose child segment is not semantically interpreted as an ordinary valid list. This layout supports different access patterns from an on-disk level stream. Converting Parquet to Arrow therefore reconstructs structure, and cannot be assumed to be a zero-copy reinterpretation of the same buffers. ORC also has its own presence and length-oriented streams.

For a narrow optional-scalar analogy, Reset the probability lab, set both p=0.6 and n=10, predict six present physical values on average, then Play or Step. The exact binomial model assumes independent scalar presence at one optional path; playback highlights bars rather than sampling records. Reset and re-enter both controls for another case. Repeated lists violate any simple equation between row count and trial count, and the instrument emits no definition levels, repetition levels, offsets, or nested rows. Use the worked trace, rather than this probability analogy, to verify reconstruction.

Encode four list rows without losing absence

Use the explicit optional tags/LIST → repeated list → optional INT32 element schema above. The four top-level rows are null, [], [null,7], and [8]. List the structural entries and count physical integers.

  1. The null list emits (repetition,definition)=(0,0), and the empty present list emits (0,1). Neither contributes a physical integer.

  2. The third row emits (0,2) for its null element and (1,3) for seven. The fourth row begins anew with (0,3) for eight.

  3. There are five level entries, four top-level rows, and only two physical INT32 values: seven and eight. Two-bit definition levels and one-bit repetition levels suffice before their actual stream framing and compression.

The result

The level stream preserves null list, empty list, null element, and row boundaries. Reading just the two integers would lose the original four-row structure.

Explore the model

Interactive lab

Interactive lab · probability

Optional scalar presence is a narrower model

Reset, set both p=0.6 and n=10, predict six present optional scalar values on average, then Play or Step. Reset and re-enter both controls before another case. These exact independent-presence probabilities do not encode nested lists, levels, offsets, or row boundaries; repeated structures require the explicit schema trace.

Optional scalar presence is a narrower modelThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. 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 forPhysical nonnull values and structural entries are separate counts, especially when repeated or absent containers are involved.

Check your understanding

Under the lesson's explicit three-level optional-list schema, what distinguishes an empty present list from a null list in its leaf-level stream?

Try it yourself

With the same explicit optional-list schema, trace rows [5,null,6] and []. Give (repetition,definition) entries, top-level row count, and physical integer count.

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

Give me a hint

Begin each row with repetition zero, continue an existing list with repetition one, and distinguish present/null elements from an empty list.

Compare with the solution

The first row emits (0,3) for five, (1,2) for its null element, and (1,3) for six. The empty second row emits (0,1). There are four level entries, two top-level rows, and two physical integers. The exact levels rely on this schema and are not universal constants for every list representation.

Take it with you

  • Null containers, empty containers, and null elements are distinct semantic states.
  • Definition/repetition levels derive from schema paths and must stay aligned with physical values.
  • Arrow offsets and validity preserve related semantics through a different physical representation.

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.