Skip to content

Expand an unnested record type into a Cascades graph - #4626

Open
g31pranjal wants to merge 4 commits into
mainfrom
apple/g31pranjal/unnested/synthetic-type-expand
Open

g31pranjal wants to merge 4 commits into
mainfrom
apple/g31pranjal/unnested/synthetic-type-expand

Conversation

@g31pranjal

@g31pranjal g31pranjal commented Sep 16, 2026

Copy link
Copy Markdown
Member

Adds SyntheticRecordType.expand, which turns a synthetic record type into the graph that assembles its records, and implements it for UnnestedRecordType: a select over the parent record's scan joined with one explode per nested constituent, whose result columns are the constituents plus the __positions field the synthetic primary key needs.

The explodes are created WITH ORDINALITY, because a stored position is exactly the ordinal of the element within its owner's array, and there is no other way to recover it. They ask for 0-based ordinals (the pull request below this one); it then only needs widening from the INT the explode flows to the LONG the Positions message declares.

This is groundwork: nothing calls expand yet. It is what lets a value index defined on a synthetic type become a match candidate, so that a query performing the same unnesting by hand can be answered from the index.

@g31pranjal g31pranjal added the enhancement New feature or request label Sep 16, 2026
@g31pranjal
g31pranjal added this pull request to stack #4627 September 16, 2026 11:19
@g31pranjal
g31pranjal removed this pull request from stack #4627 September 16, 2026 13:16
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/opt-in-zero-based-ordinality branch from 4d2d403 to 9b5aca6 Compare September 16, 2026 13:16
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 51f14cb to 40cfe34 Compare September 16, 2026 13:16
@g31pranjal
g31pranjal added this pull request to stack #4628 September 16, 2026 13:17
@g31pranjal
g31pranjal removed this pull request from stack #4628 September 16, 2026 13:35
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/opt-in-zero-based-ordinality branch from 9b5aca6 to f1509aa Compare September 16, 2026 13:35
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 40cfe34 to 28a0ea8 Compare September 16, 2026 13:35
@g31pranjal
g31pranjal added this pull request to stack #4629 September 16, 2026 13:36
Base automatically changed from apple/g31pranjal/unnested/opt-in-zero-based-ordinality to main September 16, 2026 18:55
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch 4 times, most recently from 03556e0 to 91b08d7 Compare September 17, 2026 14:22
@g31pranjal
g31pranjal marked this pull request as ready for review September 17, 2026 14:22
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 91b08d7 to b8c1fb4 Compare September 17, 2026 22:34
@g31pranjal
g31pranjal removed this pull request from stack #4629 September 17, 2026 22:35
@g31pranjal
g31pranjal added this pull request to stack #4632 September 17, 2026 22:35
@g31pranjal
g31pranjal removed this pull request from stack #4632 September 17, 2026 22:39
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from b8c1fb4 to 24551d6 Compare September 17, 2026 22:39
@github-actions

Copy link
Copy Markdown

📊 Metrics Diff Analysis Report

Summary

  • New queries: 0
  • Dropped queries: 0
  • Plan changed + metrics changed: 0
  • Plan unchanged + metrics changed: 0
ℹ️ About this analysis

This automated analysis compares query planner metrics between the base branch and this PR. It categorizes changes into:

  • New queries: Queries added in this PR
  • Dropped queries: Queries removed in this PR. These should be reviewed to ensure we are not losing coverage.
  • Plan changed + metrics changed: The query plan has changed along with planner metrics.
  • Metrics only changed: Same plan but different metrics

The last category in particular may indicate planner regressions that should be investigated.

@g31pranjal
g31pranjal changed the base branch from main to apple/g31pranjal/unnested/zero-based-ordinality September 17, 2026 22:43
@g31pranjal
g31pranjal added this pull request to stack #4634 September 17, 2026 22:44
@g31pranjal
g31pranjal removed this pull request from stack #4634 September 17, 2026 22:48
Adds `SyntheticRecordType.expand`, which turns a synthetic record type into the
graph that assembles its records, and implements it for `UnnestedRecordType`: a
select over the parent record's scan joined with one explode per nested
constituent, whose result columns are the constituents plus the `__positions`
field the synthetic primary key needs.

The explodes are created `WITH ORDINALITY`, because a stored position is exactly
the ordinal of the element within its owner's array, and there is no other way to
recover it. The ordinals only need widening from the `INT` the explode flows to
the `LONG` the `Positions` message declares -- the types have to agree, or the
record the expansion flows is not of the type's own planner type.

`RecordMetaData` gains `getPlannerTypeForRecordType(s)` overloads that take
already-resolved `RecordType`s. The existing name-based overloads resolve against
stored record types only, so they cannot describe a synthetic type, whereas
`recordTypesForIndex` hands back the type itself for an index defined on one.

This is groundwork: nothing calls `expand` yet. It is what lets a value index
defined on a synthetic type become a match candidate, so that a query performing
the same unnesting by hand can be answered from the index.
Covers the graph `UnnestedRecordType.expand` builds -- the parent scan, one
explode per nested constituent, the `__positions` record, chained constituents
and nullable-array wrappers -- and the record-type-taking planner type
overloads, including that they describe a synthetic type, which the name-taking
ones cannot.

Adds `test_records_nested_chain.proto` for the chained case. The existing
two-level proto, `test_records_double_nested.proto`, is deliberately recursive,
and the planner cannot build a type for a recursive descriptor, so a chain of
constituents needs a non-recursive record type to unnest.
@g31pranjal
g31pranjal changed the base branch from apple/g31pranjal/unnested/zero-based-ordinality to main September 18, 2026 15:06
@g31pranjal
g31pranjal force-pushed the apple/g31pranjal/unnested/synthetic-type-expand branch from 24551d6 to a74faf7 Compare September 18, 2026 15:12
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.

1 participant