org.eigenbase.rel
Class CalcRel

java.lang.Object
  extended by org.eigenbase.rel.AbstractRelNode
      extended by org.eigenbase.rel.SingleRel
          extended by org.eigenbase.rel.CalcRelBase
              extended by org.eigenbase.rel.CalcRel
All Implemented Interfaces:
Cloneable, RelNode

public final class CalcRel
extends CalcRelBase

A relational expression which computes project expressions and also filters.

This relational expression combines the functionality of ProjectRel and FilterRel. It should be created in the latter stages of optimization, by merging consecutive ProjectRel and FilterRel nodes together.

The following rules relate to CalcRel:

Since:
Mar 7, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/rel/CalcRel.java#25 $
Author:
jhyde

Field Summary
static boolean DeprecateProjectAndFilter
           
 
Fields inherited from class org.eigenbase.rel.CalcRelBase
program
 
Fields inherited from class org.eigenbase.rel.AbstractRelNode
digest, id, nextId, rowType, traits
 
Fields inherited from interface org.eigenbase.rel.RelNode
emptyArray
 
Constructor Summary
CalcRel(RelOptCluster cluster, RelTraitSet traits, RelNode child, RelDataType rowType, RexProgram program, List<RelCollation> collationList)
           
 
Method Summary
 CalcRel clone()
          Clones this RelNode.
 void collectVariablesUsed(Set<String> variableSet)
          Collects variables known to be used by this expression or its descendants.
static RelNode createFilter(RelNode child, RexNode condition)
          Creates a relational expression which filters according to a given condition, returning the same fields as its input.
static RelNode createProject(RelNode child, List<Integer> posList)
           
static RelNode createProject(RelNode child, List<RexNode> exprList, List<String> fieldNameList)
          Creates a relational expression which projects an array of expressions.
static RelNode createProject(RelNode child, List<RexNode> exprList, List<String> fieldNameList, boolean optimize)
          Creates a relational expression which projects an array of expressions, and optionally optimizes.
static ProjectRel createProject(RelNode child, RexNode[] exprs, String[] fieldNames)
          Creates a relational expression which projects a set of expressions.
static RelNode createProject(RelNode child, RexNode[] exprs, String[] fieldNames, boolean optimize)
          Creates a relational expression which projects a set of expressions.
static RelNode createRename(RelNode rel, String[] fieldNames)
          Returns a relational expression which has the same fields as the underlying expression, but the fields have different names.
static RelNode permute(RelNode rel, Permutation permutation, List<String> fieldNames)
          Creates a relational expression which permutes the output fields of a relational expression according to a permutation.
static RelNode projectMapping(RelNode rel, Mapping mapping, List<String> fieldNames)
          Creates a relational expression which projects the output fields of a relational expression according to a partial mapping.
 
Methods inherited from class org.eigenbase.rel.CalcRelBase
computeSelfCost, explain, getChildExps, getCollationList, getProgram, getRows, isValid
 
Methods inherited from class org.eigenbase.rel.SingleRel
childrenAccept, deriveRowType, getChild, getInputs, replaceInput
 
Methods inherited from class org.eigenbase.rel.AbstractRelNode
cloneTraits, collectVariablesSet, computeDigest, getCluster, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRowType, getTable, getTraits, getVariablesStopped, inheritTraitsFrom, isAccessTo, isDistinct, onRegister, recomputeDigest, register, registerCorrelVariable, setCorrelVariable, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DeprecateProjectAndFilter

public static final boolean DeprecateProjectAndFilter
See Also:
Constant Field Values
Constructor Detail

CalcRel

public CalcRel(RelOptCluster cluster,
               RelTraitSet traits,
               RelNode child,
               RelDataType rowType,
               RexProgram program,
               List<RelCollation> collationList)
Method Detail

clone

public CalcRel clone()
Description copied from interface: RelNode
Clones this RelNode.

Traits of the RelNode must be explicitly cloned, using AbstractRelNode.inheritTraitsFrom(AbstractRelNode), as the RelNode may have traits of which it has no knowledge. Example implementation:

     public MyRelNode clone()
     {
         MyRelNode clone = new MyRelNode(...);
         clone.inheritTraitsFrom(this);
         return clone;
     }
 
N.B.: This method must be overridden whenever an existing, concrete RelNode is extended. Otherwise, calling clone() will produce a differently typed RelNode, resulting in invalid or incorrect query plans.

Specified by:
clone in interface RelNode
Specified by:
clone in class AbstractRelNode
Returns:
a clone of this RelNode

createProject

public static RelNode createProject(RelNode child,
                                    List<RexNode> exprList,
                                    List<String> fieldNameList)
Creates a relational expression which projects an array of expressions.

Parameters:
child - input relational expression
exprList - list of expressions for the input columns
fieldNameList - aliases of the expressions, or null to generate

createProject

public static RelNode createProject(RelNode child,
                                    List<RexNode> exprList,
                                    List<String> fieldNameList,
                                    boolean optimize)
Creates a relational expression which projects an array of expressions, and optionally optimizes.

Parameters:
child - input relational expression
exprList - list of expressions for the input columns
fieldNameList - aliases of the expressions, or null to generate
optimize - Whether to return child unchanged if the projections are trivial.

createProject

public static ProjectRel createProject(RelNode child,
                                       RexNode[] exprs,
                                       String[] fieldNames)
Creates a relational expression which projects a set of expressions.

Parameters:
child - input relational expression
exprs - set of expressions for the input columns
fieldNames - aliases of the expressions, or null to generate

createProject

public static RelNode createProject(RelNode child,
                                    List<Integer> posList)

createProject

public static RelNode createProject(RelNode child,
                                    RexNode[] exprs,
                                    String[] fieldNames,
                                    boolean optimize)
Creates a relational expression which projects a set of expressions.

The result may not be a ProjectRel. If the projection is trivial, child is returned directly; and future versions may return other forumlations of expressions, such as CalcRel.

Parameters:
child - input relational expression
exprs - set of expressions for the input columns
fieldNames - aliases of the expressions, or null to generate
optimize - Whether to return child unchanged if the projections are trivial.

createFilter

public static RelNode createFilter(RelNode child,
                                   RexNode condition)
Creates a relational expression which filters according to a given condition, returning the same fields as its input.

Parameters:
child - Child relational expression
condition - Condition
Returns:
Relational expression

createRename

public static RelNode createRename(RelNode rel,
                                   String[] fieldNames)
Returns a relational expression which has the same fields as the underlying expression, but the fields have different names.

Parameters:
rel - Relational expression
fieldNames - Field names
Returns:
Renamed relational expression

collectVariablesUsed

public void collectVariablesUsed(Set<String> variableSet)
Description copied from interface: RelNode
Collects variables known to be used by this expression or its descendants. By default, no such information is available and must be derived by analyzing sub-expressions, but some optimizer implementations may insert special expressions which remember such information.

Specified by:
collectVariablesUsed in interface RelNode
Overrides:
collectVariablesUsed in class AbstractRelNode
Parameters:
variableSet - receives variables used

permute

public static RelNode permute(RelNode rel,
                              Permutation permutation,
                              List<String> fieldNames)
Creates a relational expression which permutes the output fields of a relational expression according to a permutation.

Optimizations:

If a permutation is combined with its inverse, these optimizations would combine to remove them both.

Parameters:
rel -
permutation -
fieldNames - Field names; if null, or if a particular entry is null, the name of the permuted field is used
Returns:
relational expression which permutes its input fields

projectMapping

public static RelNode projectMapping(RelNode rel,
                                     Mapping mapping,
                                     List<String> fieldNames)
Creates a relational expression which projects the output fields of a relational expression according to a partial mapping.

A partial mapping is weaker than a permutation: every target has one source, but a source may have 0, 1 or more than one targets. Usually the result will have fewer fields than the source, unless some source fields are projected multiple times.

This method could optimize the result as permute(org.eigenbase.rel.RelNode, org.eigenbase.util.Permutation, java.util.List) does, but does not at present.

Parameters:
rel - Relational expression
mapping - Mapping from source fields to target fields. The mapping type must obey the constaints MappingType.isMandatorySource() and MappingType.isSingleSource(), as does MappingType.InverseFunction.
fieldNames - Field names; if null, or if a particular entry is null, the name of the permuted field is used
Returns:
relational expression which projects a subset of the input fields