ExprGroup.h

Go to the documentation of this file.
00001 //# ExprGroup.h: Classes handling TaQL's GROUPBY functionality
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_EXPRGROUP_H
00029 #define TABLES_EXPRGROUP_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/BasicSL/String.h>
00034 #include <casacore/tables/TaQL/ExprAggrNode.h>
00035 #include <vector>
00036 
00037 
00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00039 
00040   // <summary>
00041   // Class representing a key in the groupby clause.
00042   // </summary>
00043   // <use visibility=local>
00044   // <reviewed reviewer="" date="" tests="tTableGram">
00045   // </reviewed>
00046   // <synopsis>
00047   // The GROUPBY clause consists of one or more keys, each being a scalar
00048   // TaQL expression with an arbitrary data type.
00049   // This class contains the value of a key for a particular table row.
00050   // It is part of a TableExprGroupKeySet object.
00051   // </synopsis> 
00052   class TableExprGroupKey
00053   {
00054   public:
00055     // Construct for a given data type.
00056     explicit TableExprGroupKey (TableExprNodeRep::NodeDataType dtype)
00057       : itsDT (dtype)
00058     {}
00059 
00060     // Get the data type.
00061     TableExprNodeRep::NodeDataType dataType() const
00062       { return itsDT; }
00063     
00064     // Set the key's value.
00065     // <group>
00066     void set (Bool v)
00067       { itsBool = v; }
00068     void set (Int64 v)
00069       { itsInt64 = v; }
00070     void set (Double v)
00071       { itsDouble = v; }
00072     void set (const String& v)
00073       { itsString = v; }
00074     // </group>
00075 
00076     // Compare this and that key.
00077     // <group>
00078     bool operator== (const TableExprGroupKey&) const;
00079     bool operator<  (const TableExprGroupKey&) const;
00080     // </group>
00081 
00082   private:
00083     TableExprNodeRep::NodeDataType itsDT;
00084     Bool   itsBool;
00085     Int64  itsInt64;
00086     Double itsDouble;
00087     String itsString;
00088   };
00089 
00090 
00091   // <summary>
00092   // Class representing all keys in the groupby clause.
00093   // </summary>
00094   // <use visibility=local>
00095   // <reviewed reviewer="" date="" tests="tTableGram">
00096   // </reviewed>
00097   // <synopsis>
00098   // The GROUPBY clause consists of one or more keys, each being a scalar
00099   // TaQL expression with an arbitrary data type.
00100   // This class contains a set of TableExprGroupKey objects, each containing
00101   // the value of a key for a particular table row.
00102   // <br>It contains comparison functions to make it possible to use them
00103   // in a std::map object to map the groupby keyset to a group.
00104   // </synopsis> 
00105   class TableExprGroupKeySet
00106   {
00107   public:
00108     // Form the object from the given groupby nodes.
00109     TableExprGroupKeySet (const vector<TableExprNode>& nodes);
00110 
00111     // Add a key to end the set.
00112     void addKey (TableExprNodeRep::NodeDataType dtype)
00113       { itsKeys.push_back (TableExprGroupKey(dtype)); }
00114 
00115     // Fill the keys with the values from the nodes for this rowid.
00116     void fill (const vector<TableExprNode>& nodes, const TableExprId& id);
00117 
00118     // Compare all keys in the set.
00119     // The keyset is compared in order of key, thus the first key defines
00120     // the major ordering.
00121     bool operator== (const TableExprGroupKeySet&) const;
00122     bool operator<  (const TableExprGroupKeySet&) const;
00123 
00124   private:
00125     vector<TableExprGroupKey> itsKeys;
00126   };
00127 
00128 
00129   // <summary>
00130   // Class holding the results of groupby and aggregation
00131   // </summary>
00132   // <use visibility=local>
00133   // <reviewed reviewer="" date="" tests="tTableGram">
00134   // </reviewed>
00135   // <synopsis>
00136   // The SELECT (and HAVING) clause can contain aggregate functions
00137   // of which the results can be grouped using the GROUPBY clause.
00138   // This class holds the results of the (immediate) aggregate functions
00139   // and, if needed, the TableExprId ids of all rows belonging to each group.
00140   // These ids are used to evaluate the lazy aggregate functions.
00141   // <br>An object of this class is part of the TableExprIdAggr object
00142   // used to get the aggregated values of each group.
00143   // </synopsis> 
00144   class TableExprGroupResult
00145   {
00146   public:
00147     // Create from the possible set of immediate aggregate functions.
00148     // No immediate functions were used, thus no TableExprIds needed.
00149     explicit TableExprGroupResult
00150     (const vector<CountedPtr<TableExprGroupFuncSet> >& funcSets);
00151     // Create from the possible set of immediate aggregate functions
00152     // and the set of TableExprIds per group for lazy aggregate functions.
00153     TableExprGroupResult
00154     (const vector<CountedPtr<TableExprGroupFuncSet> >& funcSets,
00155      const vector<CountedPtr<vector<TableExprId> > >& ids);
00156     // Get the nr of groups.
00157     uInt ngroup() const
00158       { return itsFuncSets.size(); }
00159     // Get the set of functions (and their results) for the given group.
00160     TableExprGroupFuncSet& funcSet (uInt group) const
00161       { return *itsFuncSets[group]; }
00162     // Get the set of TableExprIds for the given group.
00163     const vector<TableExprId>& ids (uInt group) const
00164       { return *itsIds[group]; }
00165   private:
00166     vector<CountedPtr<TableExprGroupFuncSet> > itsFuncSets;
00167     vector<CountedPtr<vector<TableExprId> > >  itsIds;
00168   };
00169 
00170 
00171   // <summary>
00172   // Abstract base class for classes calculating an aggregated group result.
00173   // </summary>
00174   // <use visibility=local>
00175   // <reviewed reviewer="" date="" tests="tExprGroup">
00176   // </reviewed>
00177   // <synopsis>
00178   // The GROUPBY clause divides a table into groups for which aggregated
00179   // results can be calculated like the mean or minimum. These results are
00180   // calculated in classes derived from this abstract base class.
00181   // <br>There is one such function object per aggregation per group. All
00182   // aggregation objects of a group are combined in a std::vector.
00183   // This vector is mapped to a TableExprGroupKeySet object to keep track
00184   // of all groups and aggregations.
00185   // <br> There are two types of aggregation function classes.
00186   // <ul>
00187   //  <li> Immediate classes implement the 'apply' function to immediately
00188   //       apply the operand's value in the aggregation.
00189   //       Such classes do not keep the operand's values.
00190   //  <li> Lazy classes do not need the 'apply' function. Instead they
00191   //       read all values of the group in the 'getXXX' function and do the
00192   //       aggregation. Such classes are meant for aggregation functions
00193   //       like 'median' that need to keep all values. When applying it
00194   //       immediately, all groups need to keep their values which might need
00195   //       too much memory. Lazy classes need the values of only one group
00196   //       at a time, but have the disadvantage that reading the values from
00197   //       the table might be done in a non-sequential order.
00198   // </ul>
00199   // Most derived classes are immediate classes.
00200   // </synopsis> 
00201   class TableExprGroupFuncBase
00202   {
00203   public:
00204     // Construct from the TaQL aggregation node. It keeps the operand
00205     // of the aggregation node.
00206     explicit TableExprGroupFuncBase (TableExprNodeRep* node);
00207     virtual ~TableExprGroupFuncBase();
00208     // Does the aggregate function use lazy semantics?
00209     // The default implementation returns False.
00210     virtual Bool isLazy() const;
00211     // Get the function's sequence nr.
00212     uInt seqnr() const
00213       { return itsSeqnr; }
00214     // Set the function's sequence nr.
00215     void setSeqnr (uInt seqnr)
00216       { itsSeqnr = seqnr; }
00217     // Get the operand's value for the given row and apply it to the aggregation.
00218     // This function should not be called for lazy classes.
00219     virtual void apply (const TableExprId& id) = 0;
00220     // If needed, finish the aggregation.
00221     // By default nothing is done.
00222     virtual void finish();
00223     // Get the assembled TableExprIds of a group. It is specifically meant
00224     // for TableExprGroupExprId used for lazy aggregation.
00225     virtual CountedPtr<vector<TableExprId> > getIds() const;
00226     // Get the aggregated value.
00227     // Immediate classes can return the already calculated value, while
00228     // lazy classes will get the values of all rows given by the TableExprIds
00229     // and do the aggregation.
00230     // <group>
00231     virtual Bool getBool (const vector<TableExprId>& = vector<TableExprId>());
00232     virtual Int64 getInt (const vector<TableExprId>& = vector<TableExprId>());
00233     virtual Double getDouble (const vector<TableExprId>& = vector<TableExprId>());
00234     virtual DComplex getDComplex (const vector<TableExprId>& = vector<TableExprId>());
00235     virtual MVTime getDate (const vector<TableExprId>& = vector<TableExprId>());
00236     virtual String getString (const vector<TableExprId>& = vector<TableExprId>());
00237     virtual MArray<Bool> getArrayBool (const vector<TableExprId>& = vector<TableExprId>());
00238     virtual MArray<Int64> getArrayInt (const vector<TableExprId>& = vector<TableExprId>());
00239     virtual MArray<Double> getArrayDouble (const vector<TableExprId>& = vector<TableExprId>());
00240     virtual MArray<DComplex> getArrayDComplex (const vector<TableExprId>& = vector<TableExprId>());
00241     virtual MArray<MVTime> getArrayDate (const vector<TableExprId>& = vector<TableExprId>());
00242     virtual MArray<String> getArrayString (const vector<TableExprId>& = vector<TableExprId>());
00243     // <group>
00244   private:
00245     // Copying is not needed, thus not allowed.
00246     TableExprGroupFuncBase (const TableExprGroupFuncBase&);
00247     TableExprGroupFuncBase& operator= (const TableExprGroupFuncBase&);
00248   protected:
00249     //# Data member
00250     TableExprNodeRep* itsNode;
00251     TableExprNodeRep* itsOperand;
00252     uInt              itsSeqnr;
00253   };
00254 
00255 
00256   // <summary>
00257   // Class derived from TableExprGroupFuncBase representing a no function
00258   // </summary>
00259   // <use visibility=local>
00260   // <reviewed reviewer="" date="" tests="tExprGroup">
00261   // </reviewed>
00262   // <synopsis>
00263   // This class represents a null aggregate function which is meant for
00264   // possible aggregate functionality in UDFs.
00265   // </synopsis>
00266   class TableExprGroupNull: public TableExprGroupFuncBase
00267   {
00268   public:
00269     explicit TableExprGroupNull (TableExprNodeRep* node);
00270     virtual ~TableExprGroupNull();
00271     virtual Bool isLazy() const;
00272     virtual void apply (const TableExprId& id);
00273   };
00274 
00275   // <summary>
00276   // Class derived from TableExprGroupFuncBase for the first value in a group
00277   // </summary>
00278   // <use visibility=local>
00279   // <reviewed reviewer="" date="" tests="tExprGroup">
00280   // </reviewed>
00281   // <synopsis>
00282   // This class keeps the TableExprId of the first value in a group.
00283   // The 'getXXX' functions get the value for that TableExprId.
00284   // </synopsis>
00285   class TableExprGroupFirst: public TableExprGroupFuncBase
00286   {
00287   public:
00288     explicit TableExprGroupFirst (TableExprNodeRep* node);
00289     virtual ~TableExprGroupFirst();
00290     virtual void apply (const TableExprId& id);
00291     virtual Bool getBool (const vector<TableExprId>&);
00292     virtual Int64 getInt (const vector<TableExprId>&);
00293     virtual Double getDouble (const vector<TableExprId>&);
00294     virtual DComplex getDComplex (const vector<TableExprId>&);
00295     virtual MVTime getDate (const vector<TableExprId>&);
00296     virtual String getString (const vector<TableExprId>&);
00297     virtual MArray<Bool> getArrayBool (const vector<TableExprId>&);
00298     virtual MArray<Int64> getArrayInt (const vector<TableExprId>&);
00299     virtual MArray<Double> getArrayDouble (const vector<TableExprId>&);
00300     virtual MArray<DComplex> getArrayDComplex (const vector<TableExprId>&);
00301     virtual MArray<MVTime> getArrayDate (const vector<TableExprId>&);
00302     virtual MArray<String> getArrayString (const vector<TableExprId>&);
00303   protected:
00304     TableExprId itsId;
00305   };
00306 
00307   // <summary>
00308   // Class derived from TableExprGroupFuncBase for the first value in a group
00309   // </summary>
00310   // <use visibility=local>
00311   // <reviewed reviewer="" date="" tests="tExprGroup">
00312   // </reviewed>
00313   // <synopsis>
00314   // This class keeps the TableExprId of the last value in a group.
00315   // The 'getXXX' functions get the value for that TableExprId.
00316   // <br>For ease of use this class is derived from TableExprGroupFirst.
00317   // </synopsis>
00318   class TableExprGroupLast: public TableExprGroupFirst
00319   {
00320   public:
00321     explicit TableExprGroupLast (TableExprNodeRep* node);
00322     virtual ~TableExprGroupLast();
00323     virtual void apply (const TableExprId& id);
00324   };
00325 
00326   // <summary>
00327   // Class derived from TableExprGroupFuncBase collecting the ids in a group
00328   // </summary>
00329   // <use visibility=local>
00330   // <reviewed reviewer="" date="" tests="tExprGroup">
00331   // </reviewed>
00332   // <synopsis>
00333   // This class keeps all TableExprIds in a group.
00334   // It is meant for lazy aggregation classes which use the collected
00335   // TableExprIds in their 'getXXX' functions.
00336   // </synopsis>
00337   class TableExprGroupExprId: public TableExprGroupFuncBase
00338   {
00339   public:
00340     explicit TableExprGroupExprId (TableExprNodeRep* node);
00341     virtual ~TableExprGroupExprId();
00342     virtual Bool isLazy() const;
00343     virtual void apply (const TableExprId& id);
00344     virtual CountedPtr<vector<TableExprId> > getIds() const;
00345   private:
00346     CountedPtr<vector<TableExprId> > itsIds;
00347   };
00348 
00349   // <summary>
00350   // Class collecting the rowids of entries in a group.
00351   // </summary>
00352   // <use visibility=local>
00353   // <reviewed reviewer="" date="" tests="tExprGroup">
00354   // </reviewed>
00355   // <synopsis>
00356   // This class collects the row numbers of the rows in a group.
00357   // </synopsis>
00358   class TableExprGroupRowid: public TableExprGroupFuncBase
00359   {
00360   public:
00361     explicit TableExprGroupRowid (TableExprNodeRep* node);
00362     virtual ~TableExprGroupRowid();
00363     virtual Bool isLazy() const;
00364     virtual void apply (const TableExprId& id);
00365     virtual MArray<Int64> getArrayInt (const vector<TableExprId>&);
00366   };
00367 
00368   // <summary>
00369   // Class collecting the arrays in a group.
00370   // </summary>
00371   // <use visibility=local>
00372   // <reviewed reviewer="" date="" tests="tExprGroup">
00373   // </reviewed>
00374   // <synopsis>
00375   // This class collects the non-empty arrays in a group into an array with
00376   // one more axis. All arrays (if not empty) must have the same shape.
00377   // </synopsis>
00378   class TableExprGroupAggr: public TableExprGroupFuncBase
00379   {
00380   public:
00381     explicit TableExprGroupAggr (TableExprNodeRep* node);
00382     virtual ~TableExprGroupAggr();
00383     virtual Bool isLazy() const;
00384     virtual void apply (const TableExprId& id);
00385     virtual MArray<Bool> getArrayBool (const vector<TableExprId>&);
00386     virtual MArray<Int64> getArrayInt (const vector<TableExprId>&);
00387     virtual MArray<Double> getArrayDouble (const vector<TableExprId>&);
00388     virtual MArray<DComplex> getArrayDComplex (const vector<TableExprId>&);
00389     virtual MArray<MVTime> getArrayDate (const vector<TableExprId>&);
00390     virtual MArray<String> getArrayString (const vector<TableExprId>&);
00391   protected:
00392     template<typename T>
00393     MArray<T> getArray (const vector<TableExprId>& ids)
00394     {
00395       // Return scalar values as a Vector.
00396       if (itsOperand->valueType() == TableExprNodeRep::VTScalar) {
00397         Vector<T> result(ids.size());
00398         for (size_t i=0; i<ids.size(); ++i) {
00399           itsOperand->get (ids[i], result[i]);
00400         }
00401         return MArray<T>(result);
00402       }
00403       // Array values are returned as an array with one more axis.
00404       // Use the first non-null value to determine the shape and if masked.
00405       MArray<T> arr;
00406       size_t id;
00407       Bool hasMask = False;
00408       IPosition shp;
00409       for (id=0; id<ids.size(); ++id) {
00410         itsOperand->get (ids[id], arr);
00411         if (! arr.isNull()) {
00412           hasMask = arr.hasMask();
00413           shp = arr.shape();
00414           shp.append (IPosition (1, ids.size()));
00415           break;
00416         }
00417       }
00418       size_t ndef = 0;
00419       if (id == ids.size()) {
00420         // All arrays are null.
00421         return MArray<T>();
00422       }
00423       Array<T> result(shp);
00424       ArrayIterator<T> iter (result, arr.ndim());
00425       Array<Bool> mask;
00426       CountedPtr<ArrayIterator<Bool> > miter;
00427       if (hasMask) {
00428         mask.resize (shp);
00429         miter = new ArrayIterator<Bool> (mask, arr.ndim());
00430       }
00431       for (; id<ids.size(); ++id) {
00432         MArray<T> values;
00433         itsOperand->get (ids[id], values);
00434         if (! values.isNull()) {
00435           ndef++;
00436           iter.array() = values.array();
00437           iter.next();
00438           if (hasMask) {
00439             miter->array() = values.mask();
00440             miter->next();
00441           }
00442         }
00443       }
00444       if (ndef < ids.size()) {
00445         shp[shp.size() - 1] = ndef;
00446         result.resize (shp, True);
00447         if (hasMask) {
00448           mask.resize (shp, True);
00449         }
00450       }
00451       return MArray<T>(result, mask);
00452     }
00453   };
00454 
00455 
00456   // <summary>
00457   // Abstract base class for aggregate functions giving a bool scalar.
00458   // </summary>
00459   // <use visibility=local>
00460   // <reviewed reviewer="" date="" tests="tExprGroup">
00461   // </reviewed>
00462   // <synopsis>
00463   // This class is derived from TableExprGroupFuncBase and act as the
00464   // abstract base class for aggregate functions resulting in a bool scalar.
00465   // <br>Derived classes can use <src>itsValue</src> to contain the
00466   // aggregated value. It that case they do not need to implement the
00467   // <src>get</src> function.
00468   // </synopsis>
00469   class TableExprGroupFuncBool: public TableExprGroupFuncBase
00470   {
00471   public:
00472     explicit TableExprGroupFuncBool (TableExprNodeRep* node)
00473       : TableExprGroupFuncBase (node)
00474     {}
00475     TableExprGroupFuncBool (TableExprNodeRep* node, Bool initValue)
00476       : TableExprGroupFuncBase (node),
00477         itsValue (initValue)
00478     {}
00479     virtual ~TableExprGroupFuncBool();
00480     virtual Bool getBool (const vector<TableExprId>&);
00481   protected:
00482     Bool itsValue;
00483   };
00484 
00485   // <summary>
00486   // Abstract base class for aggregate functions giving an integer scalar.
00487   // </summary>
00488   // <use visibility=local>
00489   // <reviewed reviewer="" date="" tests="tExprGroup">
00490   // </reviewed>
00491   // <synopsis>
00492   // This class is derived from TableExprGroupFuncBase and act as the
00493   // abstract base class for aggregate functions resulting in an integer scalar.
00494   // <br>Derived classes can use <src>itsValue</src> to contain the
00495   // aggregated value. It that case they do not need to implement the
00496   // <src>get</src> function.
00497   // </synopsis>
00498   class TableExprGroupFuncInt: public TableExprGroupFuncBase
00499   {
00500   public:
00501     explicit TableExprGroupFuncInt (TableExprNodeRep* node, Int64 initValue=0)
00502       : TableExprGroupFuncBase (node),
00503         itsValue (initValue)
00504     {}
00505     virtual ~TableExprGroupFuncInt();
00506     virtual Int64  getInt (const vector<TableExprId>&);
00507     virtual Double getDouble (const vector<TableExprId>&);
00508   protected:
00509     Int64 itsValue;
00510   };
00511 
00512   // <summary>
00513   // Abstract base class for aggregate functions giving a double scalar.
00514   // </summary>
00515   // <use visibility=local>
00516   // <reviewed reviewer="" date="" tests="tExprGroup">
00517   // </reviewed>
00518   // <synopsis>
00519   // This class is derived from TableExprGroupFuncBase and act as the
00520   // abstract base class for aggregate functions resulting in a double scalar.
00521   // <br>Derived classes can use <src>itsValue</src> to contain the
00522   // aggregated value. It that case they do not need to implement the
00523   // <src>get</src> function.
00524   // </synopsis>
00525   class TableExprGroupFuncDouble: public TableExprGroupFuncBase
00526   {
00527   public:
00528     explicit TableExprGroupFuncDouble (TableExprNodeRep* node,
00529                                        Double initValue = 0)
00530       : TableExprGroupFuncBase (node),
00531         itsValue (initValue)
00532     {}
00533     virtual ~TableExprGroupFuncDouble();
00534     virtual Double getDouble (const vector<TableExprId>&);
00535   protected:
00536     Double itsValue;
00537   };
00538 
00539   // <summary>
00540   // Abstract base class for aggregate functions giving a dcomplex scalar.
00541   // </summary>
00542   // <use visibility=local>
00543   // <reviewed reviewer="" date="" tests="tExprGroup">
00544   // </reviewed>
00545   // <synopsis>
00546   // This class is derived from TableExprGroupFuncBase and act as the
00547   // abstract base class for aggregate functions resulting in a dcomplex scalar.
00548   // <br>Derived classes can use <src>itsValue</src> to contain the
00549   // aggregated value. It that case they do not need to implement the
00550   // <src>get</src> function.
00551   // </synopsis>
00552   class TableExprGroupFuncDComplex: public TableExprGroupFuncBase
00553   {
00554   public:
00555     explicit TableExprGroupFuncDComplex (TableExprNodeRep* node,
00556                                          const DComplex& initValue = DComplex())
00557       : TableExprGroupFuncBase (node),
00558         itsValue (initValue)
00559     {}
00560     virtual ~TableExprGroupFuncDComplex();
00561     virtual DComplex getDComplex (const vector<TableExprId>&);
00562   protected:
00563     DComplex itsValue;
00564   };
00565 
00566   // <summary>
00567   // Abstract base class for aggregate functions giving a date/time scalar.
00568   // </summary>
00569   // <use visibility=local>
00570   // <reviewed reviewer="" date="" tests="tExprGroup">
00571   // </reviewed>
00572   // <synopsis>
00573   // This class is derived from TableExprGroupFuncBase and act as the
00574   // abstract base class for aggregate functions resulting in a date/time scalar.
00575   // <br>Derived classes can use <src>itsValue</src> to contain the
00576   // aggregated value. It that case they do not need to implement the
00577   // <src>get</src> function.
00578   // </synopsis>
00579   class TableExprGroupFuncDate: public TableExprGroupFuncBase
00580   {
00581   public:
00582     explicit TableExprGroupFuncDate (TableExprNodeRep* node,
00583                                      const MVTime& initValue = MVTime())
00584       : TableExprGroupFuncBase (node),
00585         itsValue (initValue)
00586     {}
00587     virtual ~TableExprGroupFuncDate();
00588     virtual MVTime getDate (const vector<TableExprId>&);
00589   protected:
00590     MVTime itsValue;
00591   };
00592 
00593   // <summary>
00594   // Abstract base class for aggregate functions giving a string scalar.
00595   // </summary>
00596   // <use visibility=local>
00597   // <reviewed reviewer="" date="" tests="tExprGroup">
00598   // </reviewed>
00599   // <synopsis>
00600   // This class is derived from TableExprGroupFuncBase and act as the
00601   // abstract base class for aggregate functions resulting in a string scalar.
00602   // <br>Derived classes can use <src>itsValue</src> to contain the
00603   // aggregated value. It that case they do not need to implement the
00604   // <src>get</src> function.
00605   // </synopsis>
00606   class TableExprGroupFuncString: public TableExprGroupFuncBase
00607   {
00608   public:
00609     explicit TableExprGroupFuncString (TableExprNodeRep* node,
00610                                        const String& initValue = String())
00611       : TableExprGroupFuncBase (node),
00612         itsValue (initValue)
00613     {}
00614     virtual ~TableExprGroupFuncString();
00615     virtual String getString (const vector<TableExprId>&);
00616   protected:
00617     String itsValue;
00618   };
00619 
00620   // <summary>
00621   // Abstract base class for aggregate functions giving a bool array.
00622   // </summary>
00623   // <use visibility=local>
00624   // <reviewed reviewer="" date="" tests="tExprGroup">
00625   // </reviewed>
00626   // <synopsis>
00627   // This class is derived from TableExprGroupFuncBase and act as the
00628   // abstract base class for aggregate functions resulting in a bool array.
00629   // <br>Derived classes can use <src>itsValue</src> to contain the
00630   // aggregated value. It that case they do not need to implement the
00631   // <src>get</src> function.
00632   // </synopsis>
00633   class TableExprGroupFuncArrayBool: public TableExprGroupFuncBase
00634   {
00635   public:
00636     explicit TableExprGroupFuncArrayBool (TableExprNodeRep* node)
00637       : TableExprGroupFuncBase (node)
00638     {}
00639     virtual ~TableExprGroupFuncArrayBool();
00640     virtual MArray<Bool> getArrayBool (const vector<TableExprId>&);
00641   protected:
00642     // If not empty, check if the shape matches that of <src>itsValue</src>.
00643     // If <src>itsValue</src> is still empty, it is sized.
00644     Bool checkShape (const MArrayBase& arr, const String& func);
00645     MArray<Bool> itsValue;
00646   };
00647 
00648   // <summary>
00649   // Abstract base class for aggregate functions giving an integer array.
00650   // </summary>
00651   // <use visibility=local>
00652   // <reviewed reviewer="" date="" tests="tExprGroup">
00653   // </reviewed>
00654   // <synopsis>
00655   // This class is derived from TableExprGroupFuncBase and act as the
00656   // abstract base class for aggregate functions resulting in an integer array.
00657   // <br>Derived classes can use <src>itsValue</src> to contain the
00658   // aggregated value. It that case they do not need to implement the
00659   // <src>get</src> function.
00660   // </synopsis>
00661   class TableExprGroupFuncArrayInt: public TableExprGroupFuncBase
00662   {
00663   public:
00664     explicit TableExprGroupFuncArrayInt (TableExprNodeRep* node)
00665       : TableExprGroupFuncBase (node)
00666     {}
00667     virtual ~TableExprGroupFuncArrayInt();
00668     virtual MArray<Int64> getArrayInt (const vector<TableExprId>&);
00669   protected:
00670     // If not empty, check if the shape matches that of <src>itsValue</src>.
00671     // If <src>itsValue</src> is still empty, it is sized.
00672     Bool checkShape (const MArrayBase& arr, const String& func);
00673     MArray<Int64> itsValue;
00674   };
00675 
00676   // <summary>
00677   // Abstract base class for aggregate functions giving a double array.
00678   // </summary>
00679   // <use visibility=local>
00680   // <reviewed reviewer="" date="" tests="tExprGroup">
00681   // </reviewed>
00682   // <synopsis>
00683   // This class is derived from TableExprGroupFuncBase and act as the
00684   // abstract base class for aggregate functions resulting in a double array.
00685   // <br>Derived classes can use <src>itsValue</src> to contain the
00686   // aggregated value. It that case they do not need to implement the
00687   // <src>get</src> function.
00688   // </synopsis>
00689   class TableExprGroupFuncArrayDouble: public TableExprGroupFuncBase
00690   {
00691   public:
00692     explicit TableExprGroupFuncArrayDouble (TableExprNodeRep* node)
00693       : TableExprGroupFuncBase (node)
00694     {}
00695     virtual ~TableExprGroupFuncArrayDouble();
00696     virtual MArray<Double> getArrayDouble (const vector<TableExprId>&);
00697   protected:
00698     // If not empty, check if the shape matches that of <src>itsValue</src>.
00699     // If <src>itsValue</src> is still empty, it is sized.
00700     Bool checkShape (const MArrayBase& arr, const String& func);
00701     MArray<Double> itsValue;
00702   };
00703 
00704   // <summary>
00705   // Abstract base class for aggregate functions giving a dcomplex array.
00706   // </summary>
00707   // <use visibility=local>
00708   // <reviewed reviewer="" date="" tests="tExprGroup">
00709   // </reviewed>
00710   // <synopsis>
00711   // This class is derived from TableExprGroupFuncBase and act as the
00712   // abstract base class for aggregate functions resulting in a dcomplex array.
00713   // <br>Derived classes can use <src>itsValue</src> to contain the
00714   // aggregated value. It that case they do not need to implement the
00715   // <src>get</src> function.
00716   // </synopsis>
00717   class TableExprGroupFuncArrayDComplex: public TableExprGroupFuncBase
00718   {
00719   public:
00720     explicit TableExprGroupFuncArrayDComplex (TableExprNodeRep* node)
00721       : TableExprGroupFuncBase (node)
00722     {}
00723     virtual ~TableExprGroupFuncArrayDComplex();
00724     virtual MArray<DComplex> getArrayDComplex (const vector<TableExprId>&);
00725   protected:
00726     // If not empty, check if the shape matches that of <src>itsValue</src>.
00727     // If <src>itsValue</src> is still empty, it is sized.
00728     Bool checkShape (const MArrayBase& arr, const String& func);
00729     MArray<DComplex> itsValue;
00730   };
00731 
00732   // <summary>
00733   // Abstract base class for aggregate functions giving a date/time array.
00734   // </summary>
00735   // <use visibility=local>
00736   // <reviewed reviewer="" date="" tests="tExprGroup">
00737   // </reviewed>
00738   // <synopsis>
00739   // This class is derived from TableExprGroupFuncBase and act as the
00740   // abstract base class for aggregate functions resulting in a date/time array.
00741   // <br>Derived classes can use <src>itsValue</src> to contain the
00742   // aggregated value. It that case they do not need to implement the
00743   // <src>get</src> function.
00744   // </synopsis>
00745   class TableExprGroupFuncArrayDate: public TableExprGroupFuncBase
00746   {
00747   public:
00748     explicit TableExprGroupFuncArrayDate (TableExprNodeRep* node)
00749       : TableExprGroupFuncBase (node)
00750     {}
00751     virtual ~TableExprGroupFuncArrayDate();
00752     virtual MArray<MVTime> getArrayDate (const vector<TableExprId>&);
00753   protected:
00754     // If not empty, check if the shape matches that of <src>itsValue</src>.
00755     // If <src>itsValue</src> is still empty, it is sized.
00756     Bool checkShape (const MArrayBase& arr, const String& func);
00757     MArray<MVTime> itsValue;
00758   };
00759 
00760   // <summary>
00761   // Abstract base class for aggregate functions giving a string array.
00762   // </summary>
00763   // <use visibility=local>
00764   // <reviewed reviewer="" date="" tests="tExprGroup">
00765   // </reviewed>
00766   // <synopsis>
00767   // This class is derived from TableExprGroupFuncBase and act as the
00768   // abstract base class for aggregate functions resulting in a string array.
00769   // <br>Derived classes can use <src>itsValue</src> to contain the
00770   // aggregated value. It that case they do not need to implement the
00771   // <src>get</src> function.
00772   // </synopsis>
00773   class TableExprGroupFuncArrayString: public TableExprGroupFuncBase
00774   {
00775   public:
00776     explicit TableExprGroupFuncArrayString (TableExprNodeRep* node)
00777       : TableExprGroupFuncBase (node)
00778     {}
00779     virtual ~TableExprGroupFuncArrayString();
00780     virtual MArray<String> getArrayString (const vector<TableExprId>&);
00781   protected:
00782     // If not empty, check if the shape matches that of <src>itsValue</src>.
00783     // If <src>itsValue</src> is still empty, it is sized.
00784     Bool checkShape (const MArrayBase& arr, const String& func);
00785     MArray<String> itsValue;
00786   };
00787 
00788 
00789   // <summary>
00790   // Class containing the results of aggregated values in a group.
00791   // </summary>
00792   // <use visibility=local>
00793   // <reviewed reviewer="" date="" tests="tExprGroup">
00794   // </reviewed>
00795   // <synopsis>
00796   // This class contains the set of aggregate function objects containing
00797   // all aggregate results of a particular GROUPBY group.
00798   // It also contains the TableExprId of the last row in the group.
00799   // It is used for possible non-aggregate expressions.
00800   // </synopsis>
00801   class TableExprGroupFuncSet
00802   {
00803   public:
00804     TableExprGroupFuncSet()
00805       : itsId (0)
00806     {}
00807 
00808     // Let the aggregate node objects construct the function set.
00809     TableExprGroupFuncSet (const vector<TableExprNodeRep*>& aggrNodes);
00810 
00811     // Add a function object.
00812     void add (const CountedPtr<TableExprGroupFuncBase>& func);
00813 
00814     // Apply the functions to the given row.
00815     void apply (const TableExprId& id);
00816 
00817     // Get the vector of functions.
00818     const vector<CountedPtr<TableExprGroupFuncBase> >& getFuncs() const
00819       { return itsFuncs; }
00820 
00821     // Get the TableExprId.
00822     const TableExprId& getId() const
00823       { return itsId; }
00824 
00825   private:
00826     // Copying is not needed, thus not allowed.
00827     TableExprGroupFuncSet (const TableExprGroupFuncSet&);
00828     TableExprGroupFuncSet& operator= (const TableExprGroupFuncSet&);
00829 
00830     //# Data members.
00831     vector<CountedPtr<TableExprGroupFuncBase> > itsFuncs;
00832     TableExprId itsId;      //# row containing the non-aggregate variables
00833   };
00834 
00835 } //# NAMESPACE CASACORE - END
00836 
00837 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1