Repository navigation
feat: SQL UNION over project and filter. - #20593
Merged
Merged
Conversation
This patch adds the ability for SQL UNION to run over relations that
involve projections and filters of base tables, such as:
SELECT dim1, SUM(m1), COUNT(*)
FROM (SELECT dim1, m1 FROM foo2 WHERE dim1 = '1'
UNION ALL
SELECT dim1, m1 FROM foo)
GROUP BY 1;
Such queries are planned into stacks of the existing "filter" datasource
and the new "project" datasource.
Other changes, outside the SQL planner:
1) DataSource method "createSegmentPruner" has DimFilter and
VirtualColumns added as parameters. This enables DataSource
implementations, such as FilteredDataSource and ProjectDataSource,
to rewrite the filter and contribute additional virtual columns to
the pruning logic. ExecutionVertex#isBaseColumn is removed and more
scenarios are now pruneable.
2) DataSource gets "getReservedColumns" with a set of column names to
avoid when generating higher-level virtual columns. This is used
by the SQL planner to avoid name collisions.
3) DataSource gets "mayFilterRows", which allows time-boundary queries
to properly recognize that filtering DataSources should go down the
"query has filter" path.
4) Fix an issue where various CursorHolder implementations return
lists from "getOrdering" that erroneously include base columns
which were shadowed by virtual columns.
5) Updates to MSQ to call the new ExecutionVertex#splitUnion and
splitUnionSegmentMapFunctions methods to provide each arm with its
own SegmentPruner and SegmentMapFunction.
| new LookupDataSource("lookyloo"), | ||
| "j0.", | ||
| equalsCondition( | ||
| makeColumnExpression("x0"), |
| "j0.", | ||
| equalsCondition( | ||
| makeColumnExpression("x0"), | ||
| makeColumnExpression("j0.k") |
| ), | ||
| new LookupDataSource("lookyloo"), | ||
| "j0.", | ||
| equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.k")), |
| ), | ||
| new LookupDataSource("lookyloo"), | ||
| "j0.", | ||
| equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.k")), |
clintropolis
approved these changes
Oct 15, 2026
Comment on lines
+149
to
+150
| plannerContext.setPlanningError("SQL requires union between inputs that are not simple table scans " | ||
| + "and involve more than a filter or a projection."); |
Member
There was a problem hiding this comment.
nit: this error message reads a bit off
clintropolis
approved these changes
Oct 15, 2026
This was referenced Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch adds the ability for SQL UNION to run over relations that involve projections and filters of base tables, such as:
Such queries are planned into stacks of the existing "filter" datasource and the new "project" datasource.
Other changes, outside the SQL planner:
DataSource method "createSegmentPruner" has DimFilter and
VirtualColumns added as parameters. This enables DataSource
implementations, such as FilteredDataSource and ProjectDataSource,
to rewrite the filter and contribute additional virtual columns to
the pruning logic. ExecutionVertex#isBaseColumn is removed and more
scenarios are now pruneable.
DataSource gets "getReservedColumns" with a set of column names to
avoid when generating higher-level virtual columns. This is used
by the SQL planner to avoid name collisions.
DataSource gets "mayFilterRows", which allows time-boundary queries
to properly recognize that filtering DataSources should go down the
"query has filter" path.
Fix an issue where various CursorHolder implementations return
lists from "getOrdering" that erroneously include base columns
which were shadowed by virtual columns.
Updates to MSQ to call the new ExecutionVertex#splitUnion and
splitUnionSegmentMapFunctions methods to provide each arm with its
own SegmentPruner and SegmentMapFunction.