net.sf.farrago.query
Class FarragoRelImplementor

java.lang.Object
  extended by org.eigenbase.oj.rel.JavaRelImplementor
      extended by net.sf.farrago.query.FarragoRelImplementor
All Implemented Interfaces:
FarragoOJRexRelImplementor, FennelRelImplementor, RelImplementor

public class FarragoRelImplementor
extends JavaRelImplementor
implements FennelRelImplementor, FarragoOJRexRelImplementor

FarragoRelImplementor refines JavaRelImplementor with some Farrago specifics.

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

Nested Class Summary
static class FarragoRelImplementor.RelPathEntry
          RelPathEntry keeps track of a RelNode and its input position within that node's parent RelNode in the execution stream graph.
private static class FarragoRelImplementor.RelScope
           
private static class FarragoRelImplementor.UdfAwareOJRexImplementorTable
          An operator implementor table which knows about UDF's.
 
Nested classes/interfaces inherited from class org.eigenbase.oj.rel.JavaRelImplementor
JavaRelImplementor.TranslationTester, JavaRelImplementor.VariableInitializerThunk
 
Field Summary
private  List<FarragoRelImplementor.RelPathEntry> currRelPathList
           
private  int nextDynamicParamId
           
private  long nextRelParamId
           
private  int nextTransformId
           
(package private)  OJClass ojAssignableValue
           
(package private)  OJClass ojBytePointer
           
(package private)  FarragoPreparingStmt preparingStmt
           
private  Map<List<FarragoRelImplementor.RelPathEntry>,FarragoRelImplementor.RelScope> relPathScopeMap
           
private  Map<RelNode,List<FarragoRelImplementor.RelPathEntry>> relToFirstRelPathEntryMap
           
private  Map<RelNode,List<FemExecutionStreamDef>> relToStreamDefMap
           
private  String serverMofId
           
private  Set<FemExecutionStreamDef> streamDefSet
           
private static Logger tracer
           
private  List<FarragoTransformDef> transformDefs
           
private  Map<String,FarragoTransformDef> transformMap
           
private  List<FemJavaTransformStreamDef> transformStreamDefs
           
 
Fields inherited from class org.eigenbase.oj.rel.JavaRelImplementor
implementorTable
 
Constructor Summary
FarragoRelImplementor(FarragoPreparingStmt preparingStmt, RexBuilder rexBuilder)
           
 
Method Summary
 void addDataFlowFromProducerToConsumer(FemExecutionStreamDef producer, FemExecutionStreamDef consumer)
          Adds a new explicit dataflow edge between two existing stream definitions.
 void addDataFlowFromProducerToConsumer(FemExecutionStreamDef producer, FemExecutionStreamDef consumer, boolean implicit)
          Adds a new dataflow edge between two existing stream definitions.
protected  void addRelPathEntry(RelNode rel, int ordinal)
          Adds a RelPathEntry corresponding to a new RelNode to the current RelPathEntry list
 void addTransform(RelNode rel, ClassDeclaration decl)
           
 FennelRelParamId allocateRelParamId()
          Reserves a Fennel dynamic parameter.
 int allocateTransform()
           
 void compileTransforms(String pkgName)
           
protected  FemTupleDescriptor computeStreamDefOutputDesc(RelDataType rowType)
           
private  void finishTransforms()
           
 Variable getConnectionVariable()
           
 FarragoPreparingStmt getPreparingStmt()
           
 List<FemExecutionStreamDef> getRegisteredStreamDefs(RelNode rel)
          Returns the list of stream definitions that have been registered for a RelNode.
 List<FarragoRelImplementor.RelPathEntry> getRelPathEntry()
           
 FarragoRepos getRepos()
          Returns the repository.
 String getServerMofId()
           
 Set<FemExecutionStreamDef> getStreamDefSet()
           
 String getStreamGlobalName(FemExecutionStreamDef streamDef, RelNode rel)
          Constructs a globally unique name for an execution stream.
 List<FarragoTransformDef> getTransforms()
           
 Expression implementRoot(JavaRel rel)
          Starts an iteration, by calling JavaRel.implement(org.eigenbase.oj.rel.JavaRelImplementor) on the root element.
 boolean isFirstTranslationInstance(RelNode rel)
          Determines if this is the instance of a RelNode such that the instance corresponds to the one at the time this method was first called.
 RexToOJTranslator newStmtTranslator(JavaRel rel, StatementList stmtList, MemberDeclarationList memberList)
          Creates a translator which can translate a succession of expressions, possibly using multiple statements, scratch variables, and helper functions.
protected  RexToOJTranslator newTranslator(RelNode rel)
          Creates a RexToOJTranslator with which to translate the row-expressions within a relational expression into OpenJava expressions.
private  String printTransformMap()
           
private  String printTransforms()
           
 void registerRelStreamDef(FemExecutionStreamDef streamDef, RelNode rel, RelDataType rowType)
          Registers a new stream definition.
private  void registerStreamDef(FemExecutionStreamDef streamDef, RelNode rel, RelDataType rowType)
           
protected  void removeRelPathEntry()
          Removes the RelPathEntry corresponding to the current RelNode being visited from the current RelPathEntry list
 void setErrorRecordType(FennelRel rel, FemExecutionStreamDef streamDef, RelDataType errorType)
          Sets the format of error records for an execution stream.
 void setServerMofId(String serverMofId)
          Sets the MOFID of the foreign server associated with the expression being implemented.
protected  FemExecutionStreamDef toStreamDefImpl(FennelRel rel, int ordinal)
          Converts a FennelRel to a FemExecutionStreamDef, and prints context if anything goes wrong.
 FennelDynamicParamId translateParamId(FennelRelParamId relParamId)
          Translates a FennelRelParamId into a FennelDynamicParamId based on the current scope.
 FennelDynamicParamId translateParamId(FennelRelParamId relParamId, FemExecutionStreamDef streamDef, FennelDynamicParamId.StreamType streamType)
          Translates a FennelRelParamId into a FennelDynamicParamId based on the current scope.
 Object visitChildInternal(RelNode child, int ordinal)
          Override method to deal with the possibility that we are being called from a FennelRel via our FennelRelImplementor interface.
 FemExecutionStreamDef visitFennelChild(FennelRel rel, int ordinal)
          Converts a relational expression into a plan by calling its FennelRel.toStreamDef(net.sf.farrago.query.FennelRelImplementor) method.
 
Methods inherited from class org.eigenbase.oj.rel.JavaRelImplementor
bind, bind, bind, bindCorrel, canTranslate, canTranslate, createFrame, findInputVariable, findRel, generateParentBody, generateVariableId, getAncestorRels, getExitStatement, getRexBuilder, getStatementList, getTypeFactory, implementFieldAccess, implementNext, implementResult, implementStart, implementStartAndNext, makeReference, newVariable, newVariable, popStatementList, pushStatementList, setExitStatement, translate, translateInput, translateInputField, translateList, translateViaStatements, visitChild, visitChildInternal, visitJavaChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.relopt.RelImplementor
visitChild, visitChildInternal
 

Field Detail

tracer

private static final Logger tracer

preparingStmt

FarragoPreparingStmt preparingStmt

ojAssignableValue

OJClass ojAssignableValue

ojBytePointer

OJClass ojBytePointer

streamDefSet

private Set<FemExecutionStreamDef> streamDefSet

serverMofId

private String serverMofId

nextRelParamId

private long nextRelParamId

nextDynamicParamId

private int nextDynamicParamId

currRelPathList

private List<FarragoRelImplementor.RelPathEntry> currRelPathList

relPathScopeMap

private Map<List<FarragoRelImplementor.RelPathEntry>,FarragoRelImplementor.RelScope> relPathScopeMap

transformDefs

private List<FarragoTransformDef> transformDefs

transformStreamDefs

private List<FemJavaTransformStreamDef> transformStreamDefs

transformMap

private Map<String,FarragoTransformDef> transformMap

nextTransformId

private int nextTransformId

relToStreamDefMap

private Map<RelNode,List<FemExecutionStreamDef>> relToStreamDefMap

relToFirstRelPathEntryMap

private Map<RelNode,List<FarragoRelImplementor.RelPathEntry>> relToFirstRelPathEntryMap
Constructor Detail

FarragoRelImplementor

public FarragoRelImplementor(FarragoPreparingStmt preparingStmt,
                             RexBuilder rexBuilder)
Method Detail

setServerMofId

public void setServerMofId(String serverMofId)
Sets the MOFID of the foreign server associated with the expression being implemented.

Parameters:
serverMofId - MOFID to set, or null to clear

getServerMofId

public String getServerMofId()
Specified by:
getServerMofId in interface FarragoOJRexRelImplementor
Returns:
MOFID of the foreign server associated with the expression being implemented

getRepos

public FarragoRepos getRepos()
Description copied from interface: FennelRelImplementor
Returns the repository.

Specified by:
getRepos in interface FennelRelImplementor

allocateRelParamId

public FennelRelParamId allocateRelParamId()
Description copied from interface: FennelRelImplementor
Reserves a Fennel dynamic parameter. The reserving rel can use FennelRelImplementor.translateParamId(FennelRelParamId) later as part of its toStreamDef implementation to convert this into a final FennelDynamicParamId, which can then be referenced from stream definitions.

Specified by:
allocateRelParamId in interface FennelRelImplementor
Returns:
parameter reservation ID

translateParamId

public FennelDynamicParamId translateParamId(FennelRelParamId relParamId)
Description copied from interface: FennelRelImplementor
Translates a FennelRelParamId into a FennelDynamicParamId based on the current scope.

Specified by:
translateParamId in interface FennelRelImplementor
Parameters:
relParamId - reserved ID to be translated
Returns:
physical ID to use in final plan

translateParamId

public FennelDynamicParamId translateParamId(FennelRelParamId relParamId,
                                             FemExecutionStreamDef streamDef,
                                             FennelDynamicParamId.StreamType streamType)
Description copied from interface: FennelRelImplementor
Translates a FennelRelParamId into a FennelDynamicParamId based on the current scope.

Specified by:
translateParamId in interface FennelRelImplementor
Parameters:
relParamId - reserved ID to be translated
streamDef - the stream that either produces or consumes the dynamic parameter; or null if we don't need to keep track of that information
streamType - whether the streamDef produces or consumes the dynamic parameter
Returns:
physical ID to use in final plan

setErrorRecordType

public void setErrorRecordType(FennelRel rel,
                               FemExecutionStreamDef streamDef,
                               RelDataType errorType)
Description copied from interface: FennelRelImplementor
Sets the format of error records for an execution stream.

Specified by:
setErrorRecordType in interface FennelRelImplementor
Parameters:
rel - relation to which the execution stream belongs
streamDef - stream definition of stream that may produce errors
errorType - row type of error records produced by the stream

visitFennelChild

public FemExecutionStreamDef visitFennelChild(FennelRel rel,
                                              int ordinal)
Description copied from interface: FennelRelImplementor
Converts a relational expression into a plan by calling its FennelRel.toStreamDef(net.sf.farrago.query.FennelRelImplementor) method.

Specified by:
visitFennelChild in interface FennelRelImplementor
Parameters:
rel - the relational expression
ordinal - input position of the relational expression for its parent

getRelPathEntry

public List<FarragoRelImplementor.RelPathEntry> getRelPathEntry()

addRelPathEntry

protected void addRelPathEntry(RelNode rel,
                               int ordinal)
Adds a RelPathEntry corresponding to a new RelNode to the current RelPathEntry list

Parameters:
rel - the new RelNode
ordinal - the input position of the RelNode

removeRelPathEntry

protected void removeRelPathEntry()
Removes the RelPathEntry corresponding to the current RelNode being visited from the current RelPathEntry list


toStreamDefImpl

protected final FemExecutionStreamDef toStreamDefImpl(FennelRel rel,
                                                      int ordinal)
Converts a FennelRel to a FemExecutionStreamDef, and prints context if anything goes wrong.

This method is final: derived classes should not add extra functionality.

Parameters:
rel - Relational expression
ordinal - input position of the relational expression for its parent
Returns:
Plan

visitChildInternal

public Object visitChildInternal(RelNode child,
                                 int ordinal)
Override method to deal with the possibility that we are being called from a FennelRel via our FennelRelImplementor interface.

Specified by:
visitChildInternal in interface RelImplementor
Overrides:
visitChildInternal in class JavaRelImplementor
Parameters:
child - Child relational expression
ordinal - Ordinal of child within its parent
Returns:
Interpretation of the return value is left to the implementor

getStreamDefSet

public Set<FemExecutionStreamDef> getStreamDefSet()

getTransforms

public List<FarragoTransformDef> getTransforms()

addTransform

public void addTransform(RelNode rel,
                         ClassDeclaration decl)

allocateTransform

public int allocateTransform()

compileTransforms

public void compileTransforms(String pkgName)

finishTransforms

private void finishTransforms()

printTransforms

private String printTransforms()

printTransformMap

private String printTransformMap()

getPreparingStmt

public FarragoPreparingStmt getPreparingStmt()

registerRelStreamDef

public void registerRelStreamDef(FemExecutionStreamDef streamDef,
                                 RelNode rel,
                                 RelDataType rowType)
Description copied from interface: FennelRelImplementor
Registers a new stream definition. Normally, it is not necessary to call this method explicitly; it happens automatically as part of FennelRelImplementor.visitFennelChild(net.sf.farrago.query.FennelRel, int). However, this is not true for non-tree stream graphs. For streams with multiple parents, this method must be called for streams not returned from FennelRelImplementor.visitFennelChild(net.sf.farrago.query.FennelRel, int).

Specified by:
registerRelStreamDef in interface FennelRelImplementor
Parameters:
streamDef - new stream definition
rel - RelNode which stream implements
rowType - row type for stream, or null to use rel's row type

addDataFlowFromProducerToConsumer

public void addDataFlowFromProducerToConsumer(FemExecutionStreamDef producer,
                                              FemExecutionStreamDef consumer)
Description copied from interface: FennelRelImplementor
Adds a new explicit dataflow edge between two existing stream definitions. See the three-arg version for details.

NOTE jvs 14-Nov-2005: I gave this method a long name so that it wouldn't be necessary to guess the direction when reading code that uses it.

Specified by:
addDataFlowFromProducerToConsumer in interface FennelRelImplementor
Parameters:
producer - the upstream node of the dataflow
consumer - the downstream node of the dataflow

addDataFlowFromProducerToConsumer

public void addDataFlowFromProducerToConsumer(FemExecutionStreamDef producer,
                                              FemExecutionStreamDef consumer,
                                              boolean implicit)
Description copied from interface: FennelRelImplementor
Adds a new dataflow edge between two existing stream definitions. In cases where a stream has multiple inputs or outputs, order may be significant, in which case it is the caller's responsibility to add the flows in the desired order.

Specified by:
addDataFlowFromProducerToConsumer in interface FennelRelImplementor
Parameters:
producer - the upstream node of the dataflow
consumer - the downstream node of the dataflow
implicit - false if this is an explicit dataflow edge between two ExecStreams; true if it represents implicit dataflow via a UDX reading from a cursor

computeStreamDefOutputDesc

protected FemTupleDescriptor computeStreamDefOutputDesc(RelDataType rowType)

registerStreamDef

private void registerStreamDef(FemExecutionStreamDef streamDef,
                               RelNode rel,
                               RelDataType rowType)

getRegisteredStreamDefs

public List<FemExecutionStreamDef> getRegisteredStreamDefs(RelNode rel)
Description copied from interface: FennelRelImplementor
Returns the list of stream definitions that have been registered for a RelNode.

Specified by:
getRegisteredStreamDefs in interface FennelRelImplementor
Parameters:
rel - the RelNode
Returns:
the list of registered stream definitions; null if no stream definitions have been registered yet to the RelNode

isFirstTranslationInstance

public boolean isFirstTranslationInstance(RelNode rel)
Description copied from interface: FennelRelImplementor
Determines if this is the instance of a RelNode such that the instance corresponds to the one at the time this method was first called.

Specified by:
isFirstTranslationInstance in interface FennelRelImplementor
Parameters:
rel - the RelNode
Returns:
true if the RelNode instance is the one encountered the first time this method was called

getStreamGlobalName

public String getStreamGlobalName(FemExecutionStreamDef streamDef,
                                  RelNode rel)
Constructs a globally unique name for an execution stream. This name is used to label and find C++ ExecStreams.

Parameters:
streamDef - stream definition
rel - rel which generated stream definition, or null if none
Returns:
global name for stream

getConnectionVariable

public Variable getConnectionVariable()
Overrides:
getConnectionVariable in class JavaRelImplementor

newTranslator

protected RexToOJTranslator newTranslator(RelNode rel)
Description copied from class: JavaRelImplementor
Creates a RexToOJTranslator with which to translate the row-expressions within a relational expression into OpenJava expressions.

Overrides:
newTranslator in class JavaRelImplementor

newStmtTranslator

public RexToOJTranslator newStmtTranslator(JavaRel rel,
                                           StatementList stmtList,
                                           MemberDeclarationList memberList)
Description copied from class: JavaRelImplementor
Creates a translator which can translate a succession of expressions, possibly using multiple statements, scratch variables, and helper functions.

Typical usage:

 Translator translator = newStmtTranslator(rel, stmtList, memberList);
 translator.translateRexNode(exp1);
 translator.translateRexNode(exp2);
 

Overrides:
newStmtTranslator in class JavaRelImplementor
Parameters:
rel - the relational expression which is the context for exp
stmtList - optional code can be appended here
memberList - optional member declarations can be appended here (if needed for reusable scratch space or helper functions; local variables

implementRoot

public Expression implementRoot(JavaRel rel)
Description copied from class: JavaRelImplementor
Starts an iteration, by calling JavaRel.implement(org.eigenbase.oj.rel.JavaRelImplementor) on the root element.

Overrides:
implementRoot in class JavaRelImplementor