|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--saffron.rel.Rel | +--saffron.rel.ExpressionReader
An ExpressionReader
is a relational expression node which
evaluates an expression and returns the results as a relation. Cases:
T[]
, the each result row is
of type T
.Map
or derives from
Hashtable
, each result row contains fields {Object
key; Object value;}
.Iterator
or derives from
Enumeration
, each result row is an Object
.NOTE: We support Hashtable
, Enumeration
and Vector
explicitly because
Map
, Iterator
and Map
does not exist until JDK 1.2.
Example accessing an array:
Emp[] emps; Emp[] males = (select from emps as emp where emp.gender.equals("M"));
The following example shows how you can cast the values returned from a
Hashtable
:
Hashtable nameToDeptno = new Hashtable(); nameToDeptno.put("Fred", new Integer(20)); nameToDeptno.put("Eric", new Integer(10)); nameToDeptno.put("Bill", new Integer(10)); for (i in (select {(String) key, ((Integer) value).intValue() as value} from nameToDeptno)) { print(i.key + " is in dept " + i.value); }
Here we access a value in a Hashtable
by key:
Because the Hashtable is being accessed via its key, the optimizer will probably optimize this code toObject fredDeptno = (select value from nameToDeptno where key.equals("Fred");
nameToDeptno.get("Fred")
.
Nested Class Summary |
Nested classes inherited from class saffron.rel.Rel |
|
Field Summary | |
protected CallingConvention |
convention
|
private boolean |
distinct
Whether the rows are distinct; set by deriveRowType() . |
protected Expression |
exp
|
Fields inherited from class saffron.rel.Rel |
cluster, digest, emptyArray, id, nextId, rowType |
Constructor Summary | |
ExpressionReader(Cluster cluster,
Expression exp,
Type rowType)
Creates an ExpressionReader . |
Method Summary | |
private CallingConvention |
chooseConvention(Expression exp)
|
Object |
clone()
|
Cost |
computeSelfCost(Planner planner)
Returns the cost of this plan (not including children). |
protected Type |
deriveRowType()
|
void |
explain(PlanWriter pw)
|
Expression[] |
getChildExps()
Returns an array of this Rel 's child expressions (not
including the inputs returned by Rel.getInputs() . |
CallingConvention |
getConvention()
Returns a value from CallingConvention . |
Expression |
getExp()
|
Object |
implement(Implementor implementor,
int ordinal)
Create a plan for this expression according to a calling convention. |
boolean |
isDistinct()
Returns whether the same value will not come out twice. |
private static boolean |
isDistinct(ArrayAllocationExpression arrayAlloc)
Returns true if the array allocation expression consists of distinct literals, false otherwise. |
static boolean |
isRelational(OJClass clazz)
Returns whether an expression clazz can be read as a
relation. |
Methods inherited from class saffron.rel.Rel |
childrenAccept, computeDigest, getCluster, getCorelVariable, getEnvironment, getId, getInput, getInputs, getOrCreateCorelVariable, getParentEnv, getQualifier, getQuery, getRelTypeName, getRows, getRowType, getTable, getType, getVariablesStopped, implementExp, implementExps, implementFieldAccess, implementSelf, isAccessTo, onRegister, recomputeDigest, register, registerCorelVariable, replaceInput, setCorelVariable, toString |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Expression exp
protected CallingConvention convention
private boolean distinct
deriveRowType()
.
Constructor Detail |
public ExpressionReader(Cluster cluster, Expression exp, Type rowType)
ExpressionReader
.
cluster
- Cluster
this relational expression belongs toexp
- expression to evaluaterowType
- row type of the expression; if null, the row type is
deduced from the expression (for example, the row type
of a Iterator
is Object
.Method Detail |
public Expression getExp()
private CallingConvention chooseConvention(Expression exp)
public Object clone()
clone
in class Rel
public CallingConvention getConvention()
Rel
CallingConvention
.
getConvention
in class Rel
public Expression[] getChildExps()
Rel
Rel
's child expressions (not
including the inputs returned by Rel.getInputs()
. If there are no
child expressions, returns an empty array, not null
.
getChildExps
in class Rel
public static boolean isRelational(OJClass clazz)
clazz
can be read as a
relation.
protected Type deriveRowType()
deriveRowType
in class Rel
private static boolean isDistinct(ArrayAllocationExpression arrayAlloc)
isDistinct(new String[] { "a", "b"})
returns true,
isDistinct(new int[] {1, 1+1})
returns false.
public boolean isDistinct()
Rel
false
, derived classes should override.
isDistinct
in class Rel
public Cost computeSelfCost(Planner planner)
Rel
computeSelfCost
in class Rel
public void explain(PlanWriter pw)
explain
in class Rel
public Object implement(Implementor implementor, int ordinal)
Rel
implement
in class Rel
implementor
- implementorordinal
- indicates our position in the pre-, in- and postfix walk
over the tree; ordinal
is -1 when called from the
parent, and i
when called from the
i
th child.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |