net.sf.farrago.fennel.rel
Class FennelWindowRule

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

public abstract class FennelWindowRule
extends RelOptRule

FennelWindowRule is a rule for implementing a CalcRel which contains windowed aggregates via a FennelWindowRel.

There are several instances of the rule (CalcOnWinOnCalc, CalcOnWin, WinOnCalc, Win), which pull in any CalcRel objects above or below. (It may be better to write a rule which merges CalcRel and WindowedAggregateRel objects together, thereby dealing with this problem at the logical level.)

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/fennel/rel/FennelWindowRule.java#3 $
Author:
jhyde

Field Summary
static FennelWindowRule CalcOnWin
          Instance of the rule which matches a CalcRel on top of a WindowedAggregateRel.
static FennelWindowRule CalcOnWinOnCalc
          Instance of the rule which matches CalcRel on top of WindowedAggregateRel on top of CalcRel.
static FennelWindowRule Win
          Instance of the rule which matches a WindowedAggregateRel on top of a RelNode.
static FennelWindowRule WinOnCalc
          Instance of the rule which matches a WindowedAggregateRel on top of a CalcRel.
 
Fields inherited from class org.eigenbase.relopt.RelOptRule
ANY, description, operands
 
Constructor Summary
private FennelWindowRule(RelOptRuleOperand operand, String description)
          Creates a FennelWindowRule.
 
Method Summary
private  FennelWindowRel.RexWinAggCall addWindows(List<FennelWindowRel.Window> windowList, RexOver over, RexProgramBuilder programBuilder)
           
protected  void createRels(RelOptRuleCall call, CalcRel outCalc, WindowedAggregateRel winAggRel, CalcRel inCalc, RelNode child)
           
 CallingConvention getOutConvention()
          Returns the calling convention of the result of firing this rule, null if not known.
private  Integer[] getProjectOrdinals(RexProgramBuilder programBuilder, RexNode[] exprs)
          Converts a list of expressions into a list of ordinals that these expressions are projected from a RexProgramBuilder.
private  boolean isPartitioningOnCalcField(CalcRel inCalc, List<FennelWindowRel.Window> windowList)
          Returns whether any of the partitions in windowList uses a field calculated in inCalc.
private  FennelWindowRel.Window lookupWindow(List<FennelWindowRel.Window> windowList, boolean physical, SqlNode lowerBound, SqlNode upperBound, Integer[] orderKeys)
           
 
Methods inherited from class org.eigenbase.relopt.RelOptRule
convert, equals, equals, getOperand, getOperands, getOutTrait, hashCode, matches, mergeTraitsAndConvert, mergeTraitsAndConvert, onMatch, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CalcOnWinOnCalc

public static final FennelWindowRule CalcOnWinOnCalc
Instance of the rule which matches CalcRel on top of WindowedAggregateRel on top of CalcRel.


CalcOnWin

public static final FennelWindowRule CalcOnWin
Instance of the rule which matches a CalcRel on top of a WindowedAggregateRel.


WinOnCalc

public static final FennelWindowRule WinOnCalc
Instance of the rule which matches a WindowedAggregateRel on top of a CalcRel.


Win

public static final FennelWindowRule Win
Instance of the rule which matches a WindowedAggregateRel on top of a RelNode.

Constructor Detail

FennelWindowRule

private FennelWindowRule(RelOptRuleOperand operand,
                         String description)
Creates a FennelWindowRule.

Parameters:
operand - root operand, must not be null
description - Description, or null to guess description
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

createRels

protected void createRels(RelOptRuleCall call,
                          CalcRel outCalc,
                          WindowedAggregateRel winAggRel,
                          CalcRel inCalc,
                          RelNode child)

isPartitioningOnCalcField

private boolean isPartitioningOnCalcField(CalcRel inCalc,
                                          List<FennelWindowRel.Window> windowList)
Returns whether any of the partitions in windowList uses a field calculated in inCalc.

Parameters:
inCalc - Calculator relational expression
windowList - List of windows
Returns:
Whether any partition has a calculated field

addWindows

private FennelWindowRel.RexWinAggCall addWindows(List<FennelWindowRel.Window> windowList,
                                                 RexOver over,
                                                 RexProgramBuilder programBuilder)

getProjectOrdinals

private Integer[] getProjectOrdinals(RexProgramBuilder programBuilder,
                                     RexNode[] exprs)
Converts a list of expressions into a list of ordinals that these expressions are projected from a RexProgramBuilder. If an expression is not projected, adds it.

Parameters:
programBuilder - Program builder
exprs - List of expressions
Returns:
List of ordinals where expressions are projected

lookupWindow

private FennelWindowRel.Window lookupWindow(List<FennelWindowRel.Window> windowList,
                                            boolean physical,
                                            SqlNode lowerBound,
                                            SqlNode upperBound,
                                            Integer[] orderKeys)