org.eigenbase.relopt
Class RelOptRuleOperand

java.lang.Object
  extended by org.eigenbase.relopt.RelOptRuleOperand
Direct Known Subclasses:
ConverterRule.ConverterRelOptRuleOperand

public class RelOptRuleOperand
extends Object

A RelOptRuleOperand determines whether a RelOptRule can be applied to a particular expression.

For example, the rule to pull a filter up from the left side of a join takes operands: (Join (Filter) (Any)).

Note that children means different things if it is empty or it is null: (Join (Filter ()) (Any)) means that, to match the rule, Filter must have no operands.


Nested Class Summary
static class RelOptRuleOperand.Dummy
          Dummy type, containing a single value, for parameters to overloaded forms of the RelOptRuleOperand constructor signifying operands that will be matched by relational expressions with any number of children.
 
Field Summary
private  RelOptRuleOperand[] children
           
private  Class<? extends RelNode> clazz
           
 boolean matchAnyChildren
           
 int ordinalInParent
           
 int ordinalInRule
           
private  RelOptRuleOperand parent
           
private  RelOptRule rule
           
 int[] solveOrder
           
private  RelTrait trait
           
 
Constructor Summary
RelOptRuleOperand(Class<? extends RelNode> clazz, RelOptRuleOperand... children)
          Creates an operand that matches child operands in the order they appear.
RelOptRuleOperand(Class<? extends RelNode> clazz, RelOptRuleOperand.Dummy dummy)
          Creates an operand that matches any number of children.
RelOptRuleOperand(Class<? extends RelNode> clazz, RelTrait trait, boolean matchAnyChild, RelOptRuleOperand... children)
          Creates an operand.
RelOptRuleOperand(Class<? extends RelNode> clazz, RelTrait trait, RelOptRuleOperand... children)
          Creates an operand which matches a given trait and matches child operands in the order they appear.
RelOptRuleOperand(Class<? extends RelNode> clazz, RelTrait trait, RelOptRuleOperand.Dummy dummy)
          Creates an operand that matches a given trait and any number of children.
 
Method Summary
 boolean equals(Object obj)
           
 RelOptRuleOperand[] getChildOperands()
          Returns the child operands.
 Class<? extends RelNode> getMatchedClass()
           
 RelOptRuleOperand getParent()
          Returns the parent operand.
 RelOptRule getRule()
          Returns the rule this operand belongs to.
 int hashCode()
           
 boolean matches(RelNode rel)
          Returns whether a relational expression matches this operand.
 void setParent(RelOptRuleOperand parent)
          Sets the parent operand.
 void setRule(RelOptRule rule)
          Sets the rule this operand belongs to
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

private RelOptRuleOperand parent

rule

private RelOptRule rule

solveOrder

public int[] solveOrder

ordinalInParent

public int ordinalInParent

ordinalInRule

public int ordinalInRule

trait

private final RelTrait trait

clazz

private final Class<? extends RelNode> clazz

children

private final RelOptRuleOperand[] children

matchAnyChildren

public final boolean matchAnyChildren
Constructor Detail

RelOptRuleOperand

public RelOptRuleOperand(Class<? extends RelNode> clazz,
                         RelTrait trait,
                         boolean matchAnyChild,
                         RelOptRuleOperand... children)
Creates an operand.

If children is null, the rule matches regardless of the number of children.

If matchAnyChild is true, child operands can be matched in any order. This is useful when matching a relational expression which can have a variable number of children. For example, the rule to eliminate empty children of a Union would have operands

Operand(UnionRel, true, Operand(EmptyRel))
and given the relational expressions
UnionRel(FilterRel, EmptyRel, ProjectRel)
would fire the rule with arguments
{Union, Empty}
It is up to the rule to deduce the other children, or indeed the position of the matched child.

Parameters:
clazz - Class of relational expression to match (must not be null)
trait - Trait to match, or null to match any trait
matchAnyChild - Whether child operands can be matched in any order
children - Child operands; or null, meaning match any number of children

RelOptRuleOperand

public RelOptRuleOperand(Class<? extends RelNode> clazz,
                         RelTrait trait,
                         RelOptRuleOperand... children)
Creates an operand which matches a given trait and matches child operands in the order they appear.

Parameters:
clazz - Class of relational expression to match (must not be null)
trait - Trait to match, or null to match any trait
children - Child operands; must not be null

RelOptRuleOperand

public RelOptRuleOperand(Class<? extends RelNode> clazz,
                         RelTrait trait,
                         RelOptRuleOperand.Dummy dummy)
Creates an operand that matches a given trait and any number of children.

Parameters:
clazz - Class of relational expression to match (must not be null)
trait - Trait to match, or null to match any trait
dummy - Dummy argument to distinguish this constructor from other overloaded forms

RelOptRuleOperand

public RelOptRuleOperand(Class<? extends RelNode> clazz,
                         RelOptRuleOperand... children)
Creates an operand that matches child operands in the order they appear.

If children is null, the rule matches regardless of the number of children.

Parameters:
clazz - Class of relational expression to match (must not be null)
children - Child operands; must not be null

RelOptRuleOperand

public RelOptRuleOperand(Class<? extends RelNode> clazz,
                         RelOptRuleOperand.Dummy dummy)
Creates an operand that matches any number of children.

Parameters:
clazz - Class of relational expression to match (must not be null)
dummy - Dummy argument to distinguish this constructor from other overloaded forms
Method Detail

getParent

public RelOptRuleOperand getParent()
Returns the parent operand.

Returns:
parent operand

setParent

public void setParent(RelOptRuleOperand parent)
Sets the parent operand.

Parameters:
parent - Parent operand

getRule

public RelOptRule getRule()
Returns the rule this operand belongs to.

Returns:
containing rule

setRule

public void setRule(RelOptRule rule)
Sets the rule this operand belongs to

Parameters:
rule - containing rule

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getMatchedClass

public Class<? extends RelNode> getMatchedClass()
Returns:
relational expression class matched by this operand

getChildOperands

public RelOptRuleOperand[] getChildOperands()
Returns the child operands.

Returns:
child operands

matches

public boolean matches(RelNode rel)
Returns whether a relational expression matches this operand. It must be of the right class and calling convention.