saffron.rel
Class ExpressionReader

java.lang.Object
  |
  +--saffron.rel.Rel
        |
        +--saffron.rel.ExpressionReader
Direct Known Subclasses:
PlanArrayReader

public class ExpressionReader
extends Rel

An ExpressionReader is a relational expression node which evaluates an expression and returns the results as a relation. Cases:

  1. If the expression is an array T[], the each result row is of type T.
  2. If the expression implements Map or derives from Hashtable, each result row contains fields {Object key; Object value;}.
  3. If the expression implements 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:

Object fredDeptno =
    (select value from nameToDeptno where key.equals("Fred");
Because the Hashtable is being accessed via its key, the optimizer will probably optimize this code to nameToDeptno.get("Fred").

Since:
8 December, 2001
Version:
$Id: //open/saffron/src/main/saffron/rel/ExpressionReader.java#5 $
Author:
jhyde

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

exp

protected Expression exp

convention

protected CallingConvention convention

distinct

private boolean distinct
Whether the rows are distinct; set by deriveRowType().

Constructor Detail

ExpressionReader

public ExpressionReader(Cluster cluster,
                        Expression exp,
                        Type rowType)
Creates an ExpressionReader.

Parameters:
cluster - Cluster this relational expression belongs to
exp - expression to evaluate
rowType - 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

getExp

public Expression getExp()

chooseConvention

private CallingConvention chooseConvention(Expression exp)

clone

public Object clone()
Specified by:
clone in class Rel

getConvention

public CallingConvention getConvention()
Description copied from class: Rel
Returns a value from CallingConvention.

Overrides:
getConvention in class Rel

getChildExps

public Expression[] getChildExps()
Description copied from class: Rel
Returns an array of this Rel's child expressions (not including the inputs returned by Rel.getInputs(). If there are no child expressions, returns an empty array, not null.

Overrides:
getChildExps in class Rel

isRelational

public static boolean isRelational(OJClass clazz)
Returns whether an expression clazz can be read as a relation.


deriveRowType

protected Type deriveRowType()
Specified by:
deriveRowType in class Rel

isDistinct

private static boolean isDistinct(ArrayAllocationExpression arrayAlloc)
Returns true if the array allocation expression consists of distinct literals, false otherwise. For example, isDistinct(new String[] { "a", "b"}) returns true, isDistinct(new int[] {1, 1+1}) returns false.


isDistinct

public boolean isDistinct()
Description copied from class: Rel
Returns whether the same value will not come out twice. Default value is false, derived classes should override.

Overrides:
isDistinct in class Rel

computeSelfCost

public Cost computeSelfCost(Planner planner)
Description copied from class: Rel
Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

Overrides:
computeSelfCost in class Rel

explain

public void explain(PlanWriter pw)
Overrides:
explain in class Rel

implement

public Object implement(Implementor implementor,
                        int ordinal)
Description copied from class: Rel
Create a plan for this expression according to a calling convention.

Overrides:
implement in class Rel
Parameters:
implementor - implementor
ordinal - 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 ith child.

SourceForge.net_Logo