|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.oj.rex.RexToOJTranslator
public class RexToOJTranslator
Converts expressions in logical format (RexNode
) into OpenJava code.
Nested Class Summary | |
---|---|
private static class |
RexToOJTranslator.WhichInputResult
Result of call to whichInput(int, org.eigenbase.rel.RelNode) , contains the
input relational expression, its index, and the index of the field within
that relational expression. |
Field Summary | |
---|---|
private RelNode |
contextRel
|
private JavaRelImplementor |
implementor
|
private OJRexImplementorTable |
implementorTable
|
private RexProgram |
program
Program which the expression is part of. |
private Stack<RexProgram> |
programStack
|
private StatementList[] |
stmtLists
Statement lists being built up for ROW or CASE expression. |
private Expression |
translatedExpr
|
Constructor Summary | |
---|---|
RexToOJTranslator(JavaRelImplementor implementor,
RelNode contextRel,
OJRexImplementorTable implementorTable)
Creates a translator. |
Method Summary | |
---|---|
boolean |
canConvertCall(RexCall call)
|
protected Expression |
convertByteArrayLiteral(byte[] bytes)
|
protected ArrayInitializer |
convertByteArrayLiteralToInitializer(byte[] bytes)
|
protected Expression |
convertCall(RexCall call,
Expression[] operandExprs)
Converts a call after its operands have already been translated. |
RelNode |
getContextRel()
|
protected OJRexImplementorTable |
getImplementorTable()
|
RexProgram |
getProgram()
Returns the current program. |
JavaRelImplementor |
getRelImplementor()
|
StatementList |
getSubStmtList(int i)
Returns the StatementList corresponding to a subexpression of a CASE or ROW expression. |
protected Expression |
getTranslation()
|
RelDataTypeFactory |
getTypeFactory()
|
protected boolean |
isInputRef(RexLocalRef localRef)
Tests whether a RexLocalRef refers to an input. |
void |
popProgram(RexProgram program)
Restores the current program to the one before pushProgram(RexProgram) was called. |
RexToOJTranslator |
push(StatementList stmtList)
Returns a sub-translator to deal with a sub-block. |
void |
pushProgram(RexProgram program)
Sets the current program. |
protected Expression |
setTranslation(Expression expr)
|
void |
translateAssignment(RelDataTypeField lhsField,
Expression lhs,
RexNode rhs)
Generates code for an assignment. |
private Expression |
translateInput(int index)
|
Expression |
translateRexNode(RexNode node)
Translates an expression into a Java expression. |
Expression |
translateSubExpression(RexLocalRef localRef)
Translates a common subexpression. |
Expression |
visitCall(RexCall call)
|
Expression |
visitCorrelVariable(RexCorrelVariable correlVariable)
|
Expression |
visitDynamicParam(RexDynamicParam dynamicParam)
|
Expression |
visitFieldAccess(RexFieldAccess fieldAccess)
|
Expression |
visitInputRef(RexInputRef inputRef)
|
Expression |
visitLiteral(RexLiteral literal)
|
Expression |
visitLocalRef(RexLocalRef localRef)
|
Expression |
visitOver(RexOver over)
|
Expression |
visitRangeRef(RexRangeRef rangeRef)
|
private static RexToOJTranslator.WhichInputResult |
whichInput(int fieldIndex,
RelNode rel)
Returns the ordinal of the input relational expression which a given column ordinal comes from. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final JavaRelImplementor implementor
private final RelNode contextRel
private final OJRexImplementorTable implementorTable
private Expression translatedExpr
private RexProgram program
private StatementList[] stmtLists
private final Stack<RexProgram> programStack
Constructor Detail |
---|
public RexToOJTranslator(JavaRelImplementor implementor, RelNode contextRel, OJRexImplementorTable implementorTable)
implementor
- implementation contextcontextRel
- relational expression which is the context for the
row-expressions which are to be translatedimplementorTable
- table of implementation functors for Rex
operators; if null, OJRexImplementorTableImpl.instance
is usedMethod Detail |
---|
public StatementList getSubStmtList(int i)
protected Expression setTranslation(Expression expr)
protected Expression getTranslation()
public RexProgram getProgram()
pushProgram(RexProgram)
,
popProgram(RexProgram)
protected OJRexImplementorTable getImplementorTable()
public JavaRelImplementor getRelImplementor()
public RelNode getContextRel()
public RelDataTypeFactory getTypeFactory()
public Expression visitLocalRef(RexLocalRef localRef)
visitLocalRef
in interface RexVisitor<Expression>
public Expression translateSubExpression(RexLocalRef localRef)
localRef
- common subexpression to be translated
protected boolean isInputRef(RexLocalRef localRef)
localRef
- reference to test
public Expression visitInputRef(RexInputRef inputRef)
visitInputRef
in interface RexVisitor<Expression>
private Expression translateInput(int index)
public Expression visitLiteral(RexLiteral literal)
visitLiteral
in interface RexVisitor<Expression>
public Expression visitCall(RexCall call)
visitCall
in interface RexVisitor<Expression>
protected Expression convertCall(RexCall call, Expression[] operandExprs)
call
- call to be translatedoperandExprs
- translated operands
public Expression visitOver(RexOver over)
visitOver
in interface RexVisitor<Expression>
public Expression visitCorrelVariable(RexCorrelVariable correlVariable)
visitCorrelVariable
in interface RexVisitor<Expression>
public Expression visitDynamicParam(RexDynamicParam dynamicParam)
visitDynamicParam
in interface RexVisitor<Expression>
public Expression visitRangeRef(RexRangeRef rangeRef)
visitRangeRef
in interface RexVisitor<Expression>
public Expression visitFieldAccess(RexFieldAccess fieldAccess)
visitFieldAccess
in interface RexVisitor<Expression>
public Expression translateRexNode(RexNode node)
pushProgram(RexProgram)
, the expression
is interpreted in terms of the output fields of the program.
Suppose that the program is
and the expression isexprs: {$0, $1, $0 + $1} projectRefs: {$0, $2} conditionRef: null
$1 + 5
. This would be expanded to
(a + b) + 5
, because output field $1 of the program is
defined to be the expression $0 + $1
in terms of the input
fields.
Sometimes a calculator expression is defined in terms of simpler
calculator expressions. If this is the case, those expressions will be
successively evaluated and assigned to variables. If a variable with the
appropriate value is already in scope, it will be used.
If the program is not present, no mapping occurs.
node
- Expression to be translated.
protected ArrayInitializer convertByteArrayLiteralToInitializer(byte[] bytes)
protected Expression convertByteArrayLiteral(byte[] bytes)
public boolean canConvertCall(RexCall call)
private static RexToOJTranslator.WhichInputResult whichInput(int fieldIndex, RelNode rel)
For example, if rel
has inputs I(a, b, c)
and J(d, e)
, then whichInput(0, rel)
returns 0
(column a), whichInput(2, rel)
returns 0 (column c),
whichInput(3, rel)
returns 1 (column d).
fieldIndex
- Index of fieldrel
- Relational expression
RexToOJTranslator.WhichInputResult
if found, otherwise null.public void translateAssignment(RelDataTypeField lhsField, Expression lhs, RexNode rhs)
NOTE: This method is only implemented in translators which can
generate sequences of statements. The default implementation of this
method throws UnsupportedOperationException
.
lhsField
- target fieldlhs
- target field as OpenJavarhs
- the source expression (as RexNode)public RexToOJTranslator push(StatementList stmtList)
The default implementation simply returns this translator. Other implementations may create a new translator which contains the expression-to-variable mappings of the sub-block.
stmtList
- Sub-block to generate code into
public void pushProgram(RexProgram program)
popProgram(org.eigenbase.rex.RexProgram)
is called. The program may be null.
program
- New current programpublic void popProgram(RexProgram program)
pushProgram(RexProgram)
was called.
program
- The program most recently pushed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |