Package org.h2.expression.aggregate
Class Aggregate
java.lang.Object
org.h2.expression.Expression
org.h2.expression.analysis.DataAnalysisOperation
org.h2.expression.aggregate.AbstractAggregate
org.h2.expression.aggregate.Aggregate
- All Implemented Interfaces:
ExpressionWithFlags,HasSQL,Typed
Implements the integrated aggregate functions, such as COUNT, MAX, SUM.
-
Field Summary
Fields inherited from class org.h2.expression.aggregate.AbstractAggregate
args, distinct, filterCondition, typeFields 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
ConstructorsConstructorDescriptionAggregate(AggregateType aggregateType, Expression[] args, Select select, boolean distinct) Create a new aggregate object. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectCreate aggregate data object specific to the subclass.getAggregatedValue(SessionLocal session, Object aggregateData) Returns aggregated value.Returns the type of this aggregate.static AggregateTypegetAggregateType(String name) Get the aggregate type for this name, or -1 if no aggregate has been found.intgetCost()Estimate the cost to process the expression.Returns the additional arguments.intgetFlags()Returns the flags.protected intReturns the number of expressions, excluding OVER clause.Returns the select statement.getUnenclosedSQL(StringBuilder builder, int sqlFlags) Get the SQL statement of this expression.getValue(SessionLocal session) Return the resulting value for the current row.booleanReturns if distinct is used.booleanisEverything(ExpressionVisitor visitor) Check if this expression and all sub-expressions can fulfill a criteria.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.voidsetExtraArguments(Object extraArguments) Sets the additional arguments.voidsetFlags(int flags) Set the flags for this expression.voidsetOrderByList(ArrayList<QueryOrderBy> orderByList) Set the order for ARRAY_AGG() or GROUP_CONCAT() aggregate.protected voidupdateAggregate(SessionLocal session, Object aggregateData) Updates an aggregate value.protected voidupdateFromExpressions(SessionLocal session, 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.aggregate.AbstractAggregate
appendTailConditions, getFilterCondition, getOrderedResultLoop, getSubexpression, getSubexpressionCount, getType, isAggregate, setFilterCondition, updateAggregateMethods inherited from class org.h2.expression.analysis.DataAnalysisOperation
createOrder, getGroupData, getOverCondition, getOverOrderBySort, getWindowData, 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, 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
-
Aggregate
Create a new aggregate object.- Parameters:
aggregateType- the aggregate typeargs- the aggregated expressionsselect- the select statementdistinct- if distinct is used
-
-
Method Details
-
getAggregateType
Get the aggregate type for this name, or -1 if no aggregate has been found.- Parameters:
name- the aggregate function name- Returns:
- null if no aggregate function has been found, or the aggregate type
-
setOrderByList
Set the order for ARRAY_AGG() or GROUP_CONCAT() aggregate.- Parameters:
orderByList- the order by list
-
getAggregateType
Returns the type of this aggregate.- Returns:
- the type of this aggregate
-
setExtraArguments
Sets the additional arguments.- Parameters:
extraArguments- the additional arguments
-
getExtraArguments
Returns the additional arguments.- Returns:
- the additional arguments
-
setFlags
public void setFlags(int flags) Description copied from interface:ExpressionWithFlagsSet the flags for this expression.- Specified by:
setFlagsin interfaceExpressionWithFlags- Parameters:
flags- the flags to set
-
getFlags
public int getFlags()Description copied from interface:ExpressionWithFlagsReturns the flags.- Specified by:
getFlagsin interfaceExpressionWithFlags- Returns:
- the flags
-
updateAggregate
Description copied from class:AbstractAggregateUpdates an aggregate value.- Specified by:
updateAggregatein classAbstractAggregate- Parameters:
session- the sessionaggregateData- aggregate data
-
updateGroupAggregates
Description copied from class:DataAnalysisOperationInvoked when processing group stage of grouped window queries to update arguments of this aggregate.- Overrides:
updateGroupAggregatesin classAbstractAggregate- 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
-
updateFromExpressions
Description copied from class:AbstractAggregateUpdates the provided aggregate data from the remembered expressions.- Specified by:
updateFromExpressionsin classAbstractAggregate- Parameters:
session- the sessionaggregateData- aggregate dataarray- 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.
-
getValue
Description copied from class:ExpressionReturn the resulting value for the current row.- Overrides:
getValuein classDataAnalysisOperation- Parameters:
session- the session- Returns:
- the result
-
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 classAbstractAggregate- 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 classAbstractAggregate- 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 classAbstractAggregate- Parameters:
tableFilter- the table filterb- true if the table filter can return value
-
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
-
isEverything
Description copied from class:ExpressionCheck if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.- Overrides:
isEverythingin classDataAnalysisOperation- Parameters:
visitor- the visitor- Returns:
- if the criteria can be fulfilled
-
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
-
getSelect
Returns the select statement.- Returns:
- the select statement
-
isDistinct
public boolean isDistinct()Returns if distinct is used.- Returns:
- if distinct is used
-