net.sf.saffron.rel
Class SaffronRel

java.lang.Object
  |
  +--net.sf.saffron.rel.SaffronRel
Direct Known Subclasses:
ExpressionReaderRel, ExtentRel, JdbcQuery, JoinRel, OneRowRel, OptUtil.RelHolder, RelSubset, SingleRel, TableAccessRel, UnionRel, VolcanoPlannerTest.TestLeafRel

public abstract class SaffronRel
extends Object

A SaffronRel 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(net.sf.saffron.core.SaffronPlanner).


Field Summary
protected  VolcanoCluster cluster
           
private  String correlVariable
          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 SaffronRel[] emptyArray
           
protected  int id
          unique id of this object -- for debugging
(package private) static int nextId
          generator for id values
 SaffronType rowType
          cached type of this relational expression
 
Constructor Summary
SaffronRel(VolcanoCluster cluster)
          Creates a SaffronRel.
 
Method Summary
 void childrenAccept(RelVisitor visitor)
           
abstract  Object clone()
           
protected  String computeDigest()
          Computes the digest.
 PlanCost computeSelfCost(SaffronPlanner planner)
          Returns the cost of this plan (not including children).
protected abstract  SaffronType deriveRowType()
           
 void explain(PlanWriter pw)
           
 RexNode[] getChildExps()
          Returns an array of this SaffronRel's child expressions (not including the inputs returned by getInputs().
 VolcanoCluster getCluster()
           
 CallingConvention getConvention()
          Returns a value from CallingConvention.
 String getCorrelVariable()
           
 int getId()
           
 SaffronRel getInput(int i)
          Get the ith input.
 SaffronRel[] getInputs()
          Returns an array of this SaffronRel's inputs.
 String getOrCreateCorrelVariable()
          Returns a variable with which to reference the current row of this relational expression as a correlating variable.
 String getQualifier()
           
 VolcanoQuery getQuery()
           
 String getRelTypeName()
          Returns the name of this SaffronRel's class, sans package name, for use in explain(net.sf.saffron.core.PlanWriter).
 double getRows()
          Returns an estimate of the number of rows this relational expression will return.
 SaffronType getRowType()
          Returns the type of the rows returned by this relational expression.
 SaffronTable getTable()
          If this relational expression represents an access to a table, returns that table, otherwise returns null.
 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(RelImplementor implementor, int ordinal)
          Create a plan for this expression according to a calling convention.
 SaffronRel implementFieldAccess(RelImplementor implementor, String fieldName)
          Burrows into a synthetic record and returns the underlying relation which provides the field called fieldName.
 boolean isAccessTo(SaffronTable 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(SaffronPlanner planner)
          This method is called just before the expression is registered.
 String recomputeDigest()
          Computes the digest, assigns it, and returns it.
static void register(SaffronPlanner planner)
          Registers any special rules specific to this kind of relational expression.
 void registerCorrelVariable(String correlVariable)
           
 void replaceInput(int ordinalInParent, SaffronRel p)
          Replaces the ordinalInParentth input.
 void setCorrelVariable(String correlVariable)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nextId

static int nextId
generator for id values


emptyArray

static final SaffronRel[] emptyArray

rowType

public SaffronType rowType
cached type of this relational expression


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(net.sf.saffron.core.SaffronPlanner), returned by toString().


cluster

protected VolcanoCluster cluster

id

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


correlVariable

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

Constructor Detail

SaffronRel

public SaffronRel(VolcanoCluster cluster)
Creates a SaffronRel.

Pre-condition:
cluster != null
Method Detail

clone

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

isAccessTo

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


getChildExps

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


getCluster

public VolcanoCluster getCluster()

getConvention

public CallingConvention getConvention()
Returns a value from CallingConvention.


setCorrelVariable

public void setCorrelVariable(String correlVariable)

getCorrelVariable

public String getCorrelVariable()

isDistinct

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


getId

public int getId()

getInput

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


getOrCreateCorrelVariable

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


getQuery

public VolcanoQuery getQuery()

register

public static void register(SaffronPlanner 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 SaffronPlanner.addRule(net.sf.saffron.opt.VolcanoRule) for each rule, and then call register(net.sf.saffron.core.SaffronPlanner) on its base class.


getRelTypeName

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


getRowType

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


getInputs

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


getQualifier

public String getQualifier()

getRows

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


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.


childrenAccept

public void childrenAccept(RelVisitor visitor)

computeSelfCost

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


explain

public void explain(PlanWriter pw)

implement

public Object implement(RelImplementor 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

implementFieldAccess

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


onRegister

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


recomputeDigest

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


registerCorrelVariable

public void registerCorrelVariable(String correlVariable)

replaceInput

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


toString

public String toString()
Overrides:
toString in class Object

getTable

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


computeDigest

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


deriveRowType

protected abstract SaffronType deriveRowType()

SourceForge.net_Logo