org.h2.expression.aggregate

## Class JavaAggregate

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

    public class JavaAggregate
    extends AbstractAggregate

This class wraps a user-defined aggregate.

### Field Summary

### Fields inherited from class org.h2.expression.aggregate.AbstractAggregate

`args, distinct, filterCondition, type`

### 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
`JavaAggregate(UserAggregate userAggregate, Expression[] args, Select select, boolean distinct)`

### Method Summary

Methods
`protected java.lang.Object` `createAggregateData()` Create aggregate data object specific to the subclass.
`Value` `getAggregatedValue(Session session, java.lang.Object aggregateData)` Returns aggregated value.
`int` `getCost()` Estimate the cost to process the expression.
`protected int` `getNumExpressions()` Returns the number of expressions, excluding OVER clause.
`java.lang.StringBuilder` `getSQL(java.lang.StringBuilder builder, boolean alwaysQuote)` Appends the SQL statement of this expression to the specified builder.
`boolean` `isEverything(ExpressionVisitor visitor)` Check if this expression and all sub-expressions can fulfill a criteria.
`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.
`protected void` `updateAggregate(Session session, java.lang.Object aggregateData)` Updates an aggregate value.
`protected 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.aggregate.AbstractAggregate

`appendTailConditions, getOrderedResultLoop, getType, isAggregate, mapColumnsAnalysis, setEvaluatable, setFilterCondition, updateAggregate`

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

`createOrder, getGroupData, getOverOrderBySort, getValue, getWindowData, 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

#### JavaAggregate

    public JavaAggregate(UserAggregate userAggregate,
                 Expression[] args,
                 Select select,
                 boolean distinct)

### Method Detail

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

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

#### isEverything

    public boolean isEverything(ExpressionVisitor visitor)

Description copied from class: `Expression`
Check if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.

Overrides:
  `isEverything` in class `DataAnalysisOperation`
Parameters:
  `visitor` - the visitor
Returns:
  if the criteria can be fulfilled

#### optimize

    public Expression optimize(Session session)

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

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

#### getAggregatedValue

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

#### updateAggregate

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

Description copied from class: `AbstractAggregate`
Updates an aggregate value.

Specified by:
  `updateAggregate` in class `AbstractAggregate`
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 `AbstractAggregate`
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

#### updateFromExpressions

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

Description copied from class: `AbstractAggregate`
Updates the provided aggregate data from the remembered expressions.

Specified by:
  `updateFromExpressions` in class `AbstractAggregate`
Parameters:
  `session` - the session
  `aggregateData` - aggregate data
  `array` - 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.