Package org.h2.command.query
Class SelectGroups
- java.lang.Object
-
- org.h2.command.query.SelectGroups
-
- Direct Known Subclasses:
SelectGroups.Grouped,SelectGroups.Plain
public abstract class SelectGroups extends java.lang.ObjectGrouped data for aggregates.Call sequence:
reset().- For each source row
nextSource()should be invoked. done().next()is invoked inside a loop until it returns null.
Call sequence for lazy group sorted result:
resetLazy()(not required before the first execution).- For each source group
nextLazyGroup()should be invoked. - For each source row
nextLazyRow()should be invoked. Each group can have one or more rows.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSelectGroups.Groupedprivate static classSelectGroups.Plain
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Object[]currentGroupByExprDataThe array of current group-by expression data e.g.(package private) intcurrentGroupRowIdThe id of the current group.(package private) java.util.ArrayList<Expression>expressionsThe query's column list, including invisible expressions such as order by expressions.private java.util.HashMap<Expression,java.lang.Integer>exprToIndexInGroupByDataMaps an expression object to an index, to use in accessing the Object[] pointed to by groupByData.(package private) SessionLocalsessionThe database session.private java.util.HashMap<DataAnalysisOperation,PartitionData>windowDataMaps an window expression object to its data.private java.util.HashMap<DataAnalysisOperation,java.util.TreeMap<Value,PartitionData>>windowPartitionDataMaps an partitioned window expression object to its data.
-
Constructor Summary
Constructors Constructor Description SelectGroups(SessionLocal session, java.util.ArrayList<Expression> expressions)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.Object[]createRow()Creates new object arrays to holds group-by data.voiddone()Invoked after all source rows are evaluated.java.lang.ObjectgetCurrentGroupExprData(Expression expr)Get the group-by data for the current group and the passed in expression.intgetCurrentGroupRowId()Returns identity of the current row.static SelectGroupsgetInstance(SessionLocal session, java.util.ArrayList<Expression> expressions, boolean isGroupQuery, int[] groupIndex)Creates new instance of grouped data.PartitionDatagetWindowExprData(DataAnalysisOperation expr, Value partitionKey)Get the window data for the specified expression.booleanisCurrentGroup()Is there currently a group-by active.abstract ValueRownext()Returns the key of the next group.voidnextLazyGroup()Moves group data to the next group in lazy mode.voidnextLazyRow()Moves group data to the next row in lazy mode.abstract voidnextSource()Invoked for each source row to evaluate group key and setup all necessary data for aggregates.voidremove()Removes the data for the current key.voidreset()Resets this group data for reuse.voidresetLazy()Resets this group data for reuse in lazy mode.voidsetCurrentGroupExprData(Expression expr, java.lang.Object obj)Set the group-by data for the current group and the passed in expression.voidsetWindowExprData(DataAnalysisOperation expr, Value partitionKey, PartitionData obj)Set the window data for the specified expression.(package private) abstract voidupdateCurrentGroupExprData()Update group-by data specified by implementation.
-
-
-
Field Detail
-
session
final SessionLocal session
The database session.
-
expressions
final java.util.ArrayList<Expression> expressions
The query's column list, including invisible expressions such as order by expressions.
-
currentGroupByExprData
java.lang.Object[] currentGroupByExprData
The array of current group-by expression data e.g. AggregateData.
-
exprToIndexInGroupByData
private final java.util.HashMap<Expression,java.lang.Integer> exprToIndexInGroupByData
Maps an expression object to an index, to use in accessing the Object[] pointed to by groupByData.
-
windowData
private final java.util.HashMap<DataAnalysisOperation,PartitionData> windowData
Maps an window expression object to its data.
-
windowPartitionData
private final java.util.HashMap<DataAnalysisOperation,java.util.TreeMap<Value,PartitionData>> windowPartitionData
Maps an partitioned window expression object to its data.
-
currentGroupRowId
int currentGroupRowId
The id of the current group.
-
-
Constructor Detail
-
SelectGroups
SelectGroups(SessionLocal session, java.util.ArrayList<Expression> expressions)
-
-
Method Detail
-
getInstance
public static SelectGroups getInstance(SessionLocal session, java.util.ArrayList<Expression> expressions, boolean isGroupQuery, int[] groupIndex)
Creates new instance of grouped data.- Parameters:
session- the sessionexpressions- the expressionsisGroupQuery- is this query is a group querygroupIndex- the indexes of group expressions, or null- Returns:
- new instance of the grouped data.
-
isCurrentGroup
public boolean isCurrentGroup()
Is there currently a group-by active.- Returns:
trueif there is currently a group-by active, otherwise returnsfalse.
-
getCurrentGroupExprData
public final java.lang.Object getCurrentGroupExprData(Expression expr)
Get the group-by data for the current group and the passed in expression.- Parameters:
expr- expression- Returns:
- expression data or null
-
setCurrentGroupExprData
public final void setCurrentGroupExprData(Expression expr, java.lang.Object obj)
Set the group-by data for the current group and the passed in expression.- Parameters:
expr- expressionobj- expression data to set
-
createRow
final java.lang.Object[] createRow()
Creates new object arrays to holds group-by data.- Returns:
- new object array to holds group-by data.
-
getWindowExprData
public final PartitionData getWindowExprData(DataAnalysisOperation expr, Value partitionKey)
Get the window data for the specified expression.- Parameters:
expr- expressionpartitionKey- a key of partition- Returns:
- expression data or null
-
setWindowExprData
public final void setWindowExprData(DataAnalysisOperation expr, Value partitionKey, PartitionData obj)
Set the window data for the specified expression.- Parameters:
expr- expressionpartitionKey- a key of partitionobj- window expression data to set
-
updateCurrentGroupExprData
abstract void updateCurrentGroupExprData()
Update group-by data specified by implementation.
-
getCurrentGroupRowId
public int getCurrentGroupRowId()
Returns identity of the current row. Used by aggregates to check whether they already processed this row or not.- Returns:
- identity of the current row
-
reset
public void reset()
Resets this group data for reuse.
-
nextSource
public abstract void nextSource()
Invoked for each source row to evaluate group key and setup all necessary data for aggregates.
-
done
public void done()
Invoked after all source rows are evaluated.
-
next
public abstract ValueRow next()
Returns the key of the next group.- Returns:
- the key of the next group, or null
-
remove
public void remove()
Removes the data for the current key.- See Also:
next()
-
resetLazy
public void resetLazy()
Resets this group data for reuse in lazy mode.
-
nextLazyGroup
public void nextLazyGroup()
Moves group data to the next group in lazy mode.
-
nextLazyRow
public void nextLazyRow()
Moves group data to the next row in lazy mode.
-
-