Skip to content

Support serializing and executing explodes as table functions over an ExplodeValue - #4819

Merged
g31pranjal merged 16 commits into
mainfrom
apple/g31pranjal/unnested/explode-value-serialization
Nov 9, 2026
Merged

g31pranjal merged 16 commits into
mainfrom
apple/g31pranjal/unnested/explode-value-serialization

Conversation

@g31pranjal

@g31pranjal g31pranjal commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Adds what a server needs to deserialize and execute plans in which explodes are table functions over an ExplodeValue, ahead of the planner producing such plans in #4816. Shipping this first lets a server running this version execute plans and continuations produced by a server running #4816.

Nothing plans these constructs yet, so plans are unchanged.

Changes

  • ExplodeValue: a StreamingValue that produces an (element, ordinal) struct per element of an array, akin to UNNEST ... WITH ORDINALITY. It streams with an ExplodeCursorContinuation, or evaluates eagerly (evalAsList).
    • preserveOrder: the ordinals are observed, so the collection must not be reordered. Otherwise the planner may replace it by any permutation.
    • sorted / reverse: the explode produces its elements in ascending or descending order and numbers the ordinals in that order. Only an explode that does not preserve its order can be sorted, and only elements with a Comparable representation.
  • InExplodeSource: an InComparandSource that binds the structs of an explode, so the inner plan reads the element and ordinal as it would from the explode. It is sorted and reverse when its explode is.
  • RecordQueryInUnionPlan reports the dynamic types of its IN sources.
  • DerivationsProperty: a table function over an explode derives the struct it flows, built from a representative element of the collection.
  • New protos: PExplodeValue, PInExplodeSource and ExplodeCursorContinuation.
  • Tests: ExplodeValueTest (streaming, continuations, sorting, cardinalities, equality, explain, derivations, proto round trips) and InExplodeSourceTest (evaluation, flowed type, hashing and proto round trips).

Compatibility

A server without this change cannot deserialize PExplodeValue or PInExplodeSource, so it cannot execute plans or resume continuations that contain them. That is why this change has to be deployed before #4816 starts producing such plans.

@g31pranjal g31pranjal added the enhancement New feature or request label Nov 2, 2026
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-value-serialization branch from c8f9e16 to c83eeb6 Compare November 2, 2026 17:43
@g31pranjal
g31pranjal changed the base branch from main to apple/g31pranjal/push-in-comparand-join-through-fetch November 3, 2026 15:35
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-value-serialization branch from c83eeb6 to c631a7f Compare November 3, 2026 15:35
Base automatically changed from apple/g31pranjal/push-in-comparand-join-through-fetch to main November 3, 2026 18:58
@g31pranjal
g31pranjal marked this pull request as ready for review November 3, 2026 22:22
@g31pranjal
g31pranjal changed the base branch from main to apple/g31pranjal/port-affected-core-tests-to-yamsql November 5, 2026 00:25
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-value-serialization branch 3 times, most recently from 1492507 to fee82ec Compare November 5, 2026 11:34
Base automatically changed from apple/g31pranjal/port-affected-core-tests-to-yamsql to main November 5, 2026 14:39
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-value-serialization branch 2 times, most recently from 80ac3f9 to 30f79e7 Compare November 6, 2026 00:07
@g31pranjal
g31pranjal requested a review from normen662 November 6, 2026 00:21
… ExplodeValue

Adds what a server needs to deserialize and execute plans in which explodes are
table functions over an `ExplodeValue`, ahead of the planner producing them:

- `ExplodeValue`, a streaming value producing a struct `(element)`, or
  `(element, ordinal)` if it is with ordinality, per element of an array, and its
  continuation.
- `ArraySortValue`, a sorted array, which a sorted IN source explodes.
- `InExplodeSource`, an IN source binding the structs of an explode.
- Serialization of list literals in `LiteralValue`.
- `RecordQueryInUnionPlan` reports the dynamic types of its sources, and
  `InComparandSource` tolerates comparisons without a comparand value.

Nothing plans these yet.
An array sort compares its elements as Comparables, so reject element types whose
representation is not, such as records, bytes and vectors, when it is created.
The derivations of a table function over an ExplodeValue are a struct of the first element of the collection (and
an ordinal, if the explode has one), as for the explode plan before, rather than the first struct the explode flows.
That keeps the correlations of the collection and the shape of the struct the explode flows.
The planner no longer builds explodes over literal lists or parameters, so the
list serialization of literals, the literal and parameter accessors of the
in-explode source, and the coercion of literal elements are not needed.
Every explode flows the ordinal now, so the flag no longer says whether there is one. It
says whether the planner must keep the collection in its order, which is what keeps the
ordinals meaningful.
They existed for the explodes of literal lists and parameters, which are gone. InExplodeSource
overrides both methods itself, so every remaining InComparandSource has a comparand value.
…ection

ExplodeValue gains sorted and reverse flags, and sorts the elements itself. An IN source over
a sorted explode no longer has to recognise an ArraySortValue as the collection, which would
need digging up once anything else wraps the sort, so ArraySortValue is removed.
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/explode-value-serialization branch from 30f79e7 to a7d806c Compare November 9, 2026 19:03
@g31pranjal
g31pranjal merged commit d8dcc6a into main Nov 9, 2026
14 checks passed
@g31pranjal
g31pranjal deleted the apple/g31pranjal/unnested/explode-value-serialization branch November 9, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants