Class SqlWindow
- All Implemented Interfaces:
Cloneable
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
Modifier and TypeFieldDescriptionstatic final SqlPostfixOperator
The FOLLOWING operator used exclusively in a window specification.static final SqlPostfixOperator
The PRECEDING operator used exclusively in a window specification.Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos
-
Constructor Summary
ConstructorDescriptionSqlWindow
(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.SqlWindow
(SqlParserPos pos, @Nullable SqlIdentifier declName, @Nullable SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, @Nullable SqlNode lowerBound, @Nullable SqlNode upperBound, @Nullable SqlLiteral allowPartial, SqlLiteral exclude) Creates a window. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 SqlWindow
create
(@Nullable SqlIdentifier declName, @Nullable SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, @Nullable SqlNode lowerBound, @Nullable SqlNode upperBound, @Nullable SqlLiteral allowPartial, SqlLiteral exclude, SqlParserPos pos) static SqlNode
createBound
(SqlLiteral range) static SqlNode
createCurrentRowWindow
(String columnName) Creates a window(RANGE columnName CURRENT ROW)
.static SqlLiteral
static SqlLiteral
static SqlLiteral
static SqlLiteral
static SqlNode
createFollowing
(SqlNode e, SqlParserPos pos) static SqlNode
createPreceding
(SqlNode e, SqlParserPos pos) static SqlNode
static SqlNode
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
getKind()
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special.@Nullable SqlNode
Returns the list of operands.@Nullable SqlIdentifier
@Nullable SqlNode
@Nullable SqlCall
boolean
Returns whether partial windows are allowed.boolean
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.static boolean
static boolean
isExcludeGroup
(SqlLiteral node) static boolean
isExcludeNoOthers
(SqlLiteral node) static boolean
isExcludeTies
(SqlLiteral node) 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.overlay
(SqlWindow that, SqlValidator validator) Creates a new window by combining this one with another.void
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
Writes a SQL representation of this node to a writer.void
validate
(SqlValidator validator, SqlValidatorScope scope) Validates this call.Methods inherited from class org.apache.calcite.sql.SqlCall
accept, clone, findValidOptions, getCallSignature, getFunctionQuantifier, getMonotonicity, isCountStar, isExpanded, operand, operandCount
Methods inherited from class org.apache.calcite.sql.SqlNode
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, getParserPosition, isA, toList, toList, toSqlString, toSqlString, toSqlString, toString, unparseWithParentheses, validateExpr
-
Field Details
-
FOLLOWING_OPERATOR
The FOLLOWING operator used exclusively in a window specification. -
PRECEDING_OPERATOR
The PRECEDING operator used exclusively in a window specification.
-
-
Constructor Details
-
SqlWindow
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) Creates a window. -
SqlWindow
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, SqlLiteral exclude) Creates a window.
-
-
Method Details
-
create
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) -
create
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, SqlLiteral exclude, SqlParserPos pos) -
getOperator
- Specified by:
getOperator
in classSqlCall
-
getKind
Description copied from class:SqlNode
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special. -
getOperandList
Description copied from class:SqlCall
Returns the list of operands. The set and order of operands is call-specific.Note: the proper type would be
List<@Nullable SqlNode>
, however, it would trigger too many changes to the current codebase.- Specified by:
getOperandList
in classSqlCall
- Returns:
- the list of call operands, never null, the operands can be null
-
setOperand
Description copied from class:SqlCall
Changes the value of an operand. Allows some rewrite bySqlValidator
; use sparingly.- Overrides:
setOperand
in classSqlCall
- Parameters:
i
- Operand indexoperand
- Operand value
-
unparse
Description copied from class:SqlNode
Writes a SQL representation of this node to a writer.The
leftPrec
andrightPrec
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)
. -
getDeclName
-
setDeclName
-
getLowerBound
-
setLowerBound
-
getUpperBound
-
setUpperBound
-
getExclude
-
isAlwaysNonEmpty
public boolean isAlwaysNonEmpty()Returns if the window is guaranteed to have rows. This is useful to refine data type of window aggregates. For instance sum(non-nullable) over (empty window) is NULL.- Returns:
- true when the window is non-empty
- See Also:
-
isAlwaysNonEmpty
-
setRows
-
isRows
@Pure public boolean isRows() -
getOrderList
-
setOrderList
-
getPartitionList
-
setPartitionList
-
getRefName
-
setWindowCall
-
getWindowCall
-
createExcludeNoOthers
-
createExcludeCurrentRow
-
createExcludeTies
-
createExcludeGroup
-
isExcludeNoOthers
-
isExcludeCurrentRow
-
isExcludeGroup
-
isExcludeTies
-
createCurrentRow
-
createUnboundedFollowing
-
createUnboundedPreceding
-
createFollowing
-
createPreceding
-
createBound
-
isCurrentRow
Returns whether an expression represents the "CURRENT ROW" bound. -
isUnboundedPreceding
Returns whether an expression represents the "UNBOUNDED PRECEDING" bound. -
isUnboundedFollowing
Returns whether an expression represents the "UNBOUNDED FOLLOWING" bound. -
overlay
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
-
equalsDeep
Overridden method to specifically check only the right subtree of a window definition.- Overrides:
equalsDeep
in classSqlCall
- Parameters:
node
- The SqlWindow to compare to "this" windowlitmus
- What to do if an error is detected (nodes are not equal)- Returns:
- boolean true if all nodes in the subtree are equal
-
isAllowPartial
@EnsuresNonNullIf(expression="allowPartial", result=false) 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. -
validate
Description copied from class:SqlCall
Validates this call.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 exampleSqlSelect
andSqlUpdate
). -
createCurrentRowWindow
Creates a window(RANGE columnName CURRENT ROW)
.- Parameters:
columnName
- Order column
-
createUnboundedPrecedingWindow
Creates a window(RANGE columnName UNBOUNDED PRECEDING)
.- Parameters:
columnName
- Order column
-
populateBounds
Deprecated.
-