Package org.h2.expression.analysis
Class WindowFunction
java.lang.Object
org.h2.expression.Expression
org.h2.expression.analysis.DataAnalysisOperation
org.h2.expression.analysis.WindowFunction
A window function.
-
Field Summary
Fields inherited from class org.h2.expression.analysis.DataAnalysisOperation
over, overOrderBySort, select, STAGE_GROUP, STAGE_RESET, STAGE_WINDOWFields inherited from class org.h2.expression.Expression
AUTO_PARENTHESES, MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL, WITH_PARENTHESES, WITHOUT_PARENTHESESFields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS -
Constructor Summary
ConstructorsConstructorDescriptionWindowFunction(WindowFunctionType type, Select select, Expression[] args) Creates new instance of a window function. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectCreate aggregate data object specific to the subclass.protected ValuegetAggregatedValue(SessionLocal session, Object aggregateData) Returns aggregated value.intgetCost()Estimate the cost to process the expression.Returns the type of this function.static intReturns maximal number of arguments for the specified type.static intReturns minimal number of arguments for the specified type.protected intReturns the number of expressions, excluding OVER clause.protected voidgetOrderedResultLoop(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn) Returns result of this window function or window aggregate.getType()Returns the data type.getUnenclosedSQL(StringBuilder builder, int sqlFlags) Get the SQL statement of this expression.booleanChecks whether this expression is an aggregate function.voidmapColumnsAnalysis(ColumnResolver resolver, int level, int innerState) Map the columns of the resolver to expression columns.optimize(SessionLocal session) Try to optimize the expression.protected voidrememberExpressions(SessionLocal session, Value[] array) Stores current values of expressions into the specified array.voidsetEvaluatable(TableFilter tableFilter, boolean b) Tell the expression columns whether the table filter can return values now.voidsetFromLast(boolean fromLast) Sets FROM FIRST or FROM LAST clause value.voidsetIgnoreNulls(boolean ignoreNulls) Sets RESPECT NULLS or IGNORE NULLS clause value.protected voidupdateAggregate(SessionLocal session, SelectGroups groupData, int groupRowId) Update a row of an aggregate.protected voidupdateGroupAggregates(SessionLocal session, int stage) Invoked when processing group stage of grouped window queries to update arguments of this aggregate.Methods inherited from class org.h2.expression.analysis.DataAnalysisOperation
appendTailConditions, createOrder, getGroupData, getOverCondition, getOverOrderBySort, getValue, getWindowData, isEverything, mapColumns, setOverCondition, updateAggregate, updateOrderedAggregateMethods inherited from class org.h2.expression.Expression
addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getColumnNameForView, getEnclosedSQL, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSQL, getSQL, getSQL, getSubexpression, getSubexpressionCount, getTableAlias, getTableName, getTypeIfStaticallyKnown, getWhenSQL, getWhenValue, isConstant, isIdentity, isNullConstant, isValueSet, isWhenConditionOperand, needParentheses, optimizeCondition, toString, writeExpressions, writeExpressionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
Constructor Details
-
WindowFunction
Creates new instance of a window function.- Parameters:
type- the typeselect- the select statementargs- arguments, or null
-
-
Method Details
-
getMinArgumentCount
Returns minimal number of arguments for the specified type.- Parameters:
type- the type of a window function- Returns:
- minimal number of arguments
-
getMaxArgumentCount
Returns maximal number of arguments for the specified type.- Parameters:
type- the type of a window function- Returns:
- maximal number of arguments
-
getFunctionType
Returns the type of this function.- Returns:
- the type of this function
-
setFromLast
public void setFromLast(boolean fromLast) Sets FROM FIRST or FROM LAST clause value.- Parameters:
fromLast- whether FROM LAST clause was specified.
-
setIgnoreNulls
public void setIgnoreNulls(boolean ignoreNulls) Sets RESPECT NULLS or IGNORE NULLS clause value.- Parameters:
ignoreNulls- whether IGNORE NULLS clause was specified
-
isAggregate
public boolean isAggregate()Description copied from class:DataAnalysisOperationChecks whether this expression is an aggregate function.- Specified by:
isAggregatein classDataAnalysisOperation- Returns:
- true if this is an aggregate function (including aggregates with OVER clause), false if this is a window function
-
updateAggregate
Description copied from class:DataAnalysisOperationUpdate a row of an aggregate.- Specified by:
updateAggregatein classDataAnalysisOperation- Parameters:
session- the database sessiongroupData- data for the aggregate groupgroupRowId- row id of group
-
updateGroupAggregates
Description copied from class:DataAnalysisOperationInvoked when processing group stage of grouped window queries to update arguments of this aggregate.- Overrides:
updateGroupAggregatesin classDataAnalysisOperation- Parameters:
session- the sessionstage- select stage
-
getNumExpressions
protected int getNumExpressions()Description copied from class:DataAnalysisOperationReturns the number of expressions, excluding OVER clause.- Specified by:
getNumExpressionsin classDataAnalysisOperation- Returns:
- the number of expressions
-
rememberExpressions
Description copied from class:DataAnalysisOperationStores current values of expressions into the specified array.- Specified by:
rememberExpressionsin classDataAnalysisOperation- Parameters:
session- the sessionarray- array to store values of expressions
-
createAggregateData
Description copied from class:DataAnalysisOperationCreate aggregate data object specific to the subclass.- Specified by:
createAggregateDatain classDataAnalysisOperation- Returns:
- aggregate-specific data object.
-
getOrderedResultLoop
protected void getOrderedResultLoop(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn) Description copied from class:DataAnalysisOperationReturns result of this window function or window aggregate. This method may not be called on window aggregate without window order clause.- Specified by:
getOrderedResultLoopin classDataAnalysisOperation- Parameters:
session- the sessionresult- the map to append result toordered- ordered datarowIdColumn- the index of row id value
-
getAggregatedValue
Description copied from class:DataAnalysisOperationReturns aggregated value.- Specified by:
getAggregatedValuein classDataAnalysisOperation- Parameters:
session- the sessionaggregateData- the aggregate data- Returns:
- aggregated value.
-
mapColumnsAnalysis
Description copied from class:DataAnalysisOperationMap the columns of the resolver to expression columns.- Overrides:
mapColumnsAnalysisin classDataAnalysisOperation- Parameters:
resolver- the column resolverlevel- the subquery nesting levelinnerState- one of the Expression MAP_IN_* values
-
optimize
Description copied from class:ExpressionTry to optimize the expression.- Overrides:
optimizein classDataAnalysisOperation- Parameters:
session- the session- Returns:
- the optimized expression
-
setEvaluatable
Description copied from class:ExpressionTell the expression columns whether the table filter can return values now. This is used when optimizing the query.- Overrides:
setEvaluatablein classDataAnalysisOperation- Parameters:
tableFilter- the table filterb- true if the table filter can return value
-
getType
Description copied from class:ExpressionReturns the data type. The data type may be unknown before the optimization phase.- Specified by:
getTypein interfaceTyped- Specified by:
getTypein classExpression- Returns:
- the data type
-
getUnenclosedSQL
Description copied from class:ExpressionGet the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.- Specified by:
getUnenclosedSQLin classExpression- Parameters:
builder- string buildersqlFlags- formatting flags- Returns:
- the specified string builder
-
getCost
public int getCost()Description copied from class:ExpressionEstimate the cost to process the expression. Used when optimizing the query, to calculate the query plan with the lowest estimated cost.- Specified by:
getCostin classExpression- Returns:
- the estimated cost
-