casacore
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>
33 #include <casacore/tables/TaQL/ExprFuncNode.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 
90  // Check the operands of the aggregate function and return the
91  // result's data type.
92  static NodeDataType checkOperands (Block<Int>& dtypeOper,
93  ValueType& resVT, FunctionType ftype,
95 
96  // Get the nodes representing an aggregate function.
97  virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
98 
99  // Get the operand node.
101  { return (operands().empty() ? 0 : operands()[0]); }
102 
103  // Create the correct aggregate function object.
104  // It is also kept in case it is a lazy aggregate function.
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.
126  };
127 
128 
129 } //# NAMESPACE CASACORE - END
130 
131 #endif
Class representing a function in table select expression.
Definition: ExprFuncNode.h:76
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.
virtual DComplex getDComplex(const TableExprId &id)
static NodeDataType checkOperands(Block< Int > &dtypeOper, ValueType &resVT, FunctionType ftype, PtrBlock< TableExprNodeRep *> &nodes)
Check the operands of the aggregate function and return the result&#39;s data type.
virtual Double getDouble(const TableExprId &id)
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:305
virtual MVTime getDate(const TableExprId &id)
NodeDataType
Define the data types of a node.
Definition: ExprNodeRep.h:154
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:150
const PtrBlock< TableExprNodeRep * > & operands() const
Some functions to be used by TableExprNodeFuncArray.
Definition: ExprFuncNode.h:361
virtual Int64 getInt(const TableExprId &id)
TableExprNodeRep * operand()
Get the operand node.
Definition: ExprAggrNode.h:100
TableExprGroupFuncBase * doMakeGroupAggrFunc()
Do the actual creation of the correct aggregate function object.
Referenced counted pointer for constant data.
Definition: CountedPtr.h:86
virtual void getAggrNodes(vector< TableExprNodeRep *> &aggr)
Get the nodes representing an aggregate function.
TableExprAggrNode(FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source)
Constructor.
double Double
Definition: aipstype.h:52
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
ValueType
Define the value types.
Definition: ExprNodeRep.h:169
virtual String getString(const TableExprId &id)
A drop-in replacement for Block<T*>.
Definition: Block.h:861
virtual CountedPtr< TableExprGroupFuncBase > makeGroupAggrFunc()
Create the correct aggregate function object.
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:98
CountedPtr< TableExprGroupFuncBase > itsFunc
Definition: ExprAggrNode.h:125
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Class to handle date/time type conversions and I/O.
Definition: MVTime.h:266
this file contains all the compiler specific defines
Definition: mainpage.dox:28
virtual Bool isLazyAggregate() const
Is the aggregate function a lazy or an immediate one?