Class RelStructuredTypeFlattener

java.lang.Object
org.apache.calcite.sql2rel.RelStructuredTypeFlattener
All Implemented Interfaces:
ReflectiveVisitor

public class RelStructuredTypeFlattener extends Object implements ReflectiveVisitor
RelStructuredTypeFlattener removes all structured types from a tree of relational expressions. Because it must operate globally on the tree, it is implemented as an explicit self-contained rewrite operation instead of via normal optimizer rules. This approach has the benefit that real optimizer and codegen rules never have to deal with structured types.

As an example, suppose we have a structured type ST(A1 smallint, A2 bigint), a table T(c1 ST, c2 double), and a query select t.c2, t.c1.a2 from t. After SqlToRelConverter executes, the unflattened tree looks like:


 LogicalProject(C2=[$1], A2=[$0.A2])
   LogicalTableScan(table=[T])
 

After flattening, the resulting tree looks like


 LogicalProject(C2=[$3], A2=[$2])
   FtrsIndexScanRel(table=[T], index=[clustered])
 

The index scan produces a flattened row type (boolean, smallint, bigint, double) (the boolean is a null indicator for c1), and the projection picks out the desired attributes (omitting $0 and $1 altogether). After optimization, the projection might be pushed down into the index scan, resulting in a final tree like


 FtrsIndexScanRel(table=[T], index=[clustered], projection=[3, 2])
 
  • Constructor Details

  • Method Details

    • updateRelInMap

      public void updateRelInMap(com.google.common.collect.SortedSetMultimap<RelNode,CorrelationId> mapRefRelToCorVar)
    • updateRelInMap

      public void updateRelInMap(SortedMap<CorrelationId,LogicalCorrelate> mapCorVarToCorRel)
    • rewrite

      public RelNode rewrite(RelNode root)
    • setNewForOldRel

      protected void setNewForOldRel(RelNode oldRel, RelNode newRel)
    • getNewForOldRel

      protected RelNode getNewForOldRel(RelNode oldRel)
    • getNewForOldInput

      protected int getNewForOldInput(int oldOrdinal)
      Maps the ordinal of a field pre-flattening to the ordinal of the corresponding field post-flattening.
      Parameters:
      oldOrdinal - Pre-flattening ordinal
      Returns:
      Post-flattening ordinal
    • getNewFieldForOldInput

      protected Ord<RelDataType> getNewFieldForOldInput(int oldOrdinal)
      Maps the ordinal of a field pre-flattening to the ordinal of the corresponding field post-flattening, and also returns its type.
      Parameters:
      oldOrdinal - Pre-flattening ordinal
      Returns:
      Post-flattening ordinal and type
    • rewriteRel

      public void rewriteRel(LogicalTableModify rel)
    • rewriteRel

      public void rewriteRel(LogicalAggregate rel)
    • rewriteRel

      public void rewriteRel(Sort rel)
    • rewriteRel

      public void rewriteRel(LogicalFilter rel)
    • rewriteRel

      public void rewriteRel(LogicalJoin rel)
    • rewriteRel

      public void rewriteRel(LogicalCorrelate rel)
    • rewriteRel

      public void rewriteRel(Collect rel)
    • rewriteRel

      public void rewriteRel(Uncollect rel)
    • rewriteRel

      public void rewriteRel(LogicalIntersect rel)
    • rewriteRel

      public void rewriteRel(LogicalMinus rel)
    • rewriteRel

      public void rewriteRel(LogicalUnion rel)
    • rewriteRel

      public void rewriteRel(LogicalRepeatUnion rel)
    • rewriteRel

      public void rewriteRel(LogicalTableSpool rel)
    • rewriteRel

      public void rewriteRel(LogicalValues rel)
    • rewriteRel

      public void rewriteRel(LogicalTableFunctionScan rel)
    • rewriteRel

      public void rewriteRel(Sample rel)
    • rewriteRel

      public void rewriteRel(LogicalProject rel)
    • rewriteRel

      public void rewriteRel(LogicalCalc rel)
    • rewriteRel

      public void rewriteRel(RelStructuredTypeFlattener.SelfFlatteningRel rel)
    • rewriteRel

      public void rewriteRel(LogicalExchange rel)
    • rewriteRel

      public void rewriteRel(LogicalSortExchange rel)
    • rewriteGeneric

      public void rewriteGeneric(RelNode rel)
    • rewriteRel

      public void rewriteRel(TableScan rel)
    • rewriteRel

      public void rewriteRel(LogicalSnapshot rel)
    • rewriteRel

      public void rewriteRel(LogicalDelta rel)
    • rewriteRel

      public void rewriteRel(LogicalChi rel)
    • rewriteRel

      public void rewriteRel(LogicalMatch rel)