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])