casacore
|
#include <TableParseGroupby.h>
Public Types | |
enum | GroupAggrType { GROUPBY , AGGR_FUNCS , ONLY_COUNTALL } |
Public Member Functions | |
void | handleGroupby (const std::vector< TableExprNode > &, Bool rollup) |
Keep the groupby expressions. | |
void | handleHaving (const TableExprNode &) |
Keep the having expression. | |
void | findGroupAggr (const Block< TableExprNode > &columnNodes, Bool isSelect) |
Find if groupby and/or aggregate functions are given. | |
Bool | isUsed () const |
Is GROUPBY and/or aggregation used? | |
Bool | isOnlyAggr () const |
Is only aggregation used? | |
uInt | size () const |
Get the number of aggregation ndes. | |
uInt | disableApplySelection () |
Disable applySelection for the column nodes of aggregate functions. | |
std::shared_ptr< TableExprGroupResult > | execGroupAggr (Vector< rownr_t > &rownrs) const |
Execute the grouping and aggregation and return the results. | |
Bool | execHaving (Vector< rownr_t > &rownrs, const std::shared_ptr< TableExprGroupResult > &groups) |
Execute the HAVING clause (if present). | |
Static Public Member Functions | |
static void | checkAggrFuncs (const TableExprNode &node) |
An exception is thrown if the node uses an aggregate function. | |
Private Member Functions | |
std::shared_ptr< TableExprGroupResult > | aggregate (Vector< rownr_t > &rownrs) const |
Do the grouping and aggregation and return the results. | |
std::shared_ptr< TableExprGroupResult > | countAll (Vector< rownr_t > &rownrs) const |
Do the grouping and aggregation and return the results. | |
std::vector< std::shared_ptr< TableExprGroupFuncSet > > | multiKey (const std::vector< TableExprNodeRep * > &, const Vector< rownr_t > &rownrs) const |
Create the set of aggregate functions and groupby keys. | |
template<typename T > | |
std::vector< std::shared_ptr< TableExprGroupFuncSet > > | singleKey (const std::vector< TableExprNodeRep * > &nodes, const Vector< rownr_t > &rownrs) const |
Create the set of aggregate functions and groupby keys in case a single groupby key is given. | |
void | getAggrNodes (const TableExprNode &node, std::vector< TableExprNodeRep * > &aggrNodes) const |
Get pointers to the aggregate nodes in the node expression. | |
Private Attributes | |
std::vector< TableExprNode > | itsGroupbyNodes |
The possible GROUPBY expressions. | |
Bool | itsGroupbyRollup |
TableExprNode | itsHavingNode |
The possible HAVING expression. | |
std::vector< TableExprNodeRep * > | itsAggrNodes |
Pointers to the aggregate function nodes. | |
Int | itsGroupAggrUsed |
Class handling GROUPBY and aggregate functions
Internal
This class is used by TableParseQuery to handle TaQL's GROUPBY and HAVING clauses and to setup and evaluate aggregate functions. It checks that the commands and functions are given in a valid way.
Note that some hooks are present for the ROLLUP keyword, but it is not possible to use it yet.
Definition at line 58 of file TableParseGroupby.h.
Enumerator | |
---|---|
GROUPBY | |
AGGR_FUNCS | |
ONLY_COUNTALL |
Definition at line 61 of file TableParseGroupby.h.
|
private |
Do the grouping and aggregation and return the results.
It distinguishes the immediate and lazy aggregate functions. The rownrs are adapted to the resulting rownrs consisting of the first row of each group.
|
static |
An exception is thrown if the node uses an aggregate function.
|
private |
Do the grouping and aggregation and return the results.
It consists of a single COUNTALL operation. The rownrs are adapted to the resulting rownrs consisting of the first row of each group.
uInt casacore::TableParseGroupby::disableApplySelection | ( | ) |
Disable applySelection for the column nodes of aggregate functions.
std::shared_ptr< TableExprGroupResult > casacore::TableParseGroupby::execGroupAggr | ( | Vector< rownr_t > & | rownrs | ) | const |
Execute the grouping and aggregation and return the results.
The rownrs are adapted to the resulting rownrs consisting of the first row of each group.
Bool casacore::TableParseGroupby::execHaving | ( | Vector< rownr_t > & | rownrs, |
const std::shared_ptr< TableExprGroupResult > & | groups | ||
) |
Execute the HAVING clause (if present).
Return False in no HAVING.
void casacore::TableParseGroupby::findGroupAggr | ( | const Block< TableExprNode > & | columnNodes, |
Bool | isSelect | ||
) |
Find if groupby and/or aggregate functions are given.
The column nodes can only contain aggregate functions if SELECT is used. Finally it checks that HAVING is only used if a column node contains an aggregate function (it makes no sense otherwise).
|
private |
Get pointers to the aggregate nodes in the node expression.
void casacore::TableParseGroupby::handleGroupby | ( | const std::vector< TableExprNode > & | , |
Bool | rollup | ||
) |
Keep the groupby expressions.
It checks if they are all scalar expressions and do not contain aggregate functions..
void casacore::TableParseGroupby::handleHaving | ( | const TableExprNode & | ) |
Keep the having expression.
It checks if the node results in a bool scalar value.
|
inline |
Is only aggregation used?
Definition at line 88 of file TableParseGroupby.h.
References GROUPBY, and itsGroupAggrUsed.
|
inline |
Is GROUPBY and/or aggregation used?
Definition at line 84 of file TableParseGroupby.h.
References itsGroupAggrUsed.
|
private |
Create the set of aggregate functions and groupby keys.
|
inlineprivate |
Create the set of aggregate functions and groupby keys in case a single groupby key is given.
This offers much faster map access then the general multipleKeys.
We have to group the data according to the (possibly empty) groupby. We step through the table in the normal order which may not be the groupby order. A map<key,int> is used to keep track of the results where the int is the index in a vector of a set of aggregate function objects.
Loop through all rows. For each row generate the key to get the right entry.
Definition at line 132 of file TableParseGroupby.h.
References itsGroupbyNodes, casacore::TableExprId::setRownr(), and casacore::ArrayBase::size().
|
inline |
Get the number of aggregation ndes.
Definition at line 92 of file TableParseGroupby.h.
References itsAggrNodes.
|
private |
Pointers to the aggregate function nodes.
Definition at line 181 of file TableParseGroupby.h.
Referenced by size().
|
private |
Definition at line 182 of file TableParseGroupby.h.
Referenced by isOnlyAggr(), and isUsed().
|
private |
The possible GROUPBY expressions.
Definition at line 176 of file TableParseGroupby.h.
Referenced by singleKey().
|
private |
Definition at line 177 of file TableParseGroupby.h.
|
private |
The possible HAVING expression.
Definition at line 179 of file TableParseGroupby.h.