flatten_leaves
Aliases: flattenleaves (deprecated).
flatten_leaves pathexpression: col array or object, [suggesttypes: bool]?
Given an object or array input, recursively flatten all child elements into key-value columns, returning only leaf values.
The referenced column is removed. New columns include a string path (_c_<column>_path), a variant value column (_c_<column>_value), and a hidden int64 flatten id (_c_<column>_flattenid). Optional second argument suggesttypes must be a constant boolean literal; when true, an extra hidden string column (_c_<column>_type) records the suggested OPAL type for each value. The path column is appended to any existing primary key, grouping keys are cleared, and the result is no longer strongly keyed. Unlike flatten, intermediate object and array nodes are dropped entirely rather than emitted as rows. flatten_all keeps every node (including nested containers as values), and flatten_single expands only one level without recursing.
For similarly nested data, flatten is substantially more expensive than flatten_leaves or flatten_single; prefer this verb when you only need scalar or other leaf values.
Categories
Accelerable
flatten_leaves is always accelerable if the input is accelerable. A dataset that only uses accelerable verbs can be accelerated, making queries on the dataset respond faster.
Examples
make_col doc:parse_json('{"a":1,"b":{"c":2}}')
flatten_leaves doc
Recursively unnests a nested JSON object into one row per leaf path only, omitting intermediate object rows that flatten would keep with null values.
make_col items:parse_json('[{"x":1},{"x":2}]')
flatten_leaves items, true
Uses flatten_leaves with suggesttypes true so each emitted leaf row also gets a hidden-style type hint column for the flattened value.
Updated 19 days ago