Class ImplementTableFunctionSource

java.lang.Object
io.trino.sql.planner.iterative.rule.ImplementTableFunctionSource
All Implemented Interfaces:
Rule<TableFunctionNode>

public class ImplementTableFunctionSource extends Object implements 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 invalid input: '<'= IF(table1_row_number = combined_row_number, table1_row_number, CAST(null AS bigint))
          marker_2 invalid input: '<'= IF(table2_row_number = combined_row_number, table2_row_number, CAST(null AS bigint))
          - Project
              combined_row_number invalid input: '<'= IF(COALESCE(table1_row_number, BIGINT '-1') > COALESCE(table2_row_number, BIGINT '-1'), table1_row_number, table2_row_number)
              combined_partition_size invalid input: '<'= 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 invalid input: '<'= row_number()
                      table1_partition_size invalid input: '<'= count()
                          - source T1(a1, b1)
                  - Window [PARTITION BY a2]
                      table2_row_number invalid input: '<'= row_number()
                      table2_partition_size invalid input: '<'= count()
                          - source T2(a2, b2)