net.sf.saffron.oj.rel
Class ExpressionReaderRel

java.lang.Object
  |
  +--net.sf.saffron.rel.SaffronRel
        |
        +--net.sf.saffron.oj.rel.ExpressionReaderRel

public class ExpressionReaderRel
extends SaffronRel

An ExpressionReaderRel 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/net/sf/saffron/oj/rel/ExpressionReaderRel.java#4 $
Author:
jhyde

Field Summary
protected  CallingConvention convention
           
private  boolean distinct
          Whether the rows are distinct; set by deriveRowType().
protected  RexNode exp
           
 
Fields inherited from class net.sf.saffron.rel.SaffronRel
cluster, digest, id, rowType
 
Constructor Summary
ExpressionReaderRel(VolcanoCluster cluster, RexNode exp, SaffronType rowType)
          Creates an ExpressionReaderRel.
 
Method Summary
private  CallingConvention chooseConvention(RexNode exp)
           
 Object clone()
           
 PlanCost computeSelfCost(SaffronPlanner planner)
          Returns the cost of this plan (not including children).
protected  SaffronType deriveRowType()
           
 void explain(PlanWriter pw)
           
 RexNode[] getChildExps()
          Returns an array of this SaffronRel's child expressions (not including the inputs returned by SaffronRel.getInputs().
 CallingConvention getConvention()
          Returns a value from CallingConvention.
 RexNode getExp()
           
 Object implement(RelImplementor 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.
private  boolean isDistinct(RexNode exp)
           
 
Methods inherited from class net.sf.saffron.rel.SaffronRel
childrenAccept, computeDigest, getCluster, getCorrelVariable, getId, getInput, getInputs, getOrCreateCorrelVariable, getQualifier, getQuery, getRelTypeName, getRows, getRowType, getTable, getVariablesStopped, implementFieldAccess, isAccessTo, onRegister, recomputeDigest, register, registerCorrelVariable, replaceInput, setCorrelVariable, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

convention

protected CallingConvention convention

exp

protected RexNode exp

distinct

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

Constructor Detail

ExpressionReaderRel

public ExpressionReaderRel(VolcanoCluster cluster,
                           RexNode exp,
                           SaffronType rowType)
Creates an ExpressionReaderRel.

Parameters:
cluster - VolcanoCluster 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. Note that actual row type of the relational expression is always a record type with a single field. For example, if you supply an expression of type "java.util.Iterator" and specify that the row type is "java.lang.String" then the row type will be "Record{$f0:String}".
Method Detail

getChildExps

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

Overrides:
getChildExps in class SaffronRel

getConvention

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

Overrides:
getConvention in class SaffronRel

isDistinct

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

Overrides:
isDistinct in class SaffronRel

getExp

public RexNode getExp()

clone

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

computeSelfCost

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

Overrides:
computeSelfCost in class SaffronRel

explain

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

implement

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

Overrides:
implement in class SaffronRel
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.

deriveRowType

protected SaffronType deriveRowType()
Specified by:
deriveRowType in class SaffronRel

isDistinct

private boolean isDistinct(RexNode exp)

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.


chooseConvention

private CallingConvention chooseConvention(RexNode exp)

SourceForge.net_Logo