ExprAggrNode.h

Go to the documentation of this file.
00001 //# ExprAggrNode.h: TaQL node representing a scalar aggregate function
00002 //# Copyright (C) 2013
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: TaQLNode.h 21051 2011-04-20 11:46:29Z gervandiepen $
00027 
00028 #ifndef TABLES_EXPRAGGRNODE_H
00029 #define TABLES_EXPRAGGRNODE_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/TaQL/ExprFuncNode.h>
00034 
00035 
00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00037 
00038   //# Forward Declarations.
00039   class TableExprGroupFuncBase;
00040   class TableExprGroupFuncSet;
00041 
00042 // <summary>
00043 // TaQL node representing a scalar aggregate function
00044 // </summary>
00045 
00046 // <use visibility=local>
00047 
00048 // <reviewed reviewer="" date="" tests="tTableGram">
00049 // </reviewed>
00050 
00051 // <synopsis>
00052 // A TableExprAggrNode object is a special TableExprFuncNode object.
00053 // Instead of operating on a single row, it operates on a group of table
00054 // rows, usually formed by means of the GROUPBY clause.
00055 // It aggregates the values in the rows in the group by means of an
00056 // aggregation function derived from TableExprGroupFuncBase.
00057 // Several standard aggregation functions (e.g., gmean, gmin, gsum) are
00058 // defined in TaQL and implemented this way.
00059 //
00060 // There are two types of aggregate function implementations:
00061 // <ul>
00062 //  <li> Immediate aggregate functions calculate the results while the
00063 //       groups are being formed. In this way they step sequentially through
00064 //       the data.
00065 //       This is only possible for functions that do not have to keep
00066 //       to many data in memory.
00067 //  <li> Lazy aggregate functions calculate the results after the groups are
00068 //       formed using the vector of TableExprIds they get per group.
00069 //       In this way only data for a single group might need to be kept in
00070 //       memory. It is used, for instance, to calculate the median.
00071 // </ul>
00072 // Note that this class handles operands that are a scalar or array.
00073 // If array, all values in the array are used as individual values.
00074 // Class TableExprAggrNodeArray handles aggregate functions giving an
00075 // array result (e.g., function <src>gaggr</src>).
00076 //
00077 // It is also possible to define an aggregate function in a UDF derived
00078 // from class UDFBase. Such an aggregate function is instantiated as a
00079 // TableExprUDFNode(Array) object, not as TabeExprAggrNode(Array).
00080 // These functions are always lazy.
00081 // </synopsis> 
00082 
00083   class TableExprAggrNode: public TableExprFuncNode
00084   {
00085   public:
00086     // Constructor.
00087     TableExprAggrNode (FunctionType, NodeDataType, ValueType,
00088                        const TableExprNodeSet& source);
00089 
00090     // Check the operands of the aggregate function and return the
00091     // result's data type.
00092     static NodeDataType checkOperands (Block<Int>& dtypeOper,
00093                                        ValueType& resVT, FunctionType ftype,
00094                                        PtrBlock<TableExprNodeRep*>& nodes);
00095 
00096     // Get the nodes representing an aggregate function.
00097     virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
00098 
00099     // Get the operand node.
00100     TableExprNodeRep* operand()
00101       { return (operands().empty()  ?  0 : operands()[0]); }
00102 
00103     // Create the correct aggregate function object.
00104     // It is also kept in case it is a lazy aggregate function.
00105     virtual CountedPtr<TableExprGroupFuncBase> makeGroupAggrFunc();
00106 
00107     // Is the aggregate function a lazy or an immediate one?
00108     virtual Bool isLazyAggregate() const;
00109 
00110     // Functions to get the result of an aggregate function.
00111     // <group>
00112     virtual Bool      getBool     (const TableExprId& id);
00113     virtual Int64     getInt      (const TableExprId& id);
00114     virtual Double    getDouble   (const TableExprId& id);
00115     virtual DComplex  getDComplex (const TableExprId& id);
00116     virtual String    getString   (const TableExprId& id);
00117     virtual MVTime    getDate     (const TableExprId& id);
00118     // </group>
00119 
00120   private:
00121     // Do the actual creation of the correct aggregate function object.
00122     TableExprGroupFuncBase* doMakeGroupAggrFunc();
00123 
00124     //# Data members.
00125     CountedPtr<TableExprGroupFuncBase> itsFunc;
00126   };
00127 
00128 
00129 } //# NAMESPACE CASACORE - END
00130 
00131 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1