|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.opt.RelImplementor
RelImplementor
deals with the nastiness of converting a tree
of relational expressions into an implementation, generally an openjava parse tree
.
The bind(net.sf.saffron.rel.SaffronRel, 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.
TODO jvs 29-Sept-2003: This class is way too Java-dependent to remain in opt. Most of it needs to be factored out to oj, leaving an interface or abstract base class behind. I intentionally left one macker failure unsuppressed so that this will get some attention.
Nested Class Summary | |
private static interface |
RelImplementor.Bind
|
private static class |
RelImplementor.EagerBind
|
private static class |
RelImplementor.Frame
|
private static class |
RelImplementor.LazyBind
|
private class |
RelImplementor.RelBind
Binds a relational expression to whatever another relational expression is currently bound to. |
private static class |
RelImplementor.Translator
Translator is a shuttle used to implement
translate(net.sf.saffron.rel.SaffronRel, net.sf.saffron.rex.RexNode) . |
static interface |
RelImplementor.VariableInitializerThunk
A VariableInitializerThunk yields a VariableInitializer . |
Field Summary | |
(package private) Statement |
exitStatement
|
(package private) HashMap |
mapCorrel2Frame
Map String --> Frame such that frame.rel.correlVariable == correlName |
(package private) HashMap |
mapCorrelNameToVariable
|
(package private) HashMap |
mapRel2Frame
|
(package private) RexBuilder |
rexBuilder
|
(package private) Stack |
stmtListStack
|
Constructor Summary | |
RelImplementor(RexBuilder rexBuilder)
|
Method Summary | |
private void |
bind(SaffronRel rel,
RelImplementor.Bind bind)
Record the fact that instances of rel are available via
bind (which may be eager or lazy). |
void |
bind(SaffronRel rel,
SaffronRel previous)
Shares a variable between relations. |
Variable |
bind(SaffronRel rel,
StatementList statementList,
VariableInitializer initializer)
Declare a variable, and bind it lazily, so it only gets initialized if it is actually used. |
void |
bind(SaffronRel rel,
Variable variable)
Record the fact that instances of rel are available in
variable . |
void |
bindCorrel(String correlName,
Variable variable)
Binds a correlating variable. |
private void |
bindDeferred(RelImplementor.Frame frame,
SaffronRel rel)
|
private int |
computeFieldOffset(SaffronRel rel,
int ordinal)
Returns the index of the first field in rel which comes
from its ordinal th input. |
private SaffronRel |
findInputRel(SaffronRel rel,
int offset)
|
private SaffronRel |
findInputRel(SaffronRel rel,
int offset,
int[] offsets)
|
(package private) Variable |
findInputVariable(SaffronRel rel)
Returns the variable which, in the generated program, will hold the current row of a given relational expression. |
SaffronRel |
findRel(SaffronRel rel,
RexNode expression)
|
void |
generateParentBody(SaffronRel rel,
StatementList stmtList)
Implements the body of the current expression's parent. |
Statement |
getExitStatement()
|
StatementList |
getStatementList()
|
Object |
implementChild(SaffronRel parent,
int ordinal,
SaffronRel child)
Implements a relational expression according to a calling convention. |
Object |
implementRoot(SaffronRel rel)
Starts an iteration, by calling SaffronRel.implement(net.sf.saffron.opt.RelImplementor, int) on the
root element. |
Expression |
makeReference(String correlName,
SaffronRel rel)
Creates an expression which references correlating variable correlName from the context of rel . |
Variable |
newVariable()
|
void |
popStatementList(StatementList stmtList)
|
void |
pushStatementList(StatementList stmtList)
|
void |
setExitStatement(Statement stmt)
|
Expression |
translate(SaffronRel rel,
RexNode 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
RelImplementor ). |
Expression |
translateInput(SaffronRel rel,
int ordinal)
Creates an expression which references the ordinalth input. |
Expression |
translateInputField(SaffronRel rel,
int ordinal,
int fieldOrdinal)
Creates an expression which references the fieldOrdinalth field of the ordinalth input. |
ExpressionList |
translateList(SaffronRel rel,
RexNode[] exps)
Converts an array of expressions in internal into a list of expressions in generated form. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
final HashMap mapCorrel2Frame
final HashMap mapCorrelNameToVariable
final HashMap mapRel2Frame
final Stack stmtListStack
Statement exitStatement
RexBuilder rexBuilder
Constructor Detail |
public RelImplementor(RexBuilder rexBuilder)
Method Detail |
public void setExitStatement(Statement stmt)
public Statement getExitStatement()
public StatementList getStatementList()
public void bind(SaffronRel rel, Variable variable)
rel
are available in
variable
.
public Variable bind(SaffronRel rel, StatementList statementList, VariableInitializer initializer)
public void bind(SaffronRel rel, SaffronRel previous)
previous
already has
a variable, and calling this method indicates that rel
's
output will appear in this variable too.
public void bindCorrel(String correlName, Variable variable)
$cor2
will be replaced with java variables such as
$Oj14
.
public SaffronRel findRel(SaffronRel rel, RexNode expression)
public void generateParentBody(SaffronRel 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 intoprivate void bindDeferred(RelImplementor.Frame frame, SaffronRel rel)
public Object implementChild(SaffronRel parent, int ordinal, SaffronRel child)
public Object implementRoot(SaffronRel rel)
SaffronRel.implement(net.sf.saffron.opt.RelImplementor, int)
on the
root element.
public Expression makeReference(String correlName, SaffronRel rel)
correlName
from the context of rel
. For
example, if correlName
is set by the 1st child of
rel
's 2nd child, then this method returns
$input2.$input1
.
public Variable newVariable()
public void popStatementList(StatementList stmtList)
public void pushStatementList(StatementList stmtList)
public Expression translate(SaffronRel rel, RexNode exp)
$input0
) to generated form
(the input relation is referenced using the bindings in this
RelImplementor
). 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 ExpressionList translateList(SaffronRel rel, RexNode[] exps)
translate(SaffronRel,RexNode)
public Expression translateInput(SaffronRel rel, int ordinal)
private int computeFieldOffset(SaffronRel rel, int ordinal)
rel
which comes
from its ordinal
th input.
For example, if rel joins T0(A,B,C) to T1(D,E), then countFields(0,rel) yields 0, and countFields(1,rel) yields 3.
public Expression translateInputField(SaffronRel rel, int ordinal, int fieldOrdinal)
(We can potentially optimize the generation process, so we can access field values without actually instantiating the row.)
private void bind(SaffronRel rel, RelImplementor.Bind bind)
rel
are available via
bind
(which may be eager or lazy).
private SaffronRel findInputRel(SaffronRel rel, int offset)
private SaffronRel findInputRel(SaffronRel rel, int offset, int[] offsets)
Variable findInputVariable(SaffronRel rel)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |