Loading...
Searching...
No Matches
casacore::TableParseGroupby Class Reference
tables package (libcasa_tables) » TaQL_module » TaQL_module_internal_classes

More...

`#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

## Detailed Description

Class handling GROUPBY and aggregate functions

### Intended use:

Internal

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25

### Synopsis

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.

## Member Enumeration Documentation

## GroupAggrType

enum casacore::TableParseGroupby::GroupAggrType

Enumerator
GROUPBY |
AGGR_FUNCS |
ONLY_COUNTALL |

Definition at line 61 of file TableParseGroupby.h.

## Member Function Documentation

## aggregate()

std::shared_ptr< TableExprGroupResult > casacore::TableParseGroupby::aggregate | ( | Vector< rownr_t > & | rownrs | ) | const

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.

## checkAggrFuncs()

void casacore::TableParseGroupby::checkAggrFuncs | ( | const TableExprNode & | node | ) |

static

An exception is thrown if the node uses an aggregate function.

## countAll()

std::shared_ptr< TableExprGroupResult > casacore::TableParseGroupby::countAll | ( | Vector< rownr_t > & | rownrs | ) | const

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.

## disableApplySelection()

uInt casacore::TableParseGroupby::disableApplySelection | ( |  | ) |

Disable applySelection for the column nodes of aggregate functions.

## execGroupAggr()

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.

## execHaving()

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.

## findGroupAggr()

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).

## getAggrNodes()

void casacore::TableParseGroupby::getAggrNodes | ( | const TableExprNode & | node,
|  | std::vector< TableExprNodeRep * > & | aggrNodes ) const

private

Get pointers to the aggregate nodes in the node expression.

## handleGroupby()

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..

## handleHaving()

void casacore::TableParseGroupby::handleHaving | ( | const TableExprNode & |  | ) |

Keep the having expression.

It checks if the node results in a bool scalar value.

## isOnlyAggr()

Bool casacore::TableParseGroupby::isOnlyAggr | ( |  | ) | const

inline

Is only aggregation used?

Definition at line 88 of file TableParseGroupby.h.

References GROUPBY, and itsGroupAggrUsed.

## isUsed()

Bool casacore::TableParseGroupby::isUsed | ( |  | ) | const

inline

Is GROUPBY and/or aggregation used?

Definition at line 84 of file TableParseGroupby.h.

References itsGroupAggrUsed.

## multiKey()

std::vector< std::shared_ptr< TableExprGroupFuncSet > > casacore::TableParseGroupby::multiKey | ( | const std::vector< TableExprNodeRep * > & | ,
|  | const Vector< rownr_t > & | rownrs ) const

private

Create the set of aggregate functions and groupby keys.

## singleKey()

template<typename T>

std::vector< std::shared_ptr< TableExprGroupFuncSet > > casacore::TableParseGroupby::singleKey | ( | const std::vector< TableExprNodeRep * > & | nodes,
|  | const Vector< rownr_t > & | rownrs ) const

inline private

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().

## size()

uInt casacore::TableParseGroupby::size | ( |  | ) | const

inline

Get the number of aggregation ndes.

Definition at line 92 of file TableParseGroupby.h.

References itsAggrNodes.

## Member Data Documentation

## itsAggrNodes

std::vector<TableExprNodeRep*> casacore::TableParseGroupby::itsAggrNodes

private

Pointers to the aggregate function nodes.

Definition at line 181 of file TableParseGroupby.h.

Referenced by size().

## itsGroupAggrUsed

Int casacore::TableParseGroupby::itsGroupAggrUsed

private

Definition at line 182 of file TableParseGroupby.h.

Referenced by isOnlyAggr(), and isUsed().

## itsGroupbyNodes

std::vector<TableExprNode> casacore::TableParseGroupby::itsGroupbyNodes

private

The possible GROUPBY expressions.

Definition at line 176 of file TableParseGroupby.h.

Referenced by singleKey().

## itsGroupbyRollup

Bool casacore::TableParseGroupby::itsGroupbyRollup

private

Definition at line 177 of file TableParseGroupby.h.

## itsHavingNode

TableExprNode casacore::TableParseGroupby::itsHavingNode

private

The possible HAVING expression.

Definition at line 179 of file TableParseGroupby.h.

The documentation for this class was generated from the following file:

- tables/TaQL/TableParseGroupby.h