public class SqlWindow extends SqlCall
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.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
SqlWindow.Bound
An enumeration of types of bounds in a window:
CURRENT ROW ,
UNBOUNDED PRECEDING , and UNBOUNDED FOLLOWING . |
private static class |
SqlWindow.SqlWindowOperator
An operator describing a window specification.
|
Modifier and Type | Field and Description |
---|---|
(package private) SqlLiteral |
allowPartial
Whether to allow partial results.
|
(package private) SqlIdentifier |
declName
The name of the window being declared.
|
static SqlPostfixOperator |
FOLLOWING_OPERATOR
The FOLLOWING operator used exclusively in a window specification.
|
(package private) SqlLiteral |
isRows
Whether it is a physical (rows) or logical (values) range.
|
(package private) SqlNode |
lowerBound
The lower bound of the window.
|
(package private) SqlNodeList |
orderList
The list of ordering columns.
|
(package private) SqlNodeList |
partitionList
The list of partitioning columns.
|
static SqlPostfixOperator |
PRECEDING_OPERATOR
The PRECEDING operator used exclusively in a window specification.
|
(package private) SqlIdentifier |
refName
The name of the window being referenced, or null.
|
(package private) SqlNode |
upperBound
The upper bound of the window.
|
private SqlCall |
windowCall |
EMPTY_ARRAY, pos
Constructor and Description |
---|
SqlWindow(SqlParserPos pos,
SqlIdentifier declName,
SqlIdentifier refName,
SqlNodeList partitionList,
SqlNodeList orderList,
SqlLiteral isRows,
SqlNode lowerBound,
SqlNode upperBound,
SqlLiteral allowPartial)
Creates a window.
|
Modifier and Type | Method and Description |
---|---|
(package private) static void |
checkSpecialLiterals(SqlWindow window,
SqlValidator validator) |
static SqlWindow |
create(SqlIdentifier declName,
SqlIdentifier refName,
SqlNodeList partitionList,
SqlNodeList orderList,
SqlLiteral isRows,
SqlNode lowerBound,
SqlNode upperBound,
SqlLiteral allowPartial,
SqlParserPos pos) |
static SqlNode |
createBound(SqlLiteral range) |
static SqlNode |
createCurrentRow(SqlParserPos pos) |
SqlWindow |
createCurrentRowWindow(java.lang.String columnName)
Creates a window
(RANGE columnName CURRENT ROW) . |
static SqlNode |
createFollowing(SqlNode e,
SqlParserPos pos) |
static SqlNode |
createPreceding(SqlNode e,
SqlParserPos pos) |
static SqlNode |
createUnboundedFollowing(SqlParserPos pos) |
static SqlNode |
createUnboundedPreceding(SqlParserPos pos) |
SqlWindow |
createUnboundedPrecedingWindow(java.lang.String columnName)
Creates a window
(RANGE columnName UNBOUNDED
PRECEDING) . |
boolean |
equalsDeep(SqlNode node,
Litmus litmus)
Overridden method to specifically check only the right subtree of a window
definition.
|
SqlIdentifier |
getDeclName() |
SqlKind |
getKind()
Returns the type of node this is, or
SqlKind.OTHER if it's nothing special. |
SqlNode |
getLowerBound() |
java.util.List<SqlNode> |
getOperandList() |
SqlOperator |
getOperator() |
SqlNodeList |
getOrderList() |
SqlNodeList |
getPartitionList() |
SqlIdentifier |
getRefName() |
SqlNode |
getUpperBound() |
SqlCall |
getWindowCall() |
boolean |
isAllowPartial()
Returns whether partial windows are allowed.
|
boolean |
isAlwaysNonEmpty()
Returns if the window is guaranteed to have rows.
|
static boolean |
isCurrentRow(SqlNode node)
Returns whether an expression represents the "CURRENT ROW" bound.
|
boolean |
isRows() |
static boolean |
isUnboundedFollowing(SqlNode node)
Returns whether an expression represents the "UNBOUNDED FOLLOWING" bound.
|
static boolean |
isUnboundedPreceding(SqlNode node)
Returns whether an expression represents the "UNBOUNDED PRECEDING" bound.
|
SqlWindow |
overlay(SqlWindow that,
SqlValidator validator)
Creates a new window by combining this one with another.
|
void |
populateBounds()
Fill in missing bounds.
|
void |
setDeclName(SqlIdentifier declName) |
void |
setLowerBound(SqlNode lowerBound) |
void |
setOperand(int i,
SqlNode operand)
Changes the value of an operand.
|
private static boolean |
setOperand(SqlNode clonedOperand,
SqlNode thatOperand,
SqlValidator validator) |
void |
setOrderList(SqlNodeList orderList) |
void |
setPartitionList(SqlNodeList partitionList) |
void |
setRows(SqlLiteral isRows) |
void |
setUpperBound(SqlNode upperBound) |
void |
setWindowCall(SqlCall windowCall) |
void |
unparse(SqlWriter writer,
int leftPrec,
int rightPrec)
Writes a SQL representation of this node to a writer.
|
void |
validate(SqlValidator validator,
SqlValidatorScope scope)
Validates this call.
|
private void |
validateFrameBoundary(SqlNode bound,
boolean isRows,
SqlTypeFamily orderTypeFam,
SqlValidator validator,
SqlValidatorScope scope) |
accept, clone, findValidOptions, getCallSignature, getFunctionQuantifier, getMonotonicity, isCountStar, isExpanded, operand, operandCount
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, getParserPosition, isA, toSqlString, toSqlString, toString, validateExpr
public static final SqlPostfixOperator FOLLOWING_OPERATOR
public static final SqlPostfixOperator PRECEDING_OPERATOR
SqlIdentifier declName
SqlIdentifier refName
SqlNodeList partitionList
SqlNodeList orderList
SqlLiteral isRows
SqlNode lowerBound
SqlNode upperBound
SqlLiteral allowPartial
private SqlCall windowCall
public SqlWindow(SqlParserPos pos, SqlIdentifier declName, SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, SqlNode lowerBound, SqlNode upperBound, SqlLiteral allowPartial)
public static SqlWindow create(SqlIdentifier declName, SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, SqlNode lowerBound, SqlNode upperBound, SqlLiteral allowPartial, SqlParserPos pos)
public SqlOperator getOperator()
getOperator
in class SqlCall
public SqlKind getKind()
SqlNode
SqlKind.OTHER
if it's nothing special.getKind
in class SqlCall
SqlKind
value, never nullSqlNode.isA(java.util.Set<org.apache.calcite.sql.SqlKind>)
public java.util.List<SqlNode> getOperandList()
getOperandList
in class SqlCall
public void setOperand(int i, SqlNode operand)
SqlCall
SqlValidator
; use sparingly.setOperand
in class SqlCall
i
- Operand indexoperand
- Operand valuepublic void unparse(SqlWriter writer, int leftPrec, int rightPrec)
SqlNode
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.apache.calcite.sql.SqlWriter, int, int)
.
public SqlIdentifier getDeclName()
public void setDeclName(SqlIdentifier declName)
public SqlNode getLowerBound()
public void setLowerBound(SqlNode lowerBound)
public SqlNode getUpperBound()
public void setUpperBound(SqlNode upperBound)
public boolean isAlwaysNonEmpty()
Window.Group.isAlwaysNonEmpty()
,
SqlOperatorBinding.getGroupCount()
,
SqlValidatorImpl.resolveWindow(SqlNode, org.apache.calcite.sql.validate.SqlValidatorScope, boolean)
public void setRows(SqlLiteral isRows)
public boolean isRows()
public SqlNodeList getOrderList()
public void setOrderList(SqlNodeList orderList)
public SqlNodeList getPartitionList()
public void setPartitionList(SqlNodeList partitionList)
public SqlIdentifier getRefName()
public void setWindowCall(SqlCall windowCall)
public SqlCall getWindowCall()
static void checkSpecialLiterals(SqlWindow window, SqlValidator validator)
Util.deprecated(Object, boolean)
public static SqlNode createCurrentRow(SqlParserPos pos)
public static SqlNode createUnboundedFollowing(SqlParserPos pos)
public static SqlNode createUnboundedPreceding(SqlParserPos pos)
public static SqlNode createFollowing(SqlNode e, SqlParserPos pos)
public static SqlNode createPreceding(SqlNode e, SqlParserPos pos)
public static SqlNode createBound(SqlLiteral range)
public static boolean isCurrentRow(SqlNode node)
public static boolean isUnboundedPreceding(SqlNode node)
public static boolean isUnboundedFollowing(SqlNode node)
public SqlWindow overlay(SqlWindow that, SqlValidator validator)
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.
private static boolean setOperand(SqlNode clonedOperand, SqlNode thatOperand, SqlValidator validator)
public boolean equalsDeep(SqlNode node, Litmus litmus)
equalsDeep
in class SqlCall
node
- The SqlWindow to compare to "this" windowlitmus
- What to do if an error is detected (nodes are not equal)public boolean isAllowPartial()
public void validate(SqlValidator validator, SqlValidatorScope scope)
SqlCall
The default implementation delegates the validation to the operator's
SqlOperator.validateCall(org.apache.calcite.sql.SqlCall, org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope, org.apache.calcite.sql.validate.SqlValidatorScope)
. Derived classes may override (as do,
for example SqlSelect
and SqlUpdate
).
private void validateFrameBoundary(SqlNode bound, boolean isRows, SqlTypeFamily orderTypeFam, SqlValidator validator, SqlValidatorScope scope)
public SqlWindow createCurrentRowWindow(java.lang.String columnName)
(RANGE columnName CURRENT ROW)
.columnName
- Order columnpublic SqlWindow createUnboundedPrecedingWindow(java.lang.String columnName)
(RANGE columnName UNBOUNDED
PRECEDING)
.columnName
- Order columnpublic void populateBounds()
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.