casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id: TaQLNode.h 21051 2011-04-20 11:46:29Z gervandiepen $
27 
28 #ifndef TABLES_EXPRAGGRNODE_H
29 #define TABLES_EXPRAGGRNODE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
34 
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38  //# Forward Declarations.
39  class TableExprGroupFuncBase;
40  class TableExprGroupFuncSet;
41 
42 // <summary>
43 // TaQL node representing a scalar aggregate function
44 // </summary>
45 
46 // <use visibility=local>
47 
48 // <reviewed reviewer="" date="" tests="tTableGram">
49 // </reviewed>
50 
51 // <synopsis>
52 // A TableExprAggrNode object is a special TableExprFuncNode object.
53 // Instead of operating on a single row, it operates on a group of table
54 // rows, usually formed by means of the GROUPBY clause.
55 // It aggregates the values in the rows in the group by means of an
56 // aggregation function derived from TableExprGroupFuncBase.
57 // Several standard aggregation functions (e.g., gmean, gmin, gsum) are
58 // defined in TaQL and implemented this way.
59 //
60 // There are two types of aggregate function implementations:
61 // <ul>
62 // <li> Immediate aggregate functions calculate the results while the
63 // groups are being formed. In this way they step sequentially through
64 // the data.
65 // This is only possible for functions that do not have to keep
66 // to many data in memory.
67 // <li> Lazy aggregate functions calculate the results after the groups are
68 // formed using the vector of TableExprIds they get per group.
69 // In this way only data for a single group might need to be kept in
70 // memory. It is used, for instance, to calculate the median.
71 // </ul>
72 // Note that this class handles operands that are a scalar or array.
73 // If array, all values in the array are used as individual values.
74 // Class TableExprAggrNodeArray handles aggregate functions giving an
75 // array result (e.g., function <src>gaggr</src>).
76 //
77 // It is also possible to define an aggregate function in a UDF derived
78 // from class UDFBase. Such an aggregate function is instantiated as a
79 // TableExprUDFNode(Array) object, not as TabeExprAggrNode(Array).
80 // These functions are always lazy.
81 // </synopsis>
82 
84  {
85  public:
86  // Constructor.
88  const TableExprNodeSet& source,
89  const vector<TENShPtr>& nodes,
90  const Block<Int>& dtypeOper);
91 
92  // Check the operands of the aggregate function and return the
93  // result's data type.
94  static NodeDataType checkOperands (Block<Int>& dtypeOper,
95  ValueType& resVT, FunctionType ftype,
96  std::vector<TENShPtr>& nodes);
97 
98  // Get the nodes representing an aggregate function.
99  virtual void getAggrNodes (std::vector<TableExprNodeRep*>& aggr);
100 
101  // Get the operand node.
103  { return (operands().empty() ? TENShPtr() : operands()[0]); }
104 
105  // Create the correct aggregate function object.
106  // It is also kept in case it is a lazy aggregate function.
108 
109  // Is the aggregate function a lazy or an immediate one?
110  virtual Bool isLazyAggregate() const;
111 
112  // Functions to get the result of an aggregate function.
113  // <group>
114  virtual Bool getBool (const TableExprId& id);
115  virtual Int64 getInt (const TableExprId& id);
116  virtual Double getDouble (const TableExprId& id);
117  virtual DComplex getDComplex (const TableExprId& id);
118  virtual String getString (const TableExprId& id);
119  virtual MVTime getDate (const TableExprId& id);
120  // </group>
121 
122  private:
123  // Do the actual creation of the correct aggregate function object.
125 
126  //# Data members.
128  };
129 
130 
131 } //# NAMESPACE CASACORE - END
132 
133 #endif
Class representing a function in table select expression.
Definition: ExprFuncNode.h:77
CountedPtr< TableExprNodeRep > TENShPtr
Definition: ExprNodeRep.h:56
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
virtual Bool getBool(const TableExprId &id)
Functions to get the result of an aggregate function.
TENShPtr operand()
Get the operand node.
Definition: ExprAggrNode.h:102
virtual DComplex getDComplex(const TableExprId &id)
TableExprAggrNode(FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source, const vector< TENShPtr > &nodes, const Block< Int > &dtypeOper)
Constructor.
virtual Double getDouble(const TableExprId &id)
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:310
virtual MVTime getDate(const TableExprId &id)
NodeDataType
Define the data types of a node.
Definition: ExprNodeRep.h:161
virtual Int64 getInt(const TableExprId &id)
const std::vector< TENShPtr > & operands() const
Some functions to be used by TableExprNodeFuncArray.
Definition: ExprFuncNode.h:396
TableExprGroupFuncBase * doMakeGroupAggrFunc()
Do the actual creation of the correct aggregate function object.
double Double
Definition: aipstype.h:55
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
ValueType
Define the value types.
Definition: ExprNodeRep.h:176
virtual String getString(const TableExprId &id)
virtual CountedPtr< 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&#39;s data type.
Abstract base class for classes calculating an aggregated group result.
Definition: ExprGroup.h:201
TaQL node representing a scalar aggregate function.
Definition: ExprAggrNode.h:83
The identification of a TaQL selection subject.
Definition: TableExprId.h:97
virtual Bool isLazyAggregate() const
Is the aggregate function a lazy or an immediate one?
CountedPtr< TableExprGroupFuncBase > itsFunc
Definition: ExprAggrNode.h:127
String: the storage and methods of handling collections of characters.
Definition: String.h:225
Class to handle date/time type conversions and I/O.
Definition: MVTime.h:270
virtual void getAggrNodes(std::vector< TableExprNodeRep * > &aggr)
Get the nodes representing an aggregate function.