Dremel - repetition and definition level
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Dremel's repetition and definition levels are the key idea that lets nested records be stored column by column without losing structural meaning. If you have ever wondered how a system can scan one nested field efficiently without fully flattening every row into a huge denormalized table, these two level values are the answer.
The point is not just compression. The levels encode whether a nested value exists and whether it begins a new repeated group, which lets a query engine reconstruct hierarchy while reading only the columns it needs.
Why Dremel Needs Extra Levels
Suppose a record contains optional fields and repeated lists. In a flat columnar store, a plain sequence of scalar values is not enough to recover which values belonged to which parent record and which optional fields were missing.
Dremel solves this by storing each leaf column together with:
- a definition level, which says how far down the schema path the value is actually defined,
- a repetition level, which says at what repeated nesting depth the current value continues the same repeated structure.
Without those extra integers, a column reader would know the values but not the nesting structure.
A Small Nested Example
Consider this schema idea:
- '
personhas an optionalname' - '
personhas a repeatedphone' - each
phonehas an optionalnumber
Example data:
Now focus only on the leaf column phone.number. The values alone would be:
That sequence by itself is ambiguous. The levels are what tell you which null means "phone entry exists but number is missing" and which null means "person had no phone entries at all."
Definition Level
The definition level counts how many optional or repeated nodes along the path are actually present for the current leaf.
For phone.number, the maximum definition level in this toy schema is reached when:
- the repeated
phoneentry exists, - the optional
numberfield exists.
If the phone entry exists but number is missing, the definition level is lower. If there is no phone entry at all for that person, it is lower still.
That is why definition level answers the question, "How much of the path to this leaf is defined?"
Repetition Level
The repetition level is about repeated structures. It tells the reader whether the current value starts a new parent record or continues an existing repeated group.
In the example above, the second phone number for Ana belongs to the same top-level person record as the first one. Its repetition level indicates that the repeated phone field is continuing rather than beginning a brand-new parent row.
That is why repetition level answers the question, "At what repeated depth am I still inside the same repeated collection?"
A Conceptual Encoding Sketch
For the phone.number leaf, a conceptual view might look like this:
Interpretation:
- '
111is fully defined and starts the first phone entry for Ana.' - '
222is also fully defined, but repetition level1means it continues the repeated phone list for the same person.' - the next
nullmeans Ben has a phone entry but the optionalnumberfield is missing. - the final
nullmeans Cara has no phone entry at all.
The exact numeric levels depend on the schema path, but this pattern is the essence.
Why This Matters for Query Engines
Because each leaf column carries enough structural information, Dremel-style systems can scan nested data selectively. A query touching only one leaf column does not need to materialize the whole document structure upfront.
This makes nested analytics practical in columnar storage systems such as those inspired by Dremel. The engine gets the scan efficiency of columns while still being able to reconstruct repeated and optional records when necessary.
Common Pitfalls
- Thinking repetition level is just a row counter. It is specifically about repeated nesting depth.
- Treating definition level as a simple null flag. It distinguishes multiple kinds of absence along a schema path.
- Forgetting that the maximum definition level depends on the schema, not on the value alone.
- Looking only at the leaf values and assuming the original nested structure is obvious.
- Mixing up "missing repeated field" with "present repeated field containing a missing optional leaf."
Summary
- Dremel stores nested leaf columns together with repetition and definition levels.
- Definition level describes how much of the schema path to the leaf is actually present.
- Repetition level describes whether a repeated structure is continuing or restarting.
- These levels let a columnar engine reconstruct nested records without fully flattening them.
- The idea is central to efficient querying of nested data in Dremel-style systems.
Related reading
- Duplicate a LinkedList with a pointer to a random node apart from the next node
- duplicate a tensorflow graph
- Duplicate keys in .NET dictionaries?
- Dynamic Array with O1 removal of any element
- Dynamic queue creation with RabbitMQ
- Dynamically creating asynchronous message queues in Java
- Dynamically updating shortest paths
- DynamoDB adjacency list primary key

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.