org.h2.expression.aggregate

## Class AbstractAggregate

- java.lang.Object
- - org.h2.expression.Expression
  - - org.h2.expression.analysis.DataAnalysisOperation
    - - org.h2.expression.aggregate.AbstractAggregate

Direct Known Subclasses:
  Aggregate, JavaAggregate

    public abstract class AbstractAggregate
    extends DataAnalysisOperation

A base class for aggregate functions.

### Field Summary

Fields
`protected Expression[]` `args` The arguments.
`protected boolean` `distinct` is this a DISTINCT aggregate
`protected Expression` `filterCondition` FILTER condition for aggregate
`protected TypeInfo` `type` The type of the result.

### 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`

### Method Summary

Methods
`protected java.lang.StringBuilder` `appendTailConditions(java.lang.StringBuilder builder, boolean alwaysQuote)` Used to create SQL for the OVER and FILTER clauses.
`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.
`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.
`void` `setEvaluatable(TableFilter tableFilter, boolean b)` Tell the expression columns whether the table filter can return values now.
`void` `setFilterCondition(Expression filterCondition)` Sets the FILTER condition.
`protected abstract void` `updateAggregate(Session session, java.lang.Object aggregateData)` Updates an aggregate value.
`protected void` `updateAggregate(Session session, SelectGroups groupData, int groupRowId)` Update a row of an aggregate.
`protected abstract void` `updateFromExpressions(Session session, java.lang.Object aggregateData, Value[] array)` Updates the provided aggregate data from the remembered expressions.
`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

`createAggregateData, createOrder, getAggregatedValue, getGroupData, getNumExpressions, getOverOrderBySort, getValue, getWindowData, isEverything, mapColumns, rememberExpressions, setOverCondition, updateAggregate, updateOrderedAggregate`

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

`addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getCost, getExpressionColumns, getExpressionColumns, getExpressionColumns, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, 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`

### Field Detail

#### distinct

    protected final boolean distinct

is this a DISTINCT aggregate

#### args

    protected final Expression[] args

The arguments.

#### filterCondition

    protected Expression filterCondition

FILTER condition for aggregate

#### type

    protected TypeInfo type

The type of the result.

### Method Detail

#### isAggregate

    public final 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

#### setFilterCondition

    public void setFilterCondition(Expression filterCondition)

Sets the FILTER condition.

Parameters:
  `filterCondition` - FILTER condition

#### 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

#### 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

#### 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

#### updateFromExpressions

    protected abstract void updateFromExpressions(Session session,
                             java.lang.Object aggregateData,
                             Value[] array)

Updates the provided aggregate data from the remembered expressions.

Parameters:
  `session` - the session
  `aggregateData` - aggregate data
  `array` - values of expressions

#### 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

#### updateAggregate

    protected abstract void updateAggregate(Session session,
                       java.lang.Object aggregateData)

Updates an aggregate value.

Parameters:
  `session` - the session
  `aggregateData` - aggregate data

#### 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

#### appendTailConditions

    protected java.lang.StringBuilder appendTailConditions(java.lang.StringBuilder builder,
                                               boolean alwaysQuote)

Description copied from class: `DataAnalysisOperation`
Used to create SQL for the OVER and FILTER clauses.

Overrides:
  `appendTailConditions` in class `DataAnalysisOperation`
Parameters:
  `builder` - string builder
  `alwaysQuote` - quote all identifiers
Returns:
  the builder object