casacore
Loading...
Searching...
No Matches
ExprAggrNode.h
Go to the documentation of this file.
1// # ExprAggrNode.h: TaQL node representing a scalar aggregate function
2// # Copyright (C) 2013
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_EXPRAGGRNODE_H
27#define TABLES_EXPRAGGRNODE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/ExprFuncNode.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// # Forward Declarations.
38
39// <summary>
40// TaQL node representing a scalar aggregate function
41// </summary>
42
43// <use visibility=local>
44
45// <reviewed reviewer="" date="" tests="tTableGram">
46// </reviewed>
47
48// <synopsis>
49// A TableExprAggrNode object is a special TableExprFuncNode object.
50// Instead of operating on a single row, it operates on a group of table
51// rows, usually formed by means of the GROUPBY clause.
52// It aggregates the values in the rows in the group by means of an
53// aggregation function derived from TableExprGroupFuncBase.
54// Several standard aggregation functions (e.g., gmean, gmin, gsum) are
55// defined in TaQL and implemented this way.
56//
57// There are two types of aggregate function implementations:
58// <ul>
59// <li> Immediate aggregate functions calculate the results while the
60// groups are being formed. In this way they step sequentially through
61// the data.
62// This is only possible for functions that do not have to keep
63// to many data in memory.
64// <li> Lazy aggregate functions calculate the results after the groups are
65// formed using the vector of TableExprIds they get per group.
66// In this way only data for a single group might need to be kept in
67// memory. It is used, for instance, to calculate the median.
68// </ul>
69// Note that this class handles operands that are a scalar or array.
70// If array, all values in the array are used as individual values.
71// Class TableExprAggrNodeArray handles aggregate functions giving an
72// array result (e.g., function <src>gaggr</src>).
73//
74// It is also possible to define an aggregate function in a UDF derived
75// from class UDFBase. Such an aggregate function is instantiated as a
76// TableExprUDFNode(Array) object, not as TabeExprAggrNode(Array).
77// These functions are always lazy.
78// </synopsis>
79
81 public:
82 // Constructor.
84 const vector<TENShPtr>& nodes, const Block<Int>& dtypeOper);
85
86 // This node does aggregation.
87 virtual Bool isAggregate() const;
88
89 // Check the operands of the aggregate function and return the
90 // result's data type.
92 std::vector<TENShPtr>& nodes);
93
94 // Get the operand node.
95 TENShPtr operand() { return (operands().empty() ? TENShPtr() : operands()[0]); }
96
97 // Create the correct aggregate function object.
98 // It is also kept in case it is a lazy aggregate function.
99 virtual std::shared_ptr<TableExprGroupFuncBase> makeGroupAggrFunc();
100
101 // Is the aggregate function a lazy or an immediate one?
102 virtual Bool isLazyAggregate() const;
103
104 // Functions to get the result of an aggregate function.
105 // <group>
106 virtual Bool getBool(const TableExprId& id);
107 virtual Int64 getInt(const TableExprId& id);
108 virtual Double getDouble(const TableExprId& id);
109 virtual DComplex getDComplex(const TableExprId& id);
110 virtual String getString(const TableExprId& id);
111 virtual MVTime getDate(const TableExprId& id);
112 // </group>
113
114 private:
115 // Do the actual creation of the correct aggregate function object.
117
118 // # Data members.
119 std::shared_ptr<TableExprGroupFuncBase> itsFunc;
120};
121
122} // namespace casacore
123
124#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
virtual Double getDouble(const TableExprId &id)
TENShPtr operand()
Get the operand node.
virtual Bool getBool(const TableExprId &id)
Functions to get the result of an aggregate function.
TableExprGroupFuncBase * doMakeGroupAggrFunc()
Do the actual creation of the correct aggregate function object.
virtual Bool isAggregate() const
This node does aggregation.
virtual Int64 getInt(const TableExprId &id)
TableExprAggrNode(FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source, const vector< TENShPtr > &nodes, const Block< Int > &dtypeOper)
Constructor.
std::shared_ptr< TableExprGroupFuncBase > itsFunc
virtual String getString(const TableExprId &id)
virtual MVTime getDate(const TableExprId &id)
virtual DComplex getDComplex(const TableExprId &id)
virtual std::shared_ptr< TableExprGroupFuncBase > makeGroupAggrFunc()
Create the correct aggregate function object.
static NodeDataType checkOperands(Block< Int > &dtypeOper, ValueType &resVT, FunctionType ftype, std::vector< TENShPtr > &nodes)
Check the operands of the aggregate function and return the result's data type.
virtual Bool isLazyAggregate() const
Is the aggregate function a lazy or an immediate one?
TableExprFuncNode(FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source, const vector< TENShPtr > &nodes, const Block< Int > &dtypeOper, const TableExprInfo &=TableExprInfo())
Constructor.
const std::vector< TENShPtr > & operands() const
Some functions to be used by TableExprNodeFuncArray.
Abstract base class for classes calculating an aggregated group result.
Definition ExprGroup.h:180
Class containing the results of aggregated values in a group.
Definition ExprGroup.h:740
NodeDataType
Define the data types of a node.
ValueType
Define the value types.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
Bool empty() const
Is the block empty (i.e.
Definition Block.h:574
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:56
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53