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
FieldsModifier and TypeFieldDescriptionstatic final SqlPostfixOperatorThe FOLLOWING operator used exclusively in a window specification.static final SqlPostfixOperatorThe PRECEDING operator used exclusively in a window specification.Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos -
Constructor Summary
ConstructorsConstructorDescriptionSqlWindow(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 SqlWindowcreate(@Nullable SqlIdentifier declName, @Nullable SqlIdentifier refName, SqlNodeList partitionList, SqlNodeList orderList, SqlLiteral isRows, @Nullable SqlNode lowerBound, @Nullable SqlNode upperBound, @Nullable SqlLiteral allowPartial, SqlParserPos pos) static SqlWindowcreate(@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 SqlNodecreateBound(SqlLiteral range) static SqlNodecreateCurrentRowWindow(String columnName) Creates a window(RANGE columnName CURRENT ROW).static SqlLiteralstatic SqlLiteralstatic SqlLiteralstatic SqlLiteralstatic SqlNodecreateFollowing(SqlNode e, SqlParserPos pos) static SqlNodecreatePreceding(SqlNode e, SqlParserPos pos) static SqlNodestatic SqlNodecreateUnboundedPrecedingWindow(String columnName) Creates a window(RANGE columnName UNBOUNDED PRECEDING).booleanequalsDeep(@Nullable SqlNode node, Litmus litmus) Overridden method to specifically check only the right subtree of a window definition.@Nullable SqlIdentifiergetKind()Returns the type of node this is, orSqlKind.OTHERif it's nothing special.@Nullable SqlNodeReturns the list of operands.@Nullable SqlIdentifier@Nullable SqlNode@Nullable SqlCallbooleanReturns whether partial windows are allowed.booleanReturns if the window is guaranteed to have rows.static booleanisAlwaysNonEmpty(RexWindowBound lower, RexWindowBound upper) static booleanisCurrentRow(SqlNode node) Returns whether an expression represents the "CURRENT ROW" bound.static booleanstatic booleanisExcludeGroup(SqlLiteral node) static booleanisExcludeNoOthers(SqlLiteral node) static booleanisExcludeTies(SqlLiteral node) booleanisRows()static booleanisUnboundedFollowing(SqlNode node) Returns whether an expression represents the "UNBOUNDED FOLLOWING" bound.static booleanisUnboundedPreceding(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.voidDeprecated.voidsetDeclName(SqlIdentifier declName) voidsetLowerBound(@Nullable SqlNode lowerBound) voidsetOperand(int i, @Nullable SqlNode operand) Changes the value of an operand.voidsetOrderList(SqlNodeList orderList) voidsetPartitionList(SqlNodeList partitionList) voidsetRows(SqlLiteral isRows) voidsetUpperBound(@Nullable SqlNode upperBound) voidsetWindowCall(@Nullable SqlCall windowCall) voidWrites a SQL representation of this node to a writer.voidvalidate(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, operandCountMethods 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:
getOperatorin classSqlCall
-
getKind
Description copied from class:SqlNodeReturns the type of node this is, orSqlKind.OTHERif it's nothing special. -
getOperandList
Description copied from class:SqlCallReturns 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:
getOperandListin classSqlCall- Returns:
- the list of call operands, never null, the operands can be null
-
setOperand
Description copied from class:SqlCallChanges the value of an operand. Allows some rewrite bySqlValidator; use sparingly.- Overrides:
setOperandin classSqlCall- Parameters:
i- Operand indexoperand- Operand value
-
unparse
Description copied from class:SqlNodeWrites a SQL representation of this node to a writer.The
leftPrecandrightPrecparameters 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:
equalsDeepin 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:SqlCallValidates 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 exampleSqlSelectandSqlUpdate). -
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.
-