saffron.opt
Class Implementor

java.lang.Object
  |
  +--saffron.opt.Implementor

public class Implementor
extends Object

Implementor deals with the nastiness of converting a tree of relational expressions into an implementation, generally an openjava parse tree.

The bind(saffron.rel.Rel, openjava.ptree.Variable) method allows relational expressions to register which Java variable holds their row. They can bind 'lazily', so that the variable is only declared and initialized if it is actually used in another expression.


Nested Class Summary
private static interface Implementor.Bind
           
private static class Implementor.EagerBind
           
private static class Implementor.Frame
           
private static class Implementor.LazyBind
           
private static class Implementor.Translator
          Translator is a shuttle used to implement translate(Rel,Expression).
static interface Implementor.VariableInitializerThunk
          A VariableInitializerThunk yields a VariableInitializer.
 
Field Summary
(package private)  Statement exitStatement
           
(package private)  Hashtable mapCorel2Frame
          Map String --> Frame such that frame.rel.corelVariable == corelName
(package private)  Hashtable mapCorelNameToVariable
           
(package private)  Hashtable mapRel2Frame
           
(package private)  Stack stmtListStack
           
 
Constructor Summary
Implementor()
           
 
Method Summary
private  void bind(Rel rel, Implementor.Bind bind)
          Record the fact that instances of rel are available via bind (which may be eager or lazy).
 void bind(Rel rel, Rel previous)
          Shares a variable between relations.
private  Variable bind(Rel rel, StatementList statementList, Type type, Implementor.VariableInitializerThunk thunk)
           
 Variable bind(Rel rel, StatementList statementList, VariableInitializer initializer)
          Declare a variable, and bind it lazily, so it only gets initialized if it is actually used.
 void bind(Rel rel, Variable variable)
          Record the fact that instances of rel are available in variable.
 void bindCorel(String corelName, Variable variable)
          Binds a correlating variable.
 Variable bindDeferred(Rel rel, StatementList statementList)
          A relational expression calls this method to declare that its initializer can be generated by calling its Rel.implementSelf(saffron.opt.Implementor) method.
private  Expression findExp(Rel rel, Expression expression)
          Creates an expression with which to implement "expression" from the context of "rel".
private  Rel findInputRel(Rel rel, int offset)
           
private  Rel findInputRel(Rel rel, int offset, int[] offsets)
           
private  Variable findInputVariable(Rel rel)
           
 Rel findRel(Rel rel, Expression expression)
           
 void generateParentBody(Rel rel, StatementList stmtList)
          Implements the body of the current expression's parent.
 Statement getExitStatement()
           
 StatementList getStatementList()
           
 Object implementChild(Rel parent, int ordinal, Rel child)
          Implements a relational expression according to a calling convention.
 Object implementRoot(Rel rel)
          Starts an iteration, by calling Rel.implement(saffron.opt.Implementor, int) on the root element.
 Expression makeReference(String corelName, Rel rel)
          Creates an expression which references correlating variable corelName from the context of rel.
 Variable newVariable()
           
 void popStatementList(StatementList stmtList)
           
 void pushStatementList(StatementList stmtList)
           
 void setExitStatement(Statement stmt)
           
 Expression translate(Rel rel, Expression exp)
          Converts an expression in internal form (the input relation is referenced using the variable $input0) to generated form (the input relation is referenced using the bindings in this Implementor).
 Expression translateInput(Rel rel, int ordinal)
          Creates an expression which references the ordinalth input.
 Expression translateInputField(Rel rel, int ordinal, int fieldOrdinal)
          Creates an expression which references the fieldOrdinalth field of the ordinalth input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapRel2Frame

Hashtable mapRel2Frame

mapCorel2Frame

Hashtable mapCorel2Frame
Map String --> Frame such that frame.rel.corelVariable == corelName


stmtListStack

Stack stmtListStack

exitStatement

Statement exitStatement

mapCorelNameToVariable

Hashtable mapCorelNameToVariable
Constructor Detail

Implementor

public Implementor()
Method Detail

newVariable

public Variable newVariable()

implementRoot

public Object implementRoot(Rel rel)
Starts an iteration, by calling Rel.implement(saffron.opt.Implementor, int) on the root element.


implementChild

public Object implementChild(Rel parent,
                             int ordinal,
                             Rel child)
Implements a relational expression according to a calling convention.


generateParentBody

public void generateParentBody(Rel rel,
                               StatementList stmtList)
Implements the body of the current expression's parent. If variable is not null, bind the current expression to variable. For example, a nested loops join would generate
 for (int i = 0; i < emps.length; i++) {
   Emp emp = emps[i];
   for (int j = 0; j < depts.length; j++) {
     Dept dept = depts[j];
     if (emp.deptno == dept.deptno) {
       <>
     }
   }
 }
 
which corresponds to
 [emp:iter
   [dept:iter
     [join:body(emp,dept)
       [parent:body]
     ]
   ]
 ]
 

Parameters:
rel - child relation
stmtList - block that child was generating its code into

setExitStatement

public void setExitStatement(Statement stmt)

getExitStatement

public Statement getExitStatement()

bind

public void bind(Rel rel,
                 Variable variable)
Record the fact that instances of rel are available in variable.


bind

private void bind(Rel rel,
                  Implementor.Bind bind)
Record the fact that instances of rel are available via bind (which may be eager or lazy).


bind

public Variable bind(Rel rel,
                     StatementList statementList,
                     VariableInitializer initializer)
Declare a variable, and bind it lazily, so it only gets initialized if it is actually used.


bind

private Variable bind(Rel rel,
                      StatementList statementList,
                      Type type,
                      Implementor.VariableInitializerThunk thunk)

bindDeferred

public Variable bindDeferred(Rel rel,
                             StatementList statementList)
A relational expression calls this method to declare that its initializer can be generated by calling its Rel.implementSelf(saffron.opt.Implementor) method.

Why this devious indirection? The advantage occurs if no one ever wants to reference this relational expression's row; then we spare the effort of computing a value which no one will use.


bind

public void bind(Rel rel,
                 Rel previous)
Shares a variable between relations. previous already has a variable, and calling this method indicates that rel's output will appear in this variable too.


bindCorel

public void bindCorel(String corelName,
                      Variable variable)
Binds a correlating variable. References to correlating variables such as $corel2 will be replaced with java variables such as $Oj14.


translate

public Expression translate(Rel rel,
                            Expression exp)
Converts an expression in internal form (the input relation is referenced using the variable $input0) to generated form (the input relation is referenced using the bindings in this Implementor). Compare this method with QueryInfo.convertExpToInternal(openjava.ptree.Expression), which converts from source form to internal form.

Parameters:
exp - the expression to translate (it is cloned, not modified)
rel - the relational expression which is the context for exp

translateInput

public Expression translateInput(Rel rel,
                                 int ordinal)
Creates an expression which references the ordinalth input.


translateInputField

public Expression translateInputField(Rel rel,
                                      int ordinal,
                                      int fieldOrdinal)
Creates an expression which references the fieldOrdinalth field of the ordinalth input.

(We can potentially optimize the generation process, so we can access field values without actually instantiating the row.)


makeReference

public Expression makeReference(String corelName,
                                Rel rel)
Creates an expression which references correlating variable corelName from the context of rel. For example, if corelName is set by the 1st child of rel's 2nd child, then this method returns $input2.$input1.


findExp

private Expression findExp(Rel rel,
                           Expression expression)
Creates an expression with which to implement "expression" from the context of "rel". If "expression" is a field-access referencing an input relation, it goes directly to that relation.


findRel

public Rel findRel(Rel rel,
                   Expression expression)

findInputRel

private Rel findInputRel(Rel rel,
                         int offset)

findInputRel

private Rel findInputRel(Rel rel,
                         int offset,
                         int[] offsets)

findInputVariable

private Variable findInputVariable(Rel rel)

pushStatementList

public void pushStatementList(StatementList stmtList)

popStatementList

public void popStatementList(StatementList stmtList)

getStatementList

public StatementList getStatementList()

SourceForge.net_Logo