org.eigenbase.sql
Class SqlWindow

java.lang.Object
  extended by org.eigenbase.sql.SqlNode
      extended by org.eigenbase.sql.SqlCall
          extended by org.eigenbase.sql.SqlWindow
All Implemented Interfaces:
Cloneable

public class SqlWindow
extends SqlCall

SQL window specifcation.

For example, the query

SELECT sum(a) OVER (w ROWS 3 PRECEDING)
 FROM t
 WINDOW w AS (PARTITION BY x, y ORDER BY z),
     w1 AS (w ROWS 5 PRECEDING UNBOUNDED FOLLOWING)
declares windows w and w1, and uses a window in an OVER clause. It thus contains 3 SqlWindow objects.


Field Summary
static int AllowPartial_OPERAND
          Ordinal of the operand which declares whether to allow partial results.
static int DeclName_OPERAND
          Ordinal of the operand which holds the name of the window being declared.
static int IsRows_OPERAND
          Ordinal of the operand which declares whether it is a physical (rows) or logical (values) range.
static int LowerBound_OPERAND
          Ordinal of the operand which holds the lower bound of the window.
static int OperandCount
           
static int OrderList_OPERAND
          Ordinal of the operand which holds the list of ordering columns.
static int PartitionList_OPERAND
          Ordinal of the operand which holds the list of partitioning columns.
static int RefName_OPERAND
          Ordinal of operand which holds the name of the window being referenced, or null.
static int UpperBound_OPERAND
          Ordinal of the operand which holds the upper bound of the window.
private  SqlCall windowCall
           
 
Fields inherited from class org.eigenbase.sql.SqlCall
operands
 
Fields inherited from class org.eigenbase.sql.SqlNode
emptyArray
 
Constructor Summary
SqlWindow(SqlWindowOperator operator, SqlNode[] operands, SqlParserPos pos)
          Creates a window.
 
Method Summary
 boolean equalsDeep(SqlNode node, boolean fail)
          Overridden method to specfically check only the right subtree of a window definition
 SqlIdentifier getDeclName()
           
 SqlNode getLowerBound()
           
 SqlWindowOperator.OffsetRange getOffsetAndRange()
           
 SqlNodeList getOrderList()
           
 SqlNodeList getPartitionList()
           
 SqlIdentifier getRefName()
           
 SqlNode getUpperBound()
           
 SqlCall getWindowCall()
           
 boolean isAllowPartial()
          Returns whether partial windows are allowed.
 boolean isRows()
           
 SqlWindow overlay(SqlWindow that, SqlValidator validator)
          Creates a new window by combining this one with another.
 void setDeclName(SqlIdentifier name)
           
 void setLowerBound(SqlNode bound)
           
private static void setOperand(SqlNode[] destOperands, SqlNode[] srcOperands, int i, SqlValidator validator)
           
 void setUpperBound(SqlNode bound)
           
 void setWindowCall(SqlCall windowCall)
           
 void unparse(SqlWriter writer, int leftPrec, int rightPrec)
          Writes a SQL representation of this node to a writer.
 
Methods inherited from class org.eigenbase.sql.SqlCall
accept, clone, findValidOptions, getCallSignature, getFunctionQuantifier, getKind, getMonotonicity, getOperands, getOperator, isA, isCountStar, isExpanded, isName, setOperand, setOperator, validate
 
Methods inherited from class org.eigenbase.sql.SqlNode
clone, cloneArray, equalDeep, getParserPosition, toSqlString, toSqlString, toString, validateExpr
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DeclName_OPERAND

public static final int DeclName_OPERAND
Ordinal of the operand which holds the name of the window being declared.

See Also:
Constant Field Values

RefName_OPERAND

public static final int RefName_OPERAND
Ordinal of operand which holds the name of the window being referenced, or null.

See Also:
Constant Field Values

PartitionList_OPERAND

public static final int PartitionList_OPERAND
Ordinal of the operand which holds the list of partitioning columns.

See Also:
Constant Field Values

OrderList_OPERAND

public static final int OrderList_OPERAND
Ordinal of the operand which holds the list of ordering columns.

See Also:
Constant Field Values

IsRows_OPERAND

public static final int IsRows_OPERAND
Ordinal of the operand which declares whether it is a physical (rows) or logical (values) range.

See Also:
Constant Field Values

LowerBound_OPERAND

public static final int LowerBound_OPERAND
Ordinal of the operand which holds the lower bound of the window.

See Also:
Constant Field Values

UpperBound_OPERAND

public static final int UpperBound_OPERAND
Ordinal of the operand which holds the upper bound of the window.

See Also:
Constant Field Values

AllowPartial_OPERAND

public static final int AllowPartial_OPERAND
Ordinal of the operand which declares whether to allow partial results. It may be null.

See Also:
Constant Field Values

OperandCount

public static final int OperandCount
See Also:
Constant Field Values

windowCall

private SqlCall windowCall
Constructor Detail

SqlWindow

public SqlWindow(SqlWindowOperator operator,
                 SqlNode[] operands,
                 SqlParserPos pos)
Creates a window.

"Precondition:"
operands[DeclName_OPERAND] == null || operands[DeclName_OPERAND].isSimple(), operands[OrderList_OPERAND] != null, operands[PartitionList_OPERAND] != null
Method Detail

unparse

public void unparse(SqlWriter writer,
                    int leftPrec,
                    int rightPrec)
Description copied from class: SqlNode
Writes a SQL representation of this node to a writer.

The leftPrec and rightPrec parameters give us enough context to decide whether we need to enclose the expression in parentheses. For example, we need parentheses around "2 + 3" if preceded by "5 *". This is because the precedence of the "*" operator is greater than the precedence of the "+" operator.

The algorithm handles left- and right-associative operators by giving them slightly different left- and right-precedence.

If SqlWriter.isAlwaysUseParentheses() is true, we use parentheses even when they are not required by the precedence rules.

For the details of this algorithm, see SqlCall.unparse(org.eigenbase.sql.SqlWriter, int, int).

Overrides:
unparse in class SqlCall
Parameters:
writer - Target writer
leftPrec - The precedence of the SqlNode immediately preceding this node in a depth-first scan of the parse tree
rightPrec - The precedence of the SqlNode immediately

getDeclName

public SqlIdentifier getDeclName()

setDeclName

public void setDeclName(SqlIdentifier name)

getLowerBound

public SqlNode getLowerBound()

setLowerBound

public void setLowerBound(SqlNode bound)

getUpperBound

public SqlNode getUpperBound()

setUpperBound

public void setUpperBound(SqlNode bound)

isRows

public boolean isRows()

getOrderList

public SqlNodeList getOrderList()

getPartitionList

public SqlNodeList getPartitionList()

getRefName

public SqlIdentifier getRefName()

setWindowCall

public void setWindowCall(SqlCall windowCall)

getWindowCall

public SqlCall getWindowCall()

overlay

public SqlWindow overlay(SqlWindow that,
                         SqlValidator validator)
Creates a new window by combining this one with another.

For example,

WINDOW (w PARTITION BY x ORDER BY y)
   overlay
   WINDOW w AS (PARTITION BY z)
yields
WINDOW (PARTITION BY z ORDER BY y)

Does not alter this or the other window.

Returns:
A new window

setOperand

private static void setOperand(SqlNode[] destOperands,
                               SqlNode[] srcOperands,
                               int i,
                               SqlValidator validator)

equalsDeep

public boolean equalsDeep(SqlNode node,
                          boolean fail)
Overridden method to specfically check only the right subtree of a window definition

Overrides:
equalsDeep in class SqlCall
Parameters:
node - The SqlWindow to compare to "this" window
fail -
Returns:
boolean true if all nodes in the subtree are equal

getOffsetAndRange

public SqlWindowOperator.OffsetRange getOffsetAndRange()

isAllowPartial

public boolean isAllowPartial()
Returns whether partial windows are allowed. If false, a partial window (for example, a window of size 1 hour which has only 45 minutes of data in it) will appear to windowed aggregate functions to be empty.