org.eigenbase.rel
Class JoinRelBase

java.lang.Object
  extended by org.eigenbase.rel.AbstractRelNode
      extended by org.eigenbase.rel.JoinRelBase
All Implemented Interfaces:
Cloneable, RelNode
Direct Known Subclasses:
CorrelatorRel, JoinRel, MedMdrJoinRel, SemiJoinRel

public abstract class JoinRelBase
extends AbstractRelNode

JoinRelBase is an abstract base class for implementations of JoinRel.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/rel/JoinRelBase.java#23 $
Author:
John V. Sichi

Field Summary
protected  RexNode condition
           
protected  JoinRelType joinType
          Values must be of enumeration JoinRelType, except that JoinRelType.RIGHT is disallowed.
protected  RelNode left
           
protected  RelNode right
           
protected  Set<String> variablesStopped
           
 
Fields inherited from class org.eigenbase.rel.AbstractRelNode
digest, id, nextId, rowType, traits
 
Fields inherited from interface org.eigenbase.rel.RelNode
emptyArray
 
Constructor Summary
protected JoinRelBase(RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, RexNode condition, JoinRelType joinType, Set<String> variablesStopped)
          Creates a JoinRelBase.
 
Method Summary
 boolean _isValid(boolean fail)
           
private static void addFields(List<RelDataTypeField> fieldList, List<RelDataType> typeList, List<String> nameList, HashSet<String> uniqueNameList)
           
 void childrenAccept(RelVisitor visitor)
          Interacts with the RelVisitor in a visitor pattern to traverse the tree of relational expressions.
 RelOptCost computeSelfCost(RelOptPlanner planner)
          Returns the cost of this plan (not including children).
static RelDataType createJoinType(RelDataTypeFactory typeFactory, RelDataType leftType, RelDataType rightType, List<String> fieldNameList, List<RelDataTypeField> systemFieldList)
          Returns the type the row which results when two relations are joined.
static RelDataType deriveJoinRowType(RelDataType leftType, RelDataType rightType, JoinRelType joinType, RelDataTypeFactory typeFactory, List<String> fieldNameList, List<RelDataTypeField> systemFieldList)
          Derives the type of a join relational expression.
protected  RelDataType deriveRowType()
           
static double estimateJoinedRows(JoinRelBase joinRel, RexNode condition)
           
 void explain(RelOptPlanWriter pw)
           
 RexNode[] getChildExps()
          Returns an array of this relational expression's child expressions (not including the inputs returned by RelNode.getInputs().
 RexNode getCondition()
           
 RelNode[] getInputs()
          Returns an array of this relational expression's inputs.
 JoinRelType getJoinType()
           
 RelNode getLeft()
           
 RelNode getRight()
           
 double getRows()
          Returns an estimate of the number of rows this relational expression will return.
 List<RelDataTypeField> getSystemFieldList()
          Returns a list of system fields that will be prefixed to output row type.
 Set<String> getVariablesStopped()
          Returns the names of variables which are set in this relational expression but also used and therefore not available to parents of this relational expression.
 void registerStoppedVariable(String name)
           
 void replaceInput(int ordinalInParent, RelNode p)
          Replaces the ordinalInParentth input.
 void setVariablesStopped(Set<String> set)
           
 
Methods inherited from class org.eigenbase.rel.AbstractRelNode
clone, cloneTraits, collectVariablesSet, collectVariablesUsed, computeDigest, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRowType, getTable, getTraits, inheritTraitsFrom, isAccessTo, isDistinct, isValid, onRegister, recomputeDigest, register, registerCorrelVariable, setCorrelVariable, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

condition

protected RexNode condition

left

protected RelNode left

right

protected RelNode right

variablesStopped

protected Set<String> variablesStopped

joinType

protected JoinRelType joinType
Values must be of enumeration JoinRelType, except that JoinRelType.RIGHT is disallowed.

Constructor Detail

JoinRelBase

protected JoinRelBase(RelOptCluster cluster,
                      RelTraitSet traits,
                      RelNode left,
                      RelNode right,
                      RexNode condition,
                      JoinRelType joinType,
                      Set<String> variablesStopped)
Creates a JoinRelBase.

Parameters:
cluster - Cluster
traits - Traits
left - Left input
right - Right input
condition - Join condition
joinType - Join type
variablesStopped - Set of names of variables which are set by the LHS and used by the RHS and are not available to nodes above this JoinRel in the tree
Method Detail

getChildExps

public RexNode[] getChildExps()
Description copied from interface: RelNode
Returns an array of this relational expression's child expressions (not including the inputs returned by RelNode.getInputs(). If there are no child expressions, returns an empty array, not null.

Specified by:
getChildExps in interface RelNode
Overrides:
getChildExps in class AbstractRelNode

getCondition

public RexNode getCondition()

getInputs

public RelNode[] getInputs()
Description copied from interface: RelNode
Returns an array of this relational expression's inputs. If there are no inputs, returns an empty array, not null.

Specified by:
getInputs in interface RelNode
Overrides:
getInputs in class AbstractRelNode

getJoinType

public JoinRelType getJoinType()

getLeft

public RelNode getLeft()

getRight

public RelNode getRight()

_isValid

public boolean _isValid(boolean fail)

computeSelfCost

public RelOptCost computeSelfCost(RelOptPlanner planner)
Description copied from interface: RelNode
Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getNonCumulativeCost(org.eigenbase.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.

Specified by:
computeSelfCost in interface RelNode
Overrides:
computeSelfCost in class AbstractRelNode

estimateJoinedRows

public static double estimateJoinedRows(JoinRelBase joinRel,
                                        RexNode condition)

getRows

public double getRows()
Description copied from interface: RelNode
Returns an estimate of the number of rows this relational expression will return.

NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getRowCount(org.eigenbase.rel.RelNode), which gives plugins a chance to override the rel's default ideas about row count.

Specified by:
getRows in interface RelNode
Overrides:
getRows in class AbstractRelNode

setVariablesStopped

public void setVariablesStopped(Set<String> set)

getVariablesStopped

public Set<String> getVariablesStopped()
Description copied from interface: RelNode
Returns the names of variables which are set in this relational expression but also used and therefore not available to parents of this relational expression.

By default, returns the empty set. Derived classes may override this method.

Specified by:
getVariablesStopped in interface RelNode
Overrides:
getVariablesStopped in class AbstractRelNode

childrenAccept

public void childrenAccept(RelVisitor visitor)
Description copied from interface: RelNode
Interacts with the RelVisitor in a visitor pattern to traverse the tree of relational expressions.

Specified by:
childrenAccept in interface RelNode
Overrides:
childrenAccept in class AbstractRelNode

explain

public void explain(RelOptPlanWriter pw)
Specified by:
explain in interface RelNode
Overrides:
explain in class AbstractRelNode

registerStoppedVariable

public void registerStoppedVariable(String name)

replaceInput

public void replaceInput(int ordinalInParent,
                         RelNode p)
Description copied from interface: RelNode
Replaces the ordinalInParentth input. You must override this method if you override RelNode.getInputs().

Specified by:
replaceInput in interface RelNode
Overrides:
replaceInput in class AbstractRelNode

deriveRowType

protected RelDataType deriveRowType()
Overrides:
deriveRowType in class AbstractRelNode

getSystemFieldList

public List<RelDataTypeField> getSystemFieldList()
Returns a list of system fields that will be prefixed to output row type.

Returns:
list of system fields

deriveJoinRowType

public static RelDataType deriveJoinRowType(RelDataType leftType,
                                            RelDataType rightType,
                                            JoinRelType joinType,
                                            RelDataTypeFactory typeFactory,
                                            List<String> fieldNameList,
                                            List<RelDataTypeField> systemFieldList)
Derives the type of a join relational expression.

Parameters:
leftType - Row type of left input to join
rightType - Row type of right input to join
joinType - Type of join
typeFactory - Type factory
fieldNameList - List of names of fields; if null, field names are inherited and made unique
systemFieldList - List of system fields that will be prefixed to output row type; typically empty but must not be null
Returns:
join type

createJoinType

public static RelDataType createJoinType(RelDataTypeFactory typeFactory,
                                         RelDataType leftType,
                                         RelDataType rightType,
                                         List<String> fieldNameList,
                                         List<RelDataTypeField> systemFieldList)
Returns the type the row which results when two relations are joined.

The resulting row type consists of the system fields (if any), followed by the fields of the left type, followed by the fields of the right type. The field name list, if present, overrides the original names of the fields.

Parameters:
typeFactory - Type factory
leftType - Type of left input to join
rightType - Type of right input to join
fieldNameList - If not null, overrides the original names of the fields
systemFieldList - List of system fields that will be prefixed to output row type; typically empty but must not be null
Returns:
type of row which results when two relations are joined
"Precondition:"
fieldNameList == null || fieldNameList.size() == systemFieldList.size() + leftType.getFieldCount() + rightType.getFieldCount()

addFields

private static void addFields(List<RelDataTypeField> fieldList,
                              List<RelDataType> typeList,
                              List<String> nameList,
                              HashSet<String> uniqueNameList)