Top Description Fields Constructors Methods
org.h2.expression.aggregate

public abstract Class AbstractAggregate

extends DataAnalysisOperation
Class Inheritance
Known Direct Subclasses
org.h2.expression.aggregate.Aggregate, org.h2.expression.aggregate.JavaAggregate
Imports
java.util.ArrayList, .HashMap, .Iterator, org.h2.command.query.Select, .SelectGroups, org.h2.engine.SessionLocal, org.h2.expression.Expression, org.h2.expression.analysis.DataAnalysisOperation, .WindowFrame, .WindowFrameBound, .WindowFrameBoundType, .WindowFrameExclusion, .WindowFrameUnits, org.h2.table.ColumnResolver, .TableFilter, org.h2.value.TypeInfo, .Value

A base class for aggregate functions.

Field Summary

Modifier and TypeField and Description
protected final Expression[]
args

The arguments.

protected final boolean
distinct

is this a DISTINCT aggregate

protected Expression
filterCondition

FILTER condition for aggregate

protected TypeInfo
type

The type of the result.

Inherited from org.h2.expression.analysis.DataAnalysisOperation:
overoverOrderBySortselectSTAGE_GROUPSTAGE_RESETSTAGE_WINDOW

Constructor Summary

AccessConstructor and Description
pack-priv
AbstractAggregate(Select select, Expression[] args, boolean distinct)

Method Summary

Modifier and TypeMethod and Description
private void
aggregateFastPartition(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)

private void
aggregateFastPartitionInReverse(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)

private void
aggregateWholePartition(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)

protected StringBuilder
appendTailConditions(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
,
boolean
whether synthetic ORDER BY clause should be generated when it is missing
forceOrderBy
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.appendTailConditions.

Used to create SQL for the OVER and FILTER clauses.

private static boolean
public Expression

Returns:

the FILTER Condition
getFilterCondition
()

Returns the FILTER condition.

protected void
getOrderedResultLoop(SessionLocal
the session
session
,
HashMap<Integer, Value>
the map to append result to
result
,
ArrayList<Value[]>
ordered data
ordered
,
int
the index of row id value
rowIdColumn
)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getOrderedResultLoop.

Returns result of this window function or window aggregate.

public Expression
getSubexpression(int
0-based index
index
)

Overrides org.h2.expression.Expression.getSubexpression.

Returns subexpression with specified index.

public int
public TypeInfo
getType()

Implements abstract org.h2.expression.Expression.getType.

Implements org.h2.value.Typed.getType.

Returns the data type.

public final boolean
isAggregate()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.isAggregate.

Checks whether this expression is an aggregate function.

public void
mapColumnsAnalysis(ColumnResolver
the column resolver
resolver
,
int
the subquery nesting level
level
,
int
one of the Expression MAP_IN_* values
innerState
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.mapColumnsAnalysis.

Map the columns of the resolver to expression columns.

public Expression
optimize(SessionLocal
the session
session
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.optimize.

Try to optimize the expression.

private int
processGroup(HashMap<Integer, Value> result, Value r, ArrayList<Value[]> ordered, int rowIdColumn, int i, int size, boolean grouped)

public void
setEvaluatable(TableFilter
the table filter
tableFilter
,
boolean
true if the table filter can return value
b
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.setEvaluatable.

Tell the expression columns whether the table filter can return values now.

public void
setFilterCondition(Expression
FILTER condition
filterCondition
)

Sets the FILTER condition.

protected void
updateAggregate(SessionLocal
the database session
session
,
SelectGroups
data for the aggregate group
groupData
,
int
row id of group
groupRowId
)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.updateAggregate.

Update a row of an aggregate.

protected abstract void
updateAggregate(SessionLocal
the session
session
,
Object
aggregate data
aggregateData
)

Updates an aggregate value.

protected abstract void
updateFromExpressions(SessionLocal
the session
session
,
Object
aggregate data
aggregateData
,
Value[]
values of expressions
array
)

Updates the provided aggregate data from the remembered expressions.

protected void
updateGroupAggregates(SessionLocal
the session
session
,
int
select stage
stage
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.updateGroupAggregates.

Invoked when processing group stage of grouped window queries to update arguments of this aggregate.

Inherited from org.h2.expression.analysis.DataAnalysisOperation:
createAggregateDatacreateOrdergetAggregatedValuegetGroupDatagetNumExpressionsgetOverConditiongetOverOrderBySortgetValuegetWindowDataisEverythingmapColumnsrememberExpressionssetOverConditionupdateAggregateupdateOrderedAggregate

Field Detail

argsback to summary
protected final Expression[] args

The arguments.

distinctback to summary
protected final boolean distinct

is this a DISTINCT aggregate

filterConditionback to summary
protected Expression filterCondition

FILTER condition for aggregate

typeback to summary
protected TypeInfo type

The type of the result.

Constructor Detail

AbstractAggregateback to summary
pack-priv AbstractAggregate(Select select, Expression[] args, boolean distinct)

Method Detail

aggregateFastPartitionback to summary
private void aggregateFastPartition(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)
aggregateFastPartitionInReverseback to summary
private void aggregateFastPartitionInReverse(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn, boolean grouped)
aggregateWholePartitionback to summary
private void aggregateWholePartition(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)
appendTailConditionsback to summary
protected StringBuilder appendTailConditions(StringBuilder builder, int sqlFlags, boolean forceOrderBy)

Overrides org.h2.expression.analysis.DataAnalysisOperation.appendTailConditions.

Doc from org.h2.expression.analysis.DataAnalysisOperation.appendTailConditions.

Used to create SQL for the OVER and FILTER clauses.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

forceOrderBy:boolean

whether synthetic ORDER BY clause should be generated when it is missing

Returns:StringBuilder

the builder object

Annotations
@Override
checkVariableBoundsback to summary
private static boolean checkVariableBounds(WindowFrame frame, ArrayList<Value[]> ordered)
getFilterConditionback to summary
public Expression getFilterCondition()

Returns the FILTER condition.

Returns:Expression

the FILTER Condition

getOrderedResultLoopback to summary
protected void getOrderedResultLoop(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getOrderedResultLoop.

Doc from org.h2.expression.analysis.DataAnalysisOperation.getOrderedResultLoop.

Returns result of this window function or window aggregate. This method may not be called on window aggregate without window order clause.

Parameters
session:SessionLocal

the session

result:HashMap<Integer, Value>

the map to append result to

ordered:ArrayList<Value[]>

ordered data

rowIdColumn:int

the index of row id value

Annotations
@Override
getSubexpressionback to summary
public Expression getSubexpression(int index)

Overrides org.h2.expression.Expression.getSubexpression.

Doc from org.h2.expression.Expression.getSubexpression.

Returns subexpression with specified index.

Parameters
index:int

0-based index

Returns:Expression

subexpression with specified index, may be null

Annotations
@Override
getSubexpressionCountback to summary
public int getSubexpressionCount()

Overrides org.h2.expression.Expression.getSubexpressionCount.

Doc from org.h2.expression.Expression.getSubexpressionCount.

Returns count of subexpressions.

Returns:int

count of subexpressions

Annotations
@Override
getTypeback to summary
public TypeInfo getType()

Implements abstract org.h2.expression.Expression.getType.

Implements org.h2.value.Typed.getType.

Doc from org.h2.expression.Expression.getType.

Returns the data type. The data type may be unknown before the optimization phase.

Returns:TypeInfo

the data type

Annotations
@Override
isAggregateback to summary
public final boolean isAggregate()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.isAggregate.

Doc from org.h2.expression.analysis.DataAnalysisOperation.isAggregate.

Checks whether this expression is an aggregate function.

Returns:boolean

true if this is an aggregate function (including aggregates with OVER clause), false if this is a window function

Annotations
@Override
mapColumnsAnalysisback to summary
public void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState)

Overrides org.h2.expression.analysis.DataAnalysisOperation.mapColumnsAnalysis.

Doc from org.h2.expression.analysis.DataAnalysisOperation.mapColumnsAnalysis.

Map the columns of the resolver to expression columns.

Parameters
resolver:ColumnResolver

the column resolver

level:int

the subquery nesting level

innerState:int

one of the Expression MAP_IN_* values

Annotations
@Override
optimizeback to summary
public Expression optimize(SessionLocal session)

Overrides org.h2.expression.analysis.DataAnalysisOperation.optimize.

Doc from org.h2.expression.Expression.optimize.

Try to optimize the expression.

Parameters
session:SessionLocal

the session

Returns:Expression

the optimized expression

Annotations
@Override
processGroupback to summary
private int processGroup(HashMap<Integer, Value> result, Value r, ArrayList<Value[]> ordered, int rowIdColumn, int i, int size, boolean grouped)
setEvaluatableback to summary
public void setEvaluatable(TableFilter tableFilter, boolean b)

Overrides org.h2.expression.analysis.DataAnalysisOperation.setEvaluatable.

Doc from org.h2.expression.Expression.setEvaluatable.

Tell the expression columns whether the table filter can return values now. This is used when optimizing the query.

Parameters
tableFilter:TableFilter

the table filter

b:boolean

true if the table filter can return value

Annotations
@Override
setFilterConditionback to summary
public void setFilterCondition(Expression filterCondition)

Sets the FILTER condition.

Parameters
filterCondition:Expression

FILTER condition

updateAggregateback to summary
protected void updateAggregate(SessionLocal session, SelectGroups groupData, int groupRowId)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.updateAggregate.

Doc from org.h2.expression.analysis.DataAnalysisOperation.updateAggregate.

Update a row of an aggregate.

Parameters
session:SessionLocal

the database session

groupData:SelectGroups

data for the aggregate group

groupRowId:int

row id of group

Annotations
@Override
updateAggregateback to summary
protected abstract void updateAggregate(SessionLocal session, Object aggregateData)

Updates an aggregate value.

Parameters
session:SessionLocal

the session

aggregateData:Object

aggregate data

updateFromExpressionsback to summary
protected abstract void updateFromExpressions(SessionLocal session, Object aggregateData, Value[] array)

Updates the provided aggregate data from the remembered expressions.

Parameters
session:SessionLocal

the session

aggregateData:Object

aggregate data

array:Value[]

values of expressions

updateGroupAggregatesback to summary
protected void updateGroupAggregates(SessionLocal session, int stage)

Overrides org.h2.expression.analysis.DataAnalysisOperation.updateGroupAggregates.

Doc from org.h2.expression.analysis.DataAnalysisOperation.updateGroupAggregates.

Invoked when processing group stage of grouped window queries to update arguments of this aggregate.

Parameters
session:SessionLocal

the session

stage:int

select stage

Annotations
@Override