Package 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 Modifier and Type Field Description protected Expression[]argsThe arguments.protected booleandistinctis this a DISTINCT aggregateprotected ExpressionfilterConditionFILTER condition for aggregateprotected TypeInfotypeThe 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
AUTO_PARENTHESES, MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL, WITH_PARENTHESES, WITHOUT_PARENTHESES
-
Fields 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
Constructors Constructor Description AbstractAggregate(Select select, Expression[] args, boolean distinct)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidaggregateFastPartition(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)private voidaggregateFastPartitionInReverse(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)private voidaggregateWholePartition(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn)protected java.lang.StringBuilderappendTailConditions(java.lang.StringBuilder builder, int sqlFlags, boolean forceOrderBy)Used to create SQL for the OVER and FILTER clauses.private static booleancheckVariableBounds(WindowFrame frame, java.util.ArrayList<Value[]> ordered)protected voidgetOrderedResultLoop(SessionLocal 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.ExpressiongetSubexpression(int index)Returns subexpression with specified index.intgetSubexpressionCount()Returns count of subexpressions.TypeInfogetType()Returns the data type.booleanisAggregate()Checks whether this expression is an aggregate function.voidmapColumnsAnalysis(ColumnResolver resolver, int level, int innerState)Map the columns of the resolver to expression columns.Expressionoptimize(SessionLocal session)Try to optimize the expression.private intprocessGroup(java.util.HashMap<java.lang.Integer,Value> result, Value r, java.util.ArrayList<Value[]> ordered, int rowIdColumn, int i, int size, boolean grouped)voidsetEvaluatable(TableFilter tableFilter, boolean b)Tell the expression columns whether the table filter can return values now.voidsetFilterCondition(Expression filterCondition)Sets the FILTER condition.protected abstract voidupdateAggregate(SessionLocal session, java.lang.Object aggregateData)Updates an aggregate value.protected voidupdateAggregate(SessionLocal session, SelectGroups groupData, int groupRowId)Update a row of an aggregate.protected abstract voidupdateFromExpressions(SessionLocal session, java.lang.Object aggregateData, Value[] array)Updates the provided aggregate data from the remembered expressions.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
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, getColumnNameForView, getCost, getEnclosedSQL, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSQL, getSQL, getSQL, getTableAlias, getTableName, getUnenclosedSQL, getWhenSQL, getWhenValue, isConstant, isIdentity, isNullConstant, isValueSet, isWhenConditionOperand, needParentheses, optimizeCondition, toString, writeExpressions, writeExpressions
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
-
-
-
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.
-
-
Constructor Detail
-
AbstractAggregate
AbstractAggregate(Select select, Expression[] args, boolean distinct)
-
-
Method Detail
-
isAggregate
public final 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
-
setFilterCondition
public void setFilterCondition(Expression filterCondition)
Sets the FILTER condition.- Parameters:
filterCondition- FILTER condition
-
getType
public TypeInfo 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
-
mapColumnsAnalysis
public void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState)
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
public Expression optimize(SessionLocal session)
Description copied from class:ExpressionTry to optimize the expression.- Overrides:
optimizein classDataAnalysisOperation- Parameters:
session- the session- Returns:
- the optimized expression
-
setEvaluatable
public void setEvaluatable(TableFilter tableFilter, boolean b)
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
-
getOrderedResultLoop
protected void getOrderedResultLoop(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.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
-
checkVariableBounds
private static boolean checkVariableBounds(WindowFrame frame, java.util.ArrayList<Value[]> ordered)
-
aggregateFastPartition
private void aggregateFastPartition(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)
-
aggregateFastPartitionInReverse
private void aggregateFastPartitionInReverse(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)
-
processGroup
private int processGroup(java.util.HashMap<java.lang.Integer,Value> result, Value r, java.util.ArrayList<Value[]> ordered, int rowIdColumn, int i, int size, boolean grouped)
-
aggregateWholePartition
private void aggregateWholePartition(SessionLocal session, java.util.HashMap<java.lang.Integer,Value> result, java.util.ArrayList<Value[]> ordered, int rowIdColumn)
-
updateFromExpressions
protected abstract void updateFromExpressions(SessionLocal session, java.lang.Object aggregateData, Value[] array)
Updates the provided aggregate data from the remembered expressions.- Parameters:
session- the sessionaggregateData- aggregate dataarray- values of expressions
-
updateAggregate
protected void updateAggregate(SessionLocal session, SelectGroups groupData, int groupRowId)
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
-
updateAggregate
protected abstract void updateAggregate(SessionLocal session, java.lang.Object aggregateData)
Updates an aggregate value.- Parameters:
session- the sessionaggregateData- aggregate data
-
updateGroupAggregates
protected void updateGroupAggregates(SessionLocal session, int stage)
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
-
appendTailConditions
protected java.lang.StringBuilder appendTailConditions(java.lang.StringBuilder builder, int sqlFlags, boolean forceOrderBy)Description copied from class:DataAnalysisOperationUsed to create SQL for the OVER and FILTER clauses.- Overrides:
appendTailConditionsin classDataAnalysisOperation- Parameters:
builder- string buildersqlFlags- formatting flagsforceOrderBy- whether synthetic ORDER BY clause should be generated when it is missing- Returns:
- the builder object
-
getSubexpressionCount
public int getSubexpressionCount()
Description copied from class:ExpressionReturns count of subexpressions.- Overrides:
getSubexpressionCountin classExpression- Returns:
- count of subexpressions
-
getSubexpression
public Expression getSubexpression(int index)
Description copied from class:ExpressionReturns subexpression with specified index.- Overrides:
getSubexpressionin classExpression- Parameters:
index- 0-based index- Returns:
- subexpression with specified index, may be null
-
-