org.h2.expression.analysis

## Class WindowFunction

- java.lang.Object
- - org.h2.expression.Expression
  - - org.h2.expression.analysis.DataAnalysisOperation
    - - org.h2.expression.analysis.WindowFunction

    public class WindowFunction
    extends DataAnalysisOperation

A window function.

### Field Summary

### Fields inherited from class org.h2.expression.analysis.DataAnalysisOperation

`over, overOrderBySort, select, STAGE_GROUP, STAGE_RESET, STAGE_WINDOW`

### Fields inherited from class org.h2.expression.Expression

`MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL`

### Constructor Summary

Constructors
Constructor and Description
`WindowFunction(WindowFunctionType type, Select select, Expression[] args)` Creates new instance of a window function.

### Method Summary

Methods
`protected java.lang.Object` `createAggregateData()` Create aggregate data object specific to the subclass.
`protected Value` `getAggregatedValue(Session session, java.lang.Object aggregateData)` Returns aggregated value.
`int` `getCost()` Estimate the cost to process the expression.
`WindowFunctionType` `getFunctionType()` Returns the type of this function.
`static int` `getMaxArgumentCount(WindowFunctionType type)` Returns maximal number of arguments for the specified type.
`static int` `getMinArgumentCount(WindowFunctionType type)` Returns minimal number of arguments for the specified type.
`protected int` `getNumExpressions()` Returns the number of expressions, excluding OVER clause.
`protected void` `getOrderedResultLoop(Session session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn)` Returns result of this window function or window aggregate.
`java.lang.StringBuilder` `getSQL(java.lang.StringBuilder builder, boolean alwaysQuote)` Appends the SQL statement of this expression to the specified builder.
`TypeInfo` `getType()` Returns the data type.
`boolean` `isAggregate()` Checks whether this expression is an aggregate function.
`void` `mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState)` Map the columns of the resolver to expression columns.
`Expression` `optimize(Session session)` Try to optimize the expression.
`protected void` `rememberExpressions(Session session, Value[] array)` Stores current values of expressions into the specified array.
`void` `setEvaluatable(TableFilter tableFilter, boolean b)` Tell the expression columns whether the table filter can return values now.
`void` `setFromLast(boolean fromLast)` Sets FROM FIRST or FROM LAST clause value.
`void` `setIgnoreNulls(boolean ignoreNulls)` Sets RESPECT NULLS or IGNORE NULLS clause value.
`protected void` `updateAggregate(Session session, SelectGroups groupData, int groupRowId)` Update a row of an aggregate.
`protected void` `updateGroupAggregates(Session 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, getOverOrderBySort, getValue, getWindowData, isEverything, mapColumns, setOverCondition, updateAggregate, updateOrderedAggregate`

### Methods inherited from class org.h2.expression.Expression

`addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getExpressionColumns, getExpressionColumns, getExpressionColumns, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSubexpression, getSubexpressionCount, getTableAlias, getTableName, getUnenclosedSQL, isAutoIncrement, isConstant, isGeneratedKey, isValueSet, toString, writeExpressions, writeExpressions`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### WindowFunction

    public WindowFunction(WindowFunctionType type,
                  Select select,
                  Expression[] args)

Creates new instance of a window function.

Parameters:
  `type` - the type
  `select` - the select statement
  `args` - arguments, or null

### Method Detail

#### getMinArgumentCount

    public static int getMinArgumentCount(WindowFunctionType type)

Returns minimal number of arguments for the specified type.

Parameters:
  `type` - the type of a window function
Returns:
  minimal number of arguments

#### getMaxArgumentCount

    public static int getMaxArgumentCount(WindowFunctionType type)

Returns maximal number of arguments for the specified type.

Parameters:
  `type` - the type of a window function
Returns:
  maximal number of arguments

#### getFunctionType

    public WindowFunctionType 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: `DataAnalysisOperation`
Checks whether this expression is an aggregate function.

Specified by:
  `isAggregate` in class `DataAnalysisOperation`
Returns:
  true if this is an aggregate function (including aggregates with OVER clause), false if this is a window function

#### updateAggregate

    protected void updateAggregate(Session session,
                       SelectGroups groupData,
                       int groupRowId)

Description copied from class: `DataAnalysisOperation`
Update a row of an aggregate.

Specified by:
  `updateAggregate` in class `DataAnalysisOperation`
Parameters:
  `session` - the database session
  `groupData` - data for the aggregate group
  `groupRowId` - row id of group

#### updateGroupAggregates

    protected void updateGroupAggregates(Session session,
                             int stage)

Description copied from class: `DataAnalysisOperation`
Invoked when processing group stage of grouped window queries to update arguments of this aggregate.

Overrides:
  `updateGroupAggregates` in class `DataAnalysisOperation`
Parameters:
  `session` - the session
  `stage` - select stage

#### getNumExpressions

    protected int getNumExpressions()

Description copied from class: `DataAnalysisOperation`
Returns the number of expressions, excluding OVER clause.

Specified by:
  `getNumExpressions` in class `DataAnalysisOperation`
Returns:
  the number of expressions

#### rememberExpressions

    protected void rememberExpressions(Session session,
                           Value[] array)

Description copied from class: `DataAnalysisOperation`
Stores current values of expressions into the specified array.

Specified by:
  `rememberExpressions` in class `DataAnalysisOperation`
Parameters:
  `session` - the session
  `array` - array to store values of expressions

#### createAggregateData

    protected java.lang.Object createAggregateData()

Description copied from class: `DataAnalysisOperation`
Create aggregate data object specific to the subclass.

Specified by:
  `createAggregateData` in class `DataAnalysisOperation`
Returns:
  aggregate-specific data object.

#### getOrderedResultLoop

    protected void getOrderedResultLoop(Session session,
                            java.util.HashMap<java.lang.Integer,Value> result,
                            java.util.ArrayList<Value[]> ordered,
                            int rowIdColumn)

Description copied from class: `DataAnalysisOperation`
Returns result of this window function or window aggregate. This method may not be called on window aggregate without window order clause.

Specified by:
  `getOrderedResultLoop` in class `DataAnalysisOperation`
Parameters:
  `session` - the session
  `result` - the map to append result to
  `ordered` - ordered data
  `rowIdColumn` - the index of row id value

#### getAggregatedValue

    protected Value getAggregatedValue(Session session,
                           java.lang.Object aggregateData)

Description copied from class: `DataAnalysisOperation`
Returns aggregated value.

Specified by:
  `getAggregatedValue` in class `DataAnalysisOperation`
Parameters:
  `session` - the session
  `aggregateData` - the aggregate data
Returns:
  aggregated value.

#### mapColumnsAnalysis

    public void mapColumnsAnalysis(ColumnResolver resolver,
                          int level,
                          int innerState)

Description copied from class: `DataAnalysisOperation`
Map the columns of the resolver to expression columns.

Overrides:
  `mapColumnsAnalysis` in class `DataAnalysisOperation`
Parameters:
  `resolver` - the column resolver
  `level` - the subquery nesting level
  `innerState` - one of the Expression MAP_IN_* values

#### optimize

    public Expression optimize(Session session)

Description copied from class: `Expression`
Try to optimize the expression.

Overrides:
  `optimize` in class `DataAnalysisOperation`
Parameters:
  `session` - the session
Returns:
  the optimized expression

#### setEvaluatable

    public void setEvaluatable(TableFilter tableFilter,
                      boolean b)

Description copied from class: `Expression`
Tell the expression columns whether the table filter can return values now. This is used when optimizing the query.

Overrides:
  `setEvaluatable` in class `DataAnalysisOperation`
Parameters:
  `tableFilter` - the table filter
  `b` - true if the table filter can return value

#### getType

    public TypeInfo getType()

Description copied from class: `Expression`
Returns the data type. The data type may not be known before the optimization phase.

Specified by:
  `getType` in class `Expression`
Returns:
  the data type

#### getSQL

    public java.lang.StringBuilder getSQL(java.lang.StringBuilder builder,
                                 boolean alwaysQuote)

Description copied from class: `Expression`
Appends the SQL statement of this expression to the specified builder. This may not always be the original SQL statement, specially after optimization.

Specified by:
  `getSQL` in class `Expression`
Parameters:
  `builder` - string builder
  `alwaysQuote` - quote all identifiers
Returns:
  the specified string builder

#### getCost

    public int getCost()

Description copied from class: `Expression`
Estimate the cost to process the expression. Used when optimizing the query, to calculate the query plan with the lowest estimated cost.

Specified by:
  `getCost` in class `Expression`
Returns:
  the estimated cost