net.sf.farrago.fennel.rel
Class FennelReshapeRule

java.lang.Object
  extended by org.eigenbase.relopt.RelOptRule
      extended by net.sf.farrago.fennel.rel.FennelReshapeRule

public class FennelReshapeRule
extends RelOptRule

FennelReshapeRule is a rule that converts a CalcRel into a FennelReshapeRel, provided the CalcRel only references simple projections and contains a simple condition, if it has a condition.

The projection is simple if it consists of only RexInputRefs or CASTs of RexInputRefs where the cast effectively does not require any actual data conversion or data validation.

The condition is simple if the expression is an AND of filters, where each filter is of the form RexInputRef OP RexLiteral. Each RexInputRef can only be referenced once, and OP is either =, >, >=, <, or <=. However, the non-equality operators can only be referenced once.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/fennel/rel/FennelReshapeRule.java#3 $
Author:
Zelaine Fong

Field Summary
static FennelReshapeRule instance
           
 
Fields inherited from class org.eigenbase.relopt.RelOptRule
ANY, description, operands
 
Constructor Summary
private FennelReshapeRule()
          Creates a FennelReshapeRule.
 
Method Summary
 CallingConvention getOutConvention()
          Returns the calling convention of the result of firing this rule, null if not known.
private  boolean isCastSimple(RelDataType origType, RelDataType castType)
          Returns true if a type is a simple cast of another type.
private  boolean isConditionSimple(CalcRel calcRel, RexNode filterExprs, List<Integer> filterList, List<RexLiteral> literals, List<CompOperatorEnum> op)
          Determines if a filter condition is a simple one and returns the parameters corresponding to the simple filters.
private  RelDataType isProjectSimple(CalcRel calcRel, List<Integer> projOrdinals)
          Determines if a projection is simple.
 void onMatch(RelOptRuleCall call)
          Receives notification about a rule match.
 
Methods inherited from class org.eigenbase.relopt.RelOptRule
convert, equals, equals, getOperand, getOperands, getOutTrait, hashCode, matches, mergeTraitsAndConvert, mergeTraitsAndConvert, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

instance

public static final FennelReshapeRule instance
Constructor Detail

FennelReshapeRule

private FennelReshapeRule()
Creates a FennelReshapeRule.

Method Detail

getOutConvention

public CallingConvention getOutConvention()
Description copied from class: RelOptRule
Returns the calling convention of the result of firing this rule, null if not known.

Overrides:
getOutConvention in class RelOptRule

onMatch

public void onMatch(RelOptRuleCall call)
Description copied from class: RelOptRule
Receives notification about a rule match. At the time that this method is called, call.rels holds the set of relational expressions which match the operands to the rule; call.rels[0] is the root expression.

Typically a rule would check that the nodes are valid matches, creates a new expression, then calls back RelOptRuleCall.transformTo(org.eigenbase.rel.RelNode) to register the expression.

Specified by:
onMatch in class RelOptRule
Parameters:
call - Rule call
See Also:
RelOptRule.matches(RelOptRuleCall)

isProjectSimple

private RelDataType isProjectSimple(CalcRel calcRel,
                                    List<Integer> projOrdinals)
Determines if a projection is simple.

Parameters:
calcRel - CalcRel containing the projection
projOrdinals - if the projection is simple, returns the ordinals of the projection inputs
Returns:
rowtype corresponding to the projection, provided it is simple; otherwise null is returned

isCastSimple

private boolean isCastSimple(RelDataType origType,
                             RelDataType castType)
Returns true if a type is a simple cast of another type. It is if the cast type is nullable and the cast is one of the following:
  • x TO x
  • char(n) TO varchar(m)
  • varchar(n) TO varchar(m)
  • x not null TO x nullable

    Parameters:
    origType - original type passed into the cast operand
    castType - type the operand will be casted to
    Returns:
    true if the cast is simple

  • isConditionSimple

    private boolean isConditionSimple(CalcRel calcRel,
                                      RexNode filterExprs,
                                      List<Integer> filterList,
                                      List<RexLiteral> literals,
                                      List<CompOperatorEnum> op)
    Determines if a filter condition is a simple one and returns the parameters corresponding to the simple filters.

    Parameters:
    calcRel - original CalcRel
    filterExprs - filter expression being analyzed
    filterList - returns the list of filter ordinals in the simple expression
    literals - returns the list of literals to be used in the simple comparisons
    op - returns the operator to be used in the simple comparison
    Returns:
    true if the filter condition is simple