Unnest
Describes the unnest operator in the multi-stage query engine.
The unnest operator expands an array column into one row per element. It is invoked via the CROSS JOIN UNNEST(...) SQL syntax and is only available in the multi-stage query engine (MSE).
SQL syntax
Basic unnesting
SELECT t.id, elem
FROM myTable AS t
CROSS JOIN UNNEST(t.arrayColumn) AS u(elem)Each row in myTable that has n elements in arrayColumn produces n output rows. Rows where arrayColumn is NULL or empty produce no output rows.
WITH ORDINALITY
Adding WITH ORDINALITY attaches a 1-based position index to each unnested element:
SELECT t.id, elem, pos
FROM myTable AS t
CROSS JOIN UNNEST(t.arrayColumn) WITH ORDINALITY AS u(elem, pos)The ordinality column (pos) reflects the 1-based position of each element in the original array.
Unnesting multiple arrays together
Multiple arrays can be passed to one UNNEST call:
When multiple arrays are unnested together, Pinot aligns them by position, like a zip operation. If the arrays have different lengths, shorter arrays are padded with NULL values. Add WITH ORDINALITY when you also need the 1-based element position:
Filtering unnested elements
You can filter on the unnested alias in a WHERE clause:
Aggregating after unnesting
Implementation details
Blocking nature
The unnest operator is a streaming operator. It reads rows from its single upstream and emits output rows as it processes each input row. The operator does not buffer the full input before emitting.
NULL and empty array handling
For a single unnested array, rows where the column evaluates to NULL or to an empty array produce zero output rows. This matches the SQL CROSS JOIN semantic (no match = no output row). For multiple arrays in the same UNNEST call, Pinot aligns elements by position and pads shorter arrays with NULL values.
Output column pruning
By default, Pinot keeps passthrough columns in the intermediate UNNEST output schema, including the source array column. You can opt into pruning unused passthrough columns with SET unnestColumnPruning=true, or set pinot.broker.multistage.unnest.column.pruning=true to make that the broker default.
This optimization only applies on the logical planner path. Pinot ignores it when usePhysicalOptimizer=true, and you should keep it disabled until all servers in the cluster support the smaller UNNEST output schema.
Hints
None
Stats
executionTimeMs
Type: Long
The summation of time spent by all threads executing the operator.
emittedRows
Type: Long
The number of rows emitted by the operator after unnesting.
Explain attributes
The unnest operator appears in the logical explain plan as LogicalCorrelate with Uncollect.
Example explain plan
Expected output (illustrative):
Last updated
Was this helpful?

