|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--saffron.opt.Implementor
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 |
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 |
Hashtable mapRel2Frame
Hashtable mapCorel2Frame
Stack stmtListStack
Statement exitStatement
Hashtable mapCorelNameToVariable
Constructor Detail |
public Implementor()
Method Detail |
public Variable newVariable()
public Object implementRoot(Rel rel)
Rel.implement(saffron.opt.Implementor, int)
on the
root element.
public Object implementChild(Rel parent, int ordinal, Rel child)
public void generateParentBody(Rel rel, StatementList stmtList)
variable
is not null, bind the current expression to
variable
.
For example, a nested loops join would generate
which corresponds tofor (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) { <> } } }
[emp:iter [dept:iter [join:body(emp,dept) [parent:body] ] ] ]
rel
- child relationstmtList
- block that child was generating its code intopublic void setExitStatement(Statement stmt)
public Statement getExitStatement()
public void bind(Rel rel, Variable variable)
rel
are available in
variable
.
private void bind(Rel rel, Implementor.Bind bind)
rel
are available via
bind
(which may be eager or lazy).
public Variable bind(Rel rel, StatementList statementList, VariableInitializer initializer)
private Variable bind(Rel rel, StatementList statementList, Type type, Implementor.VariableInitializerThunk thunk)
public Variable bindDeferred(Rel rel, StatementList statementList)
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.
public void bind(Rel rel, Rel previous)
previous
already has
a variable, and calling this method indicates that rel
's
output will appear in this variable too.
public void bindCorel(String corelName, Variable variable)
$corel2
will be replaced with java variables such as
$Oj14
.
public Expression translate(Rel rel, Expression exp)
$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.
exp
- the expression to translate (it is cloned, not modified)rel
- the relational expression which is the context for
exp
public Expression translateInput(Rel rel, int ordinal)
public Expression translateInputField(Rel rel, int ordinal, int fieldOrdinal)
(We can potentially optimize the generation process, so we can access field values without actually instantiating the row.)
public Expression makeReference(String corelName, Rel rel)
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
.
private Expression findExp(Rel rel, Expression expression)
public Rel findRel(Rel rel, Expression expression)
private Rel findInputRel(Rel rel, int offset)
private Rel findInputRel(Rel rel, int offset, int[] offsets)
private Variable findInputVariable(Rel rel)
public void pushStatementList(StatementList stmtList)
public void popStatementList(StatementList stmtList)
public StatementList getStatementList()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |