public class RelStructuredTypeFlattener extends Object implements ReflectiveVisitor
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])
| Modifier and Type | Class and Description |
|---|---|
private class |
RelStructuredTypeFlattener.RewriteRelVisitor
Visitor that flattens each relational expression in a tree.
|
private class |
RelStructuredTypeFlattener.RewriteRexShuttle
Shuttle that rewrites scalar expressions.
|
static interface |
RelStructuredTypeFlattener.SelfFlatteningRel
Mix-in interface for relational expressions that know how to
flatten themselves.
|
| Modifier and Type | Field and Description |
|---|---|
private RelNode |
currentRel |
private RelDataType |
flattenedRootType |
private int |
iRestructureInput |
private Map<RelNode,RelNode> |
oldToNewRelMap |
private boolean |
restructure |
(package private) boolean |
restructured |
private RexBuilder |
rexBuilder |
private RelOptTable.ToRelContext |
toRelContext |
| Constructor and Description |
|---|
RelStructuredTypeFlattener(RexBuilder rexBuilder,
RelOptTable.ToRelContext toRelContext,
boolean restructure) |
private final RexBuilder rexBuilder
private final boolean restructure
private RelNode currentRel
private int iRestructureInput
private RelDataType flattenedRootType
boolean restructured
private final RelOptTable.ToRelContext toRelContext
public RelStructuredTypeFlattener(RexBuilder rexBuilder, RelOptTable.ToRelContext toRelContext, boolean restructure)
public void updateRelInMap(com.google.common.collect.SortedSetMultimap<RelNode,CorrelationId> mapRefRelToCorVar)
public void updateRelInMap(SortedMap<CorrelationId,LogicalCorrelate> mapCorVarToCorRel)
private List<RexNode> restructureFields(RelDataType structuredType)
private RexNode restructure(RelDataType structuredType)
protected int getNewForOldInput(int oldOrdinal)
oldOrdinal - Pre-flattening ordinalprivate Mappings.TargetMapping getNewForOldInputMapping(RelNode oldRel)
oldRel - Old relational expressionprivate int calculateFlattenedOffset(RelDataType rowType, int ordinal)
public void rewriteRel(LogicalTableModify rel)
public void rewriteRel(LogicalAggregate rel)
public void rewriteRel(Sort rel)
public void rewriteRel(LogicalFilter rel)
public void rewriteRel(LogicalJoin rel)
public void rewriteRel(LogicalCorrelate rel)
public void rewriteRel(Collect rel)
public void rewriteRel(Uncollect rel)
public void rewriteRel(LogicalIntersect rel)
public void rewriteRel(LogicalMinus rel)
public void rewriteRel(LogicalUnion rel)
public void rewriteRel(LogicalValues rel)
public void rewriteRel(LogicalTableFunctionScan rel)
public void rewriteRel(Sample rel)
public void rewriteRel(LogicalProject rel)
public void rewriteRel(LogicalCalc rel)
public void rewriteRel(RelStructuredTypeFlattener.SelfFlatteningRel rel)
public void rewriteGeneric(RelNode rel)
private void flattenProjections(RelStructuredTypeFlattener.RewriteRexShuttle shuttle, List<? extends RexNode> exps, List<String> fieldNames, String prefix, List<Pair<RexNode,String>> flattenedExps)
private void flattenProjection(RelStructuredTypeFlattener.RewriteRexShuttle shuttle, RexNode exp, String fieldName, List<Pair<RexNode,String>> flattenedExps)
private void flattenNullLiteral(RelDataType type, List<Pair<RexNode,String>> flattenedExps)
private boolean isConstructor(RexNode rexNode)
public void rewriteRel(TableScan rel)
public void rewriteRel(LogicalDelta rel)
public void rewriteRel(LogicalChi rel)
public void rewriteRel(LogicalMatch rel)
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.