Package org.apache.calcite.sql2rel
Class RelStructuredTypeFlattener
java.lang.Object
org.apache.calcite.sql2rel.RelStructuredTypeFlattener
- All Implemented Interfaces:
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])
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Mix-in interface for relational expressions that know how to flatten themselves. -
Constructor Summary
ConstructorDescriptionRelStructuredTypeFlattener
(RexBuilder rexBuilder, RelOptTable.ToRelContext toRelContext, boolean restructure) Deprecated.RelStructuredTypeFlattener
(RelBuilder relBuilder, RexBuilder rexBuilder, RelOptTable.ToRelContext toRelContext, boolean restructure) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.protected int
getNewForOldInput
(int oldOrdinal) Maps the ordinal of a field pre-flattening to the ordinal of the corresponding field post-flattening.protected RelNode
getNewForOldRel
(RelNode oldRel) void
rewriteGeneric
(RelNode rel) void
rewriteRel
(Collect rel) void
rewriteRel
(Sample rel) void
rewriteRel
(Sort rel) void
rewriteRel
(TableScan rel) void
rewriteRel
(Uncollect rel) void
void
void
rewriteRel
(LogicalCalc rel) void
void
void
rewriteRel
(LogicalFilter rel) void
void
rewriteRel
(LogicalJoin rel) void
rewriteRel
(LogicalMatch rel) void
rewriteRel
(LogicalMinus rel) void
rewriteRel
(LogicalProject rel) void
void
void
void
void
void
void
rewriteRel
(LogicalUnion rel) void
rewriteRel
(LogicalValues rel) void
rewriteRel
(LogicalChi rel) void
rewriteRel
(LogicalDelta rel) void
protected void
setNewForOldRel
(RelNode oldRel, RelNode newRel) void
updateRelInMap
(com.google.common.collect.SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) void
updateRelInMap
(SortedMap<CorrelationId, LogicalCorrelate> mapCorVarToCorRel)
-
Constructor Details
-
RelStructuredTypeFlattener
@Deprecated public RelStructuredTypeFlattener(RexBuilder rexBuilder, RelOptTable.ToRelContext toRelContext, boolean restructure) Deprecated. -
RelStructuredTypeFlattener
public RelStructuredTypeFlattener(RelBuilder relBuilder, RexBuilder rexBuilder, RelOptTable.ToRelContext toRelContext, boolean restructure)
-
-
Method Details
-
updateRelInMap
public void updateRelInMap(com.google.common.collect.SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) -
updateRelInMap
-
rewrite
-
setNewForOldRel
-
getNewForOldRel
-
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
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
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteGeneric
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-
rewriteRel
-