net.sf.farrago.query
Class FennelToIteratorConverter

java.lang.Object
  extended by org.eigenbase.rel.AbstractRelNode
      extended by org.eigenbase.rel.SingleRel
          extended by org.eigenbase.rel.convert.ConverterRelImpl
              extended by net.sf.farrago.query.FennelToIteratorConverter
All Implemented Interfaces:
Cloneable, JavaRel, ConverterRel, RelNode

public class FennelToIteratorConverter
extends ConverterRelImpl
implements JavaRel, ConverterRel

FennelToIteratorConverter is a Converter from the Fennel calling convention to the iterator calling convention.

Every FennelToIteratorConverter exists in one of two locations. Location 1 means the converter is one of N roots of a sequence of JavaRels that are read by FarragoResultSetIterator or FarragoResultSetTupleIter. Location 2 means the converter is one of the N roots of a sequence of JavaRels that are converted back to Fennel convention by an IteratorToFennelConverter. These locations are handled differently:

  1. When in location 1, it generates Iterator convention code that reads from its child FennelRel, blocking when the FennelRel has no data. (This is identical to the behavior for old-style iterators.)
  2. When in location 2, it generates Iterator convention code that reads from its child FennelRel, but returns TupleIter.NoDataReason.UNDERFLOW when the FennelRel has no data. In addition, the generated code is not encapsulated in a method and returned to the caller of implement(JavaRelImplementor). Instead it's registered with the FarragoRelImplementor for later compilation. In addition, the stream def generated for child FennelRels is stored for later use by IteratorToFennelConverter.
REVIEW: SWZ 3/7/2006: It would be nice if this could be split into two converters. One for Location 1 and another for Location 2. This would simplify the code and make it easier to understand. Not sure if the planner can handle two converters from Fennel to Iterator that need to be used under different circumstances, though.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/query/FennelToIteratorConverter.java#42 $
Author:
John V. Sichi

Field Summary
static ConverterRule Rule
          The singleton rule which uses a FennelToIteratorConverter to convert a RelNode from FennelRel.FENNEL_EXEC_CONVENTION convention to CallingConvention.ITERATOR convention.
 
Fields inherited from class org.eigenbase.rel.convert.ConverterRelImpl
inTraits, traitDef
 
Fields inherited from class org.eigenbase.rel.AbstractRelNode
digest, id, rowType, traits
 
Fields inherited from interface org.eigenbase.rel.RelNode
emptyArray
 
Fields inherited from interface org.eigenbase.rel.RelNode
emptyArray
 
Constructor Summary
FennelToIteratorConverter(RelOptCluster cluster, RelNode child)
          Creates a new FennelToIteratorConverter object.
 
Method Summary
protected  FemExecutionStreamDef childToStreamDef(FennelRelImplementor implementor)
          Converts the child relational expression (which is in Fennel convention) into a FemExecutionStreamDef.
 FennelToIteratorConverter clone()
          Clones this RelNode.
 ParseTree implement(JavaRelImplementor implementor)
          Creates a plan for this expression according to a calling convention.
protected  boolean isTransformerInput(JavaRelImplementor implementor)
          Determines whether this FennelToIteratorConverter is an input to a FarragoTransform.
static void register(RelOptPlanner planner)
          Registers this relational expression and rule(s) with the planner, as per AbstractRelNode.register(org.eigenbase.relopt.RelOptPlanner).
protected  void registerChildWithAncestor(JavaRelImplementor implementor, FemExecutionStreamDef streamDef, boolean implicit)
           
 
Methods inherited from class org.eigenbase.rel.convert.ConverterRelImpl
cannotImplement, computeSelfCost, convertTraits, getInputConvention, getInputTraits, getTraitDef, isDistinct
 
Methods inherited from class org.eigenbase.rel.SingleRel
childrenAccept, deriveRowType, explain, getChild, getInputs, getRows, replaceInput
 
Methods inherited from class org.eigenbase.rel.AbstractRelNode
cloneTraits, collectVariablesSet, collectVariablesUsed, computeDigest, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRowType, getTable, getTraits, getVariablesStopped, inheritTraitsFrom, isAccessTo, isValid, onRegister, recomputeDigest, registerCorrelVariable, setCorrelVariable, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eigenbase.rel.RelNode
childrenAccept, collectVariablesSet, collectVariablesUsed, computeSelfCost, explain, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRows, getRowType, getTable, getTraits, getVariablesStopped, isAccessTo, isDistinct, isValid, onRegister, recomputeDigest, registerCorrelVariable, replaceInput, setCorrelVariable
 
Methods inherited from interface org.eigenbase.rel.convert.ConverterRel
getChild, getInputTraits, getTraitDef
 
Methods inherited from interface org.eigenbase.rel.RelNode
childrenAccept, collectVariablesSet, collectVariablesUsed, computeSelfCost, explain, getChildExps, getCluster, getCollationList, getConvention, getCorrelVariable, getDescription, getDigest, getExpectedInputRowType, getId, getInput, getInputs, getOrCreateCorrelVariable, getQuery, getRelTypeName, getRows, getRowType, getTable, getTraits, getVariablesStopped, isAccessTo, isDistinct, isValid, onRegister, recomputeDigest, registerCorrelVariable, replaceInput, setCorrelVariable
 

Field Detail

Rule

public static final ConverterRule Rule
The singleton rule which uses a FennelToIteratorConverter to convert a RelNode from FennelRel.FENNEL_EXEC_CONVENTION convention to CallingConvention.ITERATOR convention.

Constructor Detail

FennelToIteratorConverter

public FennelToIteratorConverter(RelOptCluster cluster,
                                 RelNode child)
Creates a new FennelToIteratorConverter object.

Parameters:
cluster - RelOptCluster for this rel
child - input rel producing rows in Fennel TupleStream representation
Method Detail

clone

public FennelToIteratorConverter 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

implement

public ParseTree implement(JavaRelImplementor implementor)
Description copied from interface: JavaRel
Creates a plan for this expression according to a calling convention.

Specified by:
implement in interface JavaRel
Parameters:
implementor - implementor

childToStreamDef

protected FemExecutionStreamDef childToStreamDef(FennelRelImplementor implementor)
Converts the child relational expression (which is in Fennel convention) into a FemExecutionStreamDef.

Derived classes may override this method.

Parameters:
implementor - Context for the implementation process
Returns:
stream definition

isTransformerInput

protected boolean isTransformerInput(JavaRelImplementor implementor)
Determines whether this FennelToIteratorConverter is an input to a FarragoTransform. In other words, is one of the ancestors to this rel an IteratorToFennelConverter (without an intervening FarragoJavaUdxRel).

Parameters:
implementor - implementor in use
Returns:
true if this rel is an input to a FarragoTransform, false otherwise

registerChildWithAncestor

protected final void registerChildWithAncestor(JavaRelImplementor implementor,
                                               FemExecutionStreamDef streamDef,
                                               boolean implicit)

register

public static void register(RelOptPlanner planner)
Registers this relational expression and rule(s) with the planner, as per AbstractRelNode.register(org.eigenbase.relopt.RelOptPlanner).

Parameters:
planner - Planner