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
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36 //# Forward Declarations.
37 class TableExprGroupFuncBase;
38 class TableExprGroupFuncSet;
39
40// <summary>
41// TaQL node representing a scalar aggregate function
42// </summary>
43
44// <use visibility=local>
45
46// <reviewed reviewer="" date="" tests="tTableGram">
47// </reviewed>
48
49// <synopsis>
50// A TableExprAggrNode object is a special TableExprFuncNode object.
51// Instead of operating on a single row, it operates on a group of table
52// rows, usually formed by means of the GROUPBY clause.
53// It aggregates the values in the rows in the group by means of an
54// aggregation function derived from TableExprGroupFuncBase.
55// Several standard aggregation functions (e.g., gmean, gmin, gsum) are
56// defined in TaQL and implemented this way.
57//
58// There are two types of aggregate function implementations:
59// <ul>
60// <li> Immediate aggregate functions calculate the results while the
61// groups are being formed. In this way they step sequentially through
62// the data.
63// This is only possible for functions that do not have to keep
64// to many data in memory.
65// <li> Lazy aggregate functions calculate the results after the groups are
66// formed using the vector of TableExprIds they get per group.
67// In this way only data for a single group might need to be kept in
68// memory. It is used, for instance, to calculate the median.
69// </ul>
70// Note that this class handles operands that are a scalar or array.
71// If array, all values in the array are used as individual values.
72// Class TableExprAggrNodeArray handles aggregate functions giving an
73// array result (e.g., function <src>gaggr</src>).
74//
75// It is also possible to define an aggregate function in a UDF derived
76// from class UDFBase. Such an aggregate function is instantiated as a
77// TableExprUDFNode(Array) object, not as TabeExprAggrNode(Array).
78// These functions are always lazy.
79// </synopsis>
80
82 {
83 public:
84 // Constructor.
86 const TableExprNodeSet& source,
87 const vector<TENShPtr>& nodes,
88 const Block<Int>& dtypeOper);
89
90 // This node does aggregation.
91 virtual Bool isAggregate() const;
92
93 // Check the operands of the aggregate function and return the
94 // result's data type.
96 ValueType& resVT, FunctionType ftype,
97 std::vector<TENShPtr>& nodes);
98
99 // Get the operand node.
101 { return (operands().empty() ? TENShPtr() : operands()[0]); }
102
103 // Create the correct aggregate function object.
104 // It is also kept in case it is a lazy aggregate function.
105 virtual std::shared_ptr<TableExprGroupFuncBase> makeGroupAggrFunc();
106
107 // Is the aggregate function a lazy or an immediate one?
108 virtual Bool isLazyAggregate() const;
109
110 // Functions to get the result of an aggregate function.
111 // <group>
112 virtual Bool getBool (const TableExprId& id);
113 virtual Int64 getInt (const TableExprId& id);
114 virtual Double getDouble (const TableExprId& id);
115 virtual DComplex getDComplex (const TableExprId& id);
116 virtual String getString (const TableExprId& id);
117 virtual MVTime getDate (const TableExprId& id);
118 // </group>
119
120 private:
121 // Do the actual creation of the correct aggregate function object.
123
124 //# Data members.
125 std::shared_ptr<TableExprGroupFuncBase> itsFunc;
126 };
127
128
129} //# NAMESPACE CASACORE - END
130
131#endif
simple 1-D array
Definition Block.h:198
String: the storage and methods of handling collections of characters.
Definition String.h:223
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?
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:200
NodeDataType
Define the data types of a node.
ValueType
Define the value types.
this file contains all the compiler specific defines
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
std::shared_ptr< TableExprNodeRep > TENShPtr
Definition ExprNodeRep.h:55
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53