saffron.rel
Class Rel

java.lang.Object
  |
  +--saffron.rel.Rel
Direct Known Subclasses:
ExpressionReader, ExtentRel, JdbcQuery, Join, OneRow, RelSubset, SingleRel, TableAccess, Union, Util.RelHolder

public abstract class Rel
extends Object

A Rel is a relational expression. It is NOT an Expression.

If this type of relational expression has some particular rules, it should implement the public static method register(saffron.Planner).


Nested Class Summary
private static class Rel.PlanImplementor
           
 
Field Summary
protected  Cluster cluster
           
private  String corelVariable
          The variable by which to refer to rows from this relational expression, as correlating expressions; null if this expression is not correlated on.
protected  String digest
          A short description of this relational expression's type, inputs, and other properties.
(package private) static Rel[] emptyArray
           
private  RelEnvironment env
           
protected  int id
          unique id of this object -- for debugging
(package private) static int nextId
          generator for id values
 Type rowType
          cached type of this relational expression
 
Constructor Summary
Rel(Cluster cluster)
          Creates a Rel.
 
Method Summary
 void childrenAccept(RelVisitor visitor)
           
abstract  Object clone()
           
protected  String computeDigest()
          Computes the digest.
 Cost computeSelfCost(Planner planner)
          Returns the cost of this plan (not including children).
protected abstract  Type deriveRowType()
           
 void explain(PlanWriter pw)
           
 Expression[] getChildExps()
          Returns an array of this Rel's child expressions (not including the inputs returned by getInputs().
 Cluster getCluster()
           
 CallingConvention getConvention()
          Returns a value from CallingConvention.
 String getCorelVariable()
           
 RelEnvironment getEnvironment()
           
 int getId()
           
 Rel getInput(int i)
          Get the ith input.
 Rel[] getInputs()
          Returns an array of this Rel's inputs.
 String getOrCreateCorelVariable()
          Returns a variable with which to reference the current row of this relational expression as a correlating variable.
 Environment getParentEnv()
           
 String getQualifier()
           
 Query getQuery()
           
 String getRelTypeName()
          Returns the name of this Rel's class, sans package name, for use in explain(saffron.PlanWriter).
 double getRows()
          Returns an estimate of the number of rows this relational expression will return.
 Type getRowType()
          Returns the type of the rows returned by this relational expression.
protected  Table getTable()
          If this relational expression represents an access to a table, returns that table, otherwise returns null.
 OJClass getType(Expression exp)
          Returns the type of an expression in this Rel's environment.
 Set getVariablesStopped()
          Returns the names of variables which are set in this relational expression but also used and therefore not available to parents of this relational expression.
 Object implement(Implementor implementor, int ordinal)
          Create a plan for this expression according to a calling convention.
 Expression implementExp(Expression exp, Plan[] plans)
           
 Expression[] implementExps(Expression[] exps, Plan[] plans)
           
 Rel implementFieldAccess(Implementor implementor, String fieldName)
          Burrows into a synthetic record and returns the underlying relation which provides the field called fieldName.
 Expression implementSelf(Implementor implementor)
          Returns a Java expression which yields the current row of this relational expression.
 boolean isAccessTo(Table table)
          Returns whether this relational expression is an access to table.
 boolean isDistinct()
          Returns whether the same value will not come out twice.
 void onRegister(Planner planner)
          This method is called just before the expression is registered.
 String recomputeDigest()
          Computes the digest, assigns it, and returns it.
static void register(Planner planner)
          Registers any special rules specific to this kind of relational expression.
 void registerCorelVariable(String corelVariable)
           
 void replaceInput(int ordinalInParent, Rel p)
          Replaces the ordinalInParentth input.
 void setCorelVariable(String corelVariable)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

digest

protected String digest
A short description of this relational expression's type, inputs, and other properties. The string uniquely identifies the node; another node is equivalent if and only if it has the same value. Computed by computeDigest(), assigned by onRegister(saffron.Planner), returned by toString().


id

protected int id
unique id of this object -- for debugging


nextId

static int nextId
generator for id values


rowType

public Type rowType
cached type of this relational expression


env

private RelEnvironment env

cluster

protected Cluster cluster

corelVariable

private String corelVariable
The variable by which to refer to rows from this relational expression, as correlating expressions; null if this expression is not correlated on.


emptyArray

static final Rel[] emptyArray
Constructor Detail

Rel

public Rel(Cluster cluster)
Creates a Rel.

Pre-condition:
cluster != null
Method Detail

clone

public abstract Object clone()
Overrides:
clone in class Object

getId

public int getId()

getParentEnv

public Environment getParentEnv()

getEnvironment

public RelEnvironment getEnvironment()

getQuery

public Query getQuery()

getCluster

public Cluster getCluster()

register

public static void register(Planner planner)
Registers any special rules specific to this kind of relational expression.

The planner calls this method this first time that it sees a relational expression of this class. The derived class should call Planner.addRule(saffron.opt.Rule) for each rule, and then call register(saffron.Planner) on its base class.


getType

public OJClass getType(Expression exp)
Returns the type of an expression in this Rel's environment.


getRowType

public final Type getRowType()
Returns the type of the rows returned by this relational expression.


getInputs

public Rel[] getInputs()
Returns an array of this Rel's inputs. If there are no inputs, returns an empty array, not null.


replaceInput

public void replaceInput(int ordinalInParent,
                         Rel p)
Replaces the ordinalInParentth input. You must override this method if you override getInputs().


getChildExps

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


explain

public void explain(PlanWriter pw)

getRelTypeName

public final String getRelTypeName()
Returns the name of this Rel's class, sans package name, for use in explain(saffron.PlanWriter). For example, for a saffron.ArrayRel.ArrayReader, returns "ArrayReader".


getQualifier

public String getQualifier()

computeDigest

protected String computeDigest()
Computes the digest. Does not modify this object.


recomputeDigest

public String recomputeDigest()
Computes the digest, assigns it, and returns it. For internal use only.


childrenAccept

public void childrenAccept(RelVisitor visitor)

deriveRowType

protected abstract Type deriveRowType()

isAccessTo

public boolean isAccessTo(Table table)
Returns whether this relational expression is an access to table.


getTable

protected Table getTable()
If this relational expression represents an access to a table, returns that table, otherwise returns null.


getInput

public Rel getInput(int i)
Get the ith input.


getOrCreateCorelVariable

public String getOrCreateCorelVariable()
Returns a variable with which to reference the current row of this relational expression as a correlating variable. Creates a variable if none exists.


registerCorelVariable

public void registerCorelVariable(String corelVariable)

getCorelVariable

public String getCorelVariable()

setCorelVariable

public void setCorelVariable(String corelVariable)

getVariablesStopped

public Set getVariablesStopped()
Returns the names of variables which are set in this relational expression but also used and therefore not available to parents of this relational expression.

By default, returns the empty set. Derived classes may override this method.


isDistinct

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


onRegister

public void onRegister(Planner planner)
This method is called just before the expression is registered. The implementation of this method must at least register all child expressions.


toString

public String toString()
Overrides:
toString in class Object

getRows

public double getRows()
Returns an estimate of the number of rows this relational expression will return.


computeSelfCost

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


implement

public Object implement(Implementor implementor,
                        int ordinal)
Create a plan for this expression according to a calling convention.

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.
Throws:
UnsupportedOperationException - if this expression cannot be implemented

implementSelf

public Expression implementSelf(Implementor implementor)
Returns a Java expression which yields the current row of this relational expression. This method is called by the Rel.PlanImplementor the first time a piece of Java code wants to refer to this relation. The implementor then uses this expression to initialize a variable.

If no code needs to refer to this relation, then the expression is never generated. This prevents generating useless code like

Dummy_12f614.Ojp_1 oj_var8 = new Dummy_12f614.Ojp_1();
.

See Also:
Implementor#bind(Rel,Rel)

implementFieldAccess

public Rel implementFieldAccess(Implementor implementor,
                                String fieldName)
Burrows into a synthetic record and returns the underlying relation which provides the field called fieldName.


getConvention

public CallingConvention getConvention()
Returns a value from CallingConvention.


implementExp

public Expression implementExp(Expression exp,
                               Plan[] plans)

implementExps

public Expression[] implementExps(Expression[] exps,
                                  Plan[] plans)

SourceForge.net_Logo