Class ImplementTableFunctionSource
java.lang.Object
io.trino.sql.planner.iterative.rule.ImplementTableFunctionSource
- All Implemented Interfaces:
Rule<TableFunctionNode>
This rule prepares cartesian product of partitions
from all inputs of table function.
It rewrites TableFunctionNode with potentially many sources into a TableFunctionProcessorNode. The new node has one source being a combination of the original sources.
The original sources are combined with joins. The join conditions depend on the prune when empty property, and on the co-partitioning of sources.
The resulting source should be partitioned and ordered according to combined schemas from the component sources.
Example transformation for two sources, both with set semantics and KEEP WHEN EMPTY property:
- TableFunction foo
- source T1(a1, b1) PARTITION BY a1 ORDER BY b1
- source T2(a2, b2) PARTITION BY a2
Is transformed into:
- TableFunctionProcessor foo
PARTITION BY (a1, a2), ORDER BY combined_row_number
- Project
marker_1 <= IF(table1_row_number = combined_row_number, table1_row_number, CAST(null AS bigint))
marker_2 <= IF(table2_row_number = combined_row_number, table2_row_number, CAST(null AS bigint))
- Project
combined_row_number <= IF(COALESCE(table1_row_number, BIGINT '-1') > COALESCE(table2_row_number, BIGINT '-1'), table1_row_number, table2_row_number)
combined_partition_size <= IF(COALESCE(table1_partition_size, BIGINT '-1') > COALESCE(table2_partition_size, BIGINT '-1'), table1_partition_size, table2_partition_size)
- FULL Join
[table1_row_number = table2_row_number OR
table1_row_number > table2_partition_size AND table2_row_number = BIGINT '1' OR
table2_row_number > table1_partition_size AND table1_row_number = BIGINT '1']
- Window [PARTITION BY a1 ORDER BY b1]
table1_row_number <= row_number()
table1_partition_size <= count()
- source T1(a1, b1)
- Window [PARTITION BY a2]
table2_row_number <= row_number()
table2_partition_size <= count()
- source T2(a2, b2)
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.trino.sql.planner.iterative.Rule
Rule.Context, Rule.Result -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(TableFunctionNode node, Captures captures, Rule.Context context) Returns a pattern to which plan nodes this rule applies.
-
Constructor Details
-
ImplementTableFunctionSource
-
-
Method Details
-
getPattern
Description copied from interface:RuleReturns a pattern to which plan nodes this rule applies.- Specified by:
getPatternin interfaceRule<TableFunctionNode>
-
apply
- Specified by:
applyin interfaceRule<TableFunctionNode>
-