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 | Field and Description |
|---|---|
static SqlPostfixOperator |
FOLLOWING_OPERATOR
The FOLLOWING operator used exclusively in a window specification.
|
static SqlPostfixOperator |
PRECEDING_OPERATOR
The PRECEDING operator used exclusively in a window specification.
|
EMPTY_ARRAY, pos| Constructor and Description |
|---|
SqlWindow(SqlParserPos pos,
@Nullable SqlIdentifier declName,
@Nullable SqlIdentifier refName,
SqlNodeList partitionList,
SqlNodeList orderList,
SqlLiteral isRows,
@Nullable SqlNode lowerBound,
@Nullable SqlNode upperBound,
@Nullable SqlLiteral allowPartial)
Creates a window.
|
| Modifier and Type | Method and Description |
|---|---|
static SqlWindow |
create(@Nullable SqlIdentifier declName,
@Nullable SqlIdentifier refName,
SqlNodeList partitionList,
SqlNodeList orderList,
SqlLiteral isRows,
@Nullable SqlNode lowerBound,
@Nullable SqlNode upperBound,
@Nullable SqlLiteral allowPartial,
SqlParserPos pos) |
static SqlNode |
createBound(SqlLiteral range) |
static SqlNode |
createCurrentRow(SqlParserPos pos) |
SqlWindow |
createCurrentRowWindow(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(String columnName)
Creates a window
(RANGE columnName UNBOUNDED
PRECEDING). |
boolean |
equalsDeep(@Nullable SqlNode node,
Litmus litmus)
Overridden method to specifically check only the right subtree of a window
definition.
|
@Nullable SqlIdentifier |
getDeclName() |
SqlKind |
getKind()
Returns the type of node this is, or
SqlKind.OTHER if it's nothing special. |
@Nullable SqlNode |
getLowerBound() |
List<SqlNode> |
getOperandList()
Returns the list of operands.
|
SqlOperator |
getOperator() |
SqlNodeList |
getOrderList() |
SqlNodeList |
getPartitionList() |
@Nullable SqlIdentifier |
getRefName() |
@Nullable SqlNode |
getUpperBound() |
@Nullable SqlCall |
getWindowCall() |
boolean |
isAllowPartial()
Returns whether partial windows are allowed.
|
boolean |
isAlwaysNonEmpty()
Returns if the window is guaranteed to have rows.
|
static boolean |
isAlwaysNonEmpty(RexWindowBound lower,
RexWindowBound upper) |
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()
Deprecated.
|
void |
setDeclName(SqlIdentifier declName) |
void |
setLowerBound(@Nullable SqlNode lowerBound) |
void |
setOperand(int i,
@Nullable SqlNode operand)
Changes the value of an operand.
|
void |
setOrderList(SqlNodeList orderList) |
void |
setPartitionList(SqlNodeList partitionList) |
void |
setRows(SqlLiteral isRows) |
void |
setUpperBound(@Nullable SqlNode upperBound) |
void |
setWindowCall(@Nullable 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.
|
accept, clone, findValidOptions, getCallSignature, getFunctionQuantifier, getMonotonicity, isCountStar, isExpanded, operand, operandCountclone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, getParserPosition, isA, toList, toList, toSqlString, toSqlString, toSqlString, toString, unparseWithParentheses, validateExprpublic static final SqlPostfixOperator FOLLOWING_OPERATOR
public static final SqlPostfixOperator PRECEDING_OPERATOR
public SqlWindow(SqlParserPos pos, @Nullable SqlIdentifier declName, @Nullable SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, @Nullable SqlNode lowerBound, @Nullable SqlNode upperBound, @Nullable SqlLiteral allowPartial)
public static SqlWindow create(@Nullable SqlIdentifier declName, @Nullable SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, @Nullable SqlNode lowerBound, @Nullable SqlNode upperBound, @Nullable SqlLiteral allowPartial, SqlParserPos pos)
public SqlOperator getOperator()
getOperator in class SqlCallpublic SqlKind getKind()
SqlNodeSqlKind.OTHER if it's nothing special.getKind in class SqlCallSqlKind value, never nullSqlNode.isA(java.util.Set<org.apache.calcite.sql.SqlKind>)public List<SqlNode> getOperandList()
SqlCallNote: the proper type would be List<@Nullable SqlNode>, however,
it would trigger too many changes to the current codebase.
getOperandList in class SqlCallpublic void setOperand(int i,
@Nullable SqlNode operand)
SqlCallSqlValidator; use sparingly.setOperand in class SqlCalli - Operand indexoperand - Operand valuepublic void unparse(SqlWriter writer, int leftPrec, int rightPrec)
SqlNodeThe 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 @Nullable SqlIdentifier getDeclName()
public void setDeclName(SqlIdentifier declName)
public @Nullable SqlNode getLowerBound()
public void setLowerBound(@Nullable SqlNode lowerBound)
public @Nullable SqlNode getUpperBound()
public void setUpperBound(@Nullable SqlNode upperBound)
public boolean isAlwaysNonEmpty()
Window.Group.isAlwaysNonEmpty(),
SqlOperatorBinding.getGroupCount(),
SqlValidatorImpl.resolveWindow(SqlNode, SqlValidatorScope)public static boolean isAlwaysNonEmpty(RexWindowBound lower, RexWindowBound upper)
public void setRows(SqlLiteral isRows)
@Pure public boolean isRows()
public SqlNodeList getOrderList()
public void setOrderList(SqlNodeList orderList)
public SqlNodeList getPartitionList()
public void setPartitionList(SqlNodeList partitionList)
public @Nullable SqlIdentifier getRefName()
public void setWindowCall(@Nullable SqlCall windowCall)
public @Nullable SqlCall getWindowCall()
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.
public boolean equalsDeep(@Nullable SqlNode node, Litmus litmus)
equalsDeep in class SqlCallnode - The SqlWindow to compare to "this" windowlitmus - What to do if an error is detected (nodes are not equal)@EnsuresNonNullIf(expression="allowPartial",
result=false)
public boolean isAllowPartial()
public void validate(SqlValidator validator, SqlValidatorScope scope)
SqlCallThe 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).
public SqlWindow createCurrentRowWindow(String columnName)
(RANGE columnName CURRENT ROW).columnName - Order columnpublic SqlWindow createUnboundedPrecedingWindow(String columnName)
(RANGE columnName UNBOUNDED
PRECEDING).columnName - Order column@Deprecated public void populateBounds()
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.