casacore
ExprGroup.h
Go to the documentation of this file.
1 //# ExprGroup.h: Classes handling TaQL's GROUPBY functionality
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_EXPRGROUP_H
29 #define TABLES_EXPRGROUP_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/BasicSL/String.h>
34 #include <casacore/tables/TaQL/ExprAggrNode.h>
35 #include <vector>
36 
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40  // <summary>
41  // Class representing a key in the groupby clause.
42  // </summary>
43  // <use visibility=local>
44  // <reviewed reviewer="" date="" tests="tTableGram">
45  // </reviewed>
46  // <synopsis>
47  // The GROUPBY clause consists of one or more keys, each being a scalar
48  // TaQL expression with an arbitrary data type.
49  // This class contains the value of a key for a particular table row.
50  // It is part of a TableExprGroupKeySet object.
51  // </synopsis>
53  {
54  public:
55  // Construct for a given data type.
57  : itsDT (dtype)
58  {}
59 
60  // Get the data type.
62  { return itsDT; }
63 
64  // Set the key's value.
65  // <group>
66  void set (Bool v)
67  { itsBool = v; }
68  void set (Int64 v)
69  { itsInt64 = v; }
70  void set (Double v)
71  { itsDouble = v; }
72  void set (const String& v)
73  { itsString = v; }
74  // </group>
75 
76  // Compare this and that key.
77  // <group>
78  bool operator== (const TableExprGroupKey&) const;
79  bool operator< (const TableExprGroupKey&) const;
80  // </group>
81 
82  private:
88  };
89 
90 
91  // <summary>
92  // Class representing all keys in the groupby clause.
93  // </summary>
94  // <use visibility=local>
95  // <reviewed reviewer="" date="" tests="tTableGram">
96  // </reviewed>
97  // <synopsis>
98  // The GROUPBY clause consists of one or more keys, each being a scalar
99  // TaQL expression with an arbitrary data type.
100  // This class contains a set of TableExprGroupKey objects, each containing
101  // the value of a key for a particular table row.
102  // <br>It contains comparison functions to make it possible to use them
103  // in a std::map object to map the groupby keyset to a group.
104  // </synopsis>
106  {
107  public:
108  // Form the object from the given groupby nodes.
109  TableExprGroupKeySet (const vector<TableExprNode>& nodes);
110 
111  // Add a key to end the set.
113  { itsKeys.push_back (TableExprGroupKey(dtype)); }
114 
115  // Fill the keys with the values from the nodes for this rowid.
116  void fill (const vector<TableExprNode>& nodes, const TableExprId& id);
117 
118  // Compare all keys in the set.
119  // The keyset is compared in order of key, thus the first key defines
120  // the major ordering.
121  bool operator== (const TableExprGroupKeySet&) const;
122  bool operator< (const TableExprGroupKeySet&) const;
123 
124  private:
125  vector<TableExprGroupKey> itsKeys;
126  };
127 
128 
129  // <summary>
130  // Class holding the results of groupby and aggregation
131  // </summary>
132  // <use visibility=local>
133  // <reviewed reviewer="" date="" tests="tTableGram">
134  // </reviewed>
135  // <synopsis>
136  // The SELECT (and HAVING) clause can contain aggregate functions
137  // of which the results can be grouped using the GROUPBY clause.
138  // This class holds the results of the (immediate) aggregate functions
139  // and, if needed, the TableExprId ids of all rows belonging to each group.
140  // These ids are used to evaluate the lazy aggregate functions.
141  // <br>An object of this class is part of the TableExprIdAggr object
142  // used to get the aggregated values of each group.
143  // </synopsis>
145  {
146  public:
147  // Create from the possible set of immediate aggregate functions.
148  // No immediate functions were used, thus no TableExprIds needed.
149  explicit TableExprGroupResult
150  (const vector<CountedPtr<TableExprGroupFuncSet> >& funcSets);
151  // Create from the possible set of immediate aggregate functions
152  // and the set of TableExprIds per group for lazy aggregate functions.
154  (const vector<CountedPtr<TableExprGroupFuncSet> >& funcSets,
155  const vector<CountedPtr<vector<TableExprId> > >& ids);
156  // Get the nr of groups.
157  uInt ngroup() const
158  { return itsFuncSets.size(); }
159  // Get the set of functions (and their results) for the given group.
161  { return *itsFuncSets[group]; }
162  // Get the set of TableExprIds for the given group.
163  const vector<TableExprId>& ids (uInt group) const
164  { return *itsIds[group]; }
165  private:
166  vector<CountedPtr<TableExprGroupFuncSet> > itsFuncSets;
167  vector<CountedPtr<vector<TableExprId> > > itsIds;
168  };
169 
170 
171  // <summary>
172  // Abstract base class for classes calculating an aggregated group result.
173  // </summary>
174  // <use visibility=local>
175  // <reviewed reviewer="" date="" tests="tExprGroup">
176  // </reviewed>
177  // <synopsis>
178  // The GROUPBY clause divides a table into groups for which aggregated
179  // results can be calculated like the mean or minimum. These results are
180  // calculated in classes derived from this abstract base class.
181  // <br>There is one such function object per aggregation per group. All
182  // aggregation objects of a group are combined in a std::vector.
183  // This vector is mapped to a TableExprGroupKeySet object to keep track
184  // of all groups and aggregations.
185  // <br> There are two types of aggregation function classes.
186  // <ul>
187  // <li> Immediate classes implement the 'apply' function to immediately
188  // apply the operand's value in the aggregation.
189  // Such classes do not keep the operand's values.
190  // <li> Lazy classes do not need the 'apply' function. Instead they
191  // read all values of the group in the 'getXXX' function and do the
192  // aggregation. Such classes are meant for aggregation functions
193  // like 'median' that need to keep all values. When applying it
194  // immediately, all groups need to keep their values which might need
195  // too much memory. Lazy classes need the values of only one group
196  // at a time, but have the disadvantage that reading the values from
197  // the table might be done in a non-sequential order.
198  // </ul>
199  // Most derived classes are immediate classes.
200  // </synopsis>
202  {
203  public:
204  // Construct from the TaQL aggregation node. It keeps the operand
205  // of the aggregation node.
206  explicit TableExprGroupFuncBase (TableExprNodeRep* node);
207  virtual ~TableExprGroupFuncBase();
208  // Does the aggregate function use lazy semantics?
209  // The default implementation returns False.
210  virtual Bool isLazy() const;
211  // Get the function's sequence nr.
212  uInt seqnr() const
213  { return itsSeqnr; }
214  // Set the function's sequence nr.
215  void setSeqnr (uInt seqnr)
216  { itsSeqnr = seqnr; }
217  // Get the operand's value for the given row and apply it to the aggregation.
218  // This function should not be called for lazy classes.
219  virtual void apply (const TableExprId& id) = 0;
220  // If needed, finish the aggregation.
221  // By default nothing is done.
222  virtual void finish();
223  // Get the assembled TableExprIds of a group. It is specifically meant
224  // for TableExprGroupExprId used for lazy aggregation.
225  virtual CountedPtr<vector<TableExprId> > getIds() const;
226  // Get the aggregated value.
227  // Immediate classes can return the already calculated value, while
228  // lazy classes will get the values of all rows given by the TableExprIds
229  // and do the aggregation.
230  // <group>
231  virtual Bool getBool (const vector<TableExprId>& = vector<TableExprId>());
232  virtual Int64 getInt (const vector<TableExprId>& = vector<TableExprId>());
233  virtual Double getDouble (const vector<TableExprId>& = vector<TableExprId>());
234  virtual DComplex getDComplex (const vector<TableExprId>& = vector<TableExprId>());
235  virtual MVTime getDate (const vector<TableExprId>& = vector<TableExprId>());
236  virtual String getString (const vector<TableExprId>& = vector<TableExprId>());
237  virtual Array<Bool> getArrayBool (const vector<TableExprId>& = vector<TableExprId>());
238  virtual Array<Int64> getArrayInt (const vector<TableExprId>& = vector<TableExprId>());
239  virtual Array<Double> getArrayDouble (const vector<TableExprId>& = vector<TableExprId>());
240  virtual Array<DComplex> getArrayDComplex (const vector<TableExprId>& = vector<TableExprId>());
241  virtual Array<MVTime> getArrayDate (const vector<TableExprId>& = vector<TableExprId>());
242  virtual Array<String> getArrayString (const vector<TableExprId>& = vector<TableExprId>());
243  // <group>
244  private:
245  // Copying is not needed, thus not allowed.
248  protected:
249  //# Data member
253  };
254 
255 
256  // <summary>
257  // Class derived from TableExprGroupFuncBase representing a no function
258  // </summary>
259  // <use visibility=local>
260  // <reviewed reviewer="" date="" tests="tExprGroup">
261  // </reviewed>
262  // <synopsis>
263  // This class represents a null aggregate function which is meant for
264  // possible aggregate functionality in UDFs.
265  // </synopsis>
267  {
268  public:
269  explicit TableExprGroupNull (TableExprNodeRep* node);
270  virtual ~TableExprGroupNull();
271  virtual Bool isLazy() const;
272  virtual void apply (const TableExprId& id);
273  };
274 
275  // <summary>
276  // Class derived from TableExprGroupFuncBase for the first value in a group
277  // </summary>
278  // <use visibility=local>
279  // <reviewed reviewer="" date="" tests="tExprGroup">
280  // </reviewed>
281  // <synopsis>
282  // This class keeps the TableExprId of the first value in a group.
283  // The 'getXXX' functions get the value for that TableExprId.
284  // </synopsis>
286  {
287  public:
288  explicit TableExprGroupFirst (TableExprNodeRep* node);
289  virtual ~TableExprGroupFirst();
290  virtual void apply (const TableExprId& id);
291  virtual Bool getBool (const vector<TableExprId>&);
292  virtual Int64 getInt (const vector<TableExprId>&);
293  virtual Double getDouble (const vector<TableExprId>&);
294  virtual DComplex getDComplex (const vector<TableExprId>&);
295  virtual MVTime getDate (const vector<TableExprId>&);
296  virtual String getString (const vector<TableExprId>&);
297  virtual Array<Bool> getArrayBool (const vector<TableExprId>&);
298  virtual Array<Int64> getArrayInt (const vector<TableExprId>&);
299  virtual Array<Double> getArrayDouble (const vector<TableExprId>&);
300  virtual Array<DComplex> getArrayDComplex (const vector<TableExprId>&);
301  virtual Array<MVTime> getArrayDate (const vector<TableExprId>&);
302  virtual Array<String> getArrayString (const vector<TableExprId>&);
303  protected:
305  };
306 
307  // <summary>
308  // Class derived from TableExprGroupFuncBase for the first value in a group
309  // </summary>
310  // <use visibility=local>
311  // <reviewed reviewer="" date="" tests="tExprGroup">
312  // </reviewed>
313  // <synopsis>
314  // This class keeps the TableExprId of the last value in a group.
315  // The 'getXXX' functions get the value for that TableExprId.
316  // <br>For ease of use this class is derived from TableExprGroupFirst.
317  // </synopsis>
319  {
320  public:
321  explicit TableExprGroupLast (TableExprNodeRep* node);
322  virtual ~TableExprGroupLast();
323  virtual void apply (const TableExprId& id);
324  };
325 
326  // <summary>
327  // Class derived from TableExprGroupFuncBase collecting the ids in a group
328  // </summary>
329  // <use visibility=local>
330  // <reviewed reviewer="" date="" tests="tExprGroup">
331  // </reviewed>
332  // <synopsis>
333  // This class keeps all TableExprIds in a group.
334  // It is meant for lazy aggregation classes which use the collected
335  // TableExprIds in their 'getXXX' functions.
336  // </synopsis>
338  {
339  public:
340  explicit TableExprGroupExprId (TableExprNodeRep* node);
341  virtual ~TableExprGroupExprId();
342  virtual Bool isLazy() const;
343  virtual void apply (const TableExprId& id);
344  virtual CountedPtr<vector<TableExprId> > getIds() const;
345  private:
347  };
348 
349  // <summary>
350  // Class collecting the rowids of entries in a group.
351  // </summary>
352  // <use visibility=local>
353  // <reviewed reviewer="" date="" tests="tExprGroup">
354  // </reviewed>
355  // <synopsis>
356  // This class collects the row numbers of the rows in a group.
357  // </synopsis>
359  {
360  public:
361  explicit TableExprGroupRowid (TableExprNodeRep* node);
362  virtual ~TableExprGroupRowid();
363  virtual Bool isLazy() const;
364  virtual void apply (const TableExprId& id);
365  virtual Array<Int64> getArrayInt (const vector<TableExprId>&);
366  };
367 
368  // <summary>
369  // Class collecting the arrays in a group.
370  // </summary>
371  // <use visibility=local>
372  // <reviewed reviewer="" date="" tests="tExprGroup">
373  // </reviewed>
374  // <synopsis>
375  // This class collects the non-empty arrays in a group into an array with
376  // one more axis. All arrays (if not empty) must have the same shape.
377  // </synopsis>
379  {
380  public:
381  explicit TableExprGroupAggr (TableExprNodeRep* node);
382  virtual ~TableExprGroupAggr();
383  virtual Bool isLazy() const;
384  virtual void apply (const TableExprId& id);
385  virtual Array<Bool> getArrayBool (const vector<TableExprId>&);
386  virtual Array<Int64> getArrayInt (const vector<TableExprId>&);
387  virtual Array<Double> getArrayDouble (const vector<TableExprId>&);
388  virtual Array<DComplex> getArrayDComplex (const vector<TableExprId>&);
389  virtual Array<MVTime> getArrayDate (const vector<TableExprId>&);
390  virtual Array<String> getArrayString (const vector<TableExprId>&);
391  protected:
392  template<typename T>
393  Array<T> getArray (const vector<TableExprId>& ids)
394  {
395  // Return scalar values as a Vector.
396  if (itsOperand->valueType() == TableExprNodeRep::VTScalar) {
397  Vector<T> result(ids.size());
398  for (size_t i=0; i<ids.size(); ++i) {
399  itsOperand->get (ids[i], result[i]);
400  }
401  return result;
402  }
403  // Array values are returned as an array with one more axis.
404  // Get the first value to determine the shape.
405  Array<T> arr;
406  itsOperand->get (ids[0], arr);
407  IPosition shp = arr.shape();
408  shp.append (IPosition (1, ids.size()));
409  Array<T> result(shp);
410  ArrayIterator<T> iter (result, arr.ndim());
411  iter.array() = arr;
412  iter.next();
413  int i=1;
414  while (! iter.pastEnd()) {
415  itsOperand->get (ids[i], iter.array());
416  iter.next();
417  i++;
418  }
419  return result;
420  }
421  };
422 
423 
424  // <summary>
425  // Abstract base class for aggregate functions giving a bool scalar.
426  // </summary>
427  // <use visibility=local>
428  // <reviewed reviewer="" date="" tests="tExprGroup">
429  // </reviewed>
430  // <synopsis>
431  // This class is derived from TableExprGroupFuncBase and act as the
432  // abstract base class for aggregate functions resulting in a bool scalar.
433  // <br>Derived classes can use <src>itsValue</src> to contain the
434  // aggregated value. It that case they do not need to implement the
435  // <src>get</src> function.
436  // </synopsis>
438  {
439  public:
441  : TableExprGroupFuncBase (node)
442  {}
444  : TableExprGroupFuncBase (node),
445  itsValue (initValue)
446  {}
447  virtual ~TableExprGroupFuncBool();
448  virtual Bool getBool (const vector<TableExprId>&);
449  protected:
451  };
452 
453  // <summary>
454  // Abstract base class for aggregate functions giving an integer scalar.
455  // </summary>
456  // <use visibility=local>
457  // <reviewed reviewer="" date="" tests="tExprGroup">
458  // </reviewed>
459  // <synopsis>
460  // This class is derived from TableExprGroupFuncBase and act as the
461  // abstract base class for aggregate functions resulting in an integer scalar.
462  // <br>Derived classes can use <src>itsValue</src> to contain the
463  // aggregated value. It that case they do not need to implement the
464  // <src>get</src> function.
465  // </synopsis>
467  {
468  public:
469  explicit TableExprGroupFuncInt (TableExprNodeRep* node, Int64 initValue=0)
470  : TableExprGroupFuncBase (node),
471  itsValue (initValue)
472  {}
473  virtual ~TableExprGroupFuncInt();
474  virtual Int64 getInt (const vector<TableExprId>&);
475  virtual Double getDouble (const vector<TableExprId>&);
476  protected:
478  };
479 
480  // <summary>
481  // Abstract base class for aggregate functions giving a double scalar.
482  // </summary>
483  // <use visibility=local>
484  // <reviewed reviewer="" date="" tests="tExprGroup">
485  // </reviewed>
486  // <synopsis>
487  // This class is derived from TableExprGroupFuncBase and act as the
488  // abstract base class for aggregate functions resulting in a double scalar.
489  // <br>Derived classes can use <src>itsValue</src> to contain the
490  // aggregated value. It that case they do not need to implement the
491  // <src>get</src> function.
492  // </synopsis>
494  {
495  public:
497  Double initValue = 0)
498  : TableExprGroupFuncBase (node),
499  itsValue (initValue)
500  {}
501  virtual ~TableExprGroupFuncDouble();
502  virtual Double getDouble (const vector<TableExprId>&);
503  protected:
505  };
506 
507  // <summary>
508  // Abstract base class for aggregate functions giving a dcomplex scalar.
509  // </summary>
510  // <use visibility=local>
511  // <reviewed reviewer="" date="" tests="tExprGroup">
512  // </reviewed>
513  // <synopsis>
514  // This class is derived from TableExprGroupFuncBase and act as the
515  // abstract base class for aggregate functions resulting in a dcomplex scalar.
516  // <br>Derived classes can use <src>itsValue</src> to contain the
517  // aggregated value. It that case they do not need to implement the
518  // <src>get</src> function.
519  // </synopsis>
521  {
522  public:
524  const DComplex& initValue = DComplex())
525  : TableExprGroupFuncBase (node),
526  itsValue (initValue)
527  {}
528  virtual ~TableExprGroupFuncDComplex();
529  virtual DComplex getDComplex (const vector<TableExprId>&);
530  protected:
532  };
533 
534  // <summary>
535  // Abstract base class for aggregate functions giving a date/time scalar.
536  // </summary>
537  // <use visibility=local>
538  // <reviewed reviewer="" date="" tests="tExprGroup">
539  // </reviewed>
540  // <synopsis>
541  // This class is derived from TableExprGroupFuncBase and act as the
542  // abstract base class for aggregate functions resulting in a date/time scalar.
543  // <br>Derived classes can use <src>itsValue</src> to contain the
544  // aggregated value. It that case they do not need to implement the
545  // <src>get</src> function.
546  // </synopsis>
548  {
549  public:
551  const MVTime& initValue = MVTime())
552  : TableExprGroupFuncBase (node),
553  itsValue (initValue)
554  {}
555  virtual ~TableExprGroupFuncDate();
556  virtual MVTime getDate (const vector<TableExprId>&);
557  protected:
559  };
560 
561  // <summary>
562  // Abstract base class for aggregate functions giving a string scalar.
563  // </summary>
564  // <use visibility=local>
565  // <reviewed reviewer="" date="" tests="tExprGroup">
566  // </reviewed>
567  // <synopsis>
568  // This class is derived from TableExprGroupFuncBase and act as the
569  // abstract base class for aggregate functions resulting in a string scalar.
570  // <br>Derived classes can use <src>itsValue</src> to contain the
571  // aggregated value. It that case they do not need to implement the
572  // <src>get</src> function.
573  // </synopsis>
575  {
576  public:
578  const String& initValue = String())
579  : TableExprGroupFuncBase (node),
580  itsValue (initValue)
581  {}
582  virtual ~TableExprGroupFuncString();
583  virtual String getString (const vector<TableExprId>&);
584  protected:
586  };
587 
588  // <summary>
589  // Abstract base class for aggregate functions giving a bool array.
590  // </summary>
591  // <use visibility=local>
592  // <reviewed reviewer="" date="" tests="tExprGroup">
593  // </reviewed>
594  // <synopsis>
595  // This class is derived from TableExprGroupFuncBase and act as the
596  // abstract base class for aggregate functions resulting in a bool array.
597  // <br>Derived classes can use <src>itsValue</src> to contain the
598  // aggregated value. It that case they do not need to implement the
599  // <src>get</src> function.
600  // </synopsis>
602  {
603  public:
605  : TableExprGroupFuncBase (node)
606  {}
607  virtual ~TableExprGroupFuncArrayBool();
608  virtual Array<Bool> getArrayBool (const vector<TableExprId>&);
609  protected:
610  // If not empty, check if the shape matches that of <src>itsValue</src>.
611  // If <src>itsValue</src> is still empty, it is sized.
612  Bool checkShape (const ArrayBase& arr, const String& func);
614  };
615 
616  // <summary>
617  // Abstract base class for aggregate functions giving an integer array.
618  // </summary>
619  // <use visibility=local>
620  // <reviewed reviewer="" date="" tests="tExprGroup">
621  // </reviewed>
622  // <synopsis>
623  // This class is derived from TableExprGroupFuncBase and act as the
624  // abstract base class for aggregate functions resulting in an integer array.
625  // <br>Derived classes can use <src>itsValue</src> to contain the
626  // aggregated value. It that case they do not need to implement the
627  // <src>get</src> function.
628  // </synopsis>
630  {
631  public:
633  : TableExprGroupFuncBase (node)
634  {}
635  virtual ~TableExprGroupFuncArrayInt();
636  virtual Array<Int64> getArrayInt (const vector<TableExprId>&);
637  protected:
638  // If not empty, check if the shape matches that of <src>itsValue</src>.
639  // If <src>itsValue</src> is still empty, it is sized.
640  Bool checkShape (const ArrayBase& arr, const String& func);
642  };
643 
644  // <summary>
645  // Abstract base class for aggregate functions giving a double array.
646  // </summary>
647  // <use visibility=local>
648  // <reviewed reviewer="" date="" tests="tExprGroup">
649  // </reviewed>
650  // <synopsis>
651  // This class is derived from TableExprGroupFuncBase and act as the
652  // abstract base class for aggregate functions resulting in a double array.
653  // <br>Derived classes can use <src>itsValue</src> to contain the
654  // aggregated value. It that case they do not need to implement the
655  // <src>get</src> function.
656  // </synopsis>
658  {
659  public:
661  : TableExprGroupFuncBase (node)
662  {}
664  virtual Array<Double> getArrayDouble (const vector<TableExprId>&);
665  protected:
666  // If not empty, check if the shape matches that of <src>itsValue</src>.
667  // If <src>itsValue</src> is still empty, it is sized.
668  Bool checkShape (const ArrayBase& arr, const String& func);
670  };
671 
672  // <summary>
673  // Abstract base class for aggregate functions giving a dcomplex array.
674  // </summary>
675  // <use visibility=local>
676  // <reviewed reviewer="" date="" tests="tExprGroup">
677  // </reviewed>
678  // <synopsis>
679  // This class is derived from TableExprGroupFuncBase and act as the
680  // abstract base class for aggregate functions resulting in a dcomplex array.
681  // <br>Derived classes can use <src>itsValue</src> to contain the
682  // aggregated value. It that case they do not need to implement the
683  // <src>get</src> function.
684  // </synopsis>
686  {
687  public:
689  : TableExprGroupFuncBase (node)
690  {}
692  virtual Array<DComplex> getArrayDComplex (const vector<TableExprId>&);
693  protected:
694  // If not empty, check if the shape matches that of <src>itsValue</src>.
695  // If <src>itsValue</src> is still empty, it is sized.
696  Bool checkShape (const ArrayBase& arr, const String& func);
698  };
699 
700  // <summary>
701  // Abstract base class for aggregate functions giving a date/time array.
702  // </summary>
703  // <use visibility=local>
704  // <reviewed reviewer="" date="" tests="tExprGroup">
705  // </reviewed>
706  // <synopsis>
707  // This class is derived from TableExprGroupFuncBase and act as the
708  // abstract base class for aggregate functions resulting in a date/time array.
709  // <br>Derived classes can use <src>itsValue</src> to contain the
710  // aggregated value. It that case they do not need to implement the
711  // <src>get</src> function.
712  // </synopsis>
714  {
715  public:
717  : TableExprGroupFuncBase (node)
718  {}
719  virtual ~TableExprGroupFuncArrayDate();
720  virtual Array<MVTime> getArrayDate (const vector<TableExprId>&);
721  protected:
722  // If not empty, check if the shape matches that of <src>itsValue</src>.
723  // If <src>itsValue</src> is still empty, it is sized.
724  Bool checkShape (const ArrayBase& arr, const String& func);
726  };
727 
728  // <summary>
729  // Abstract base class for aggregate functions giving a string array.
730  // </summary>
731  // <use visibility=local>
732  // <reviewed reviewer="" date="" tests="tExprGroup">
733  // </reviewed>
734  // <synopsis>
735  // This class is derived from TableExprGroupFuncBase and act as the
736  // abstract base class for aggregate functions resulting in a string array.
737  // <br>Derived classes can use <src>itsValue</src> to contain the
738  // aggregated value. It that case they do not need to implement the
739  // <src>get</src> function.
740  // </synopsis>
742  {
743  public:
745  : TableExprGroupFuncBase (node)
746  {}
748  virtual Array<String> getArrayString (const vector<TableExprId>&);
749  protected:
750  // If not empty, check if the shape matches that of <src>itsValue</src>.
751  // If <src>itsValue</src> is still empty, it is sized.
752  Bool checkShape (const ArrayBase& arr, const String& func);
754  };
755 
756 
757  // <summary>
758  // Class containing the results of aggregated values in a group.
759  // </summary>
760  // <use visibility=local>
761  // <reviewed reviewer="" date="" tests="tExprGroup">
762  // </reviewed>
763  // <synopsis>
764  // This class contains the set of aggregate function objects containing
765  // all aggregate results of a particular GROUPBY group.
766  // It also contains the TableExprId of the last row in the group.
767  // It is used for possible non-aggregate expressions.
768  // </synopsis>
770  {
771  public:
773  : itsId (0)
774  {}
775 
776  // Let the aggregate node objects construct the function set.
777  TableExprGroupFuncSet (const vector<TableExprNodeRep*>& aggrNodes);
778 
779  // Add a function object.
780  void add (const CountedPtr<TableExprGroupFuncBase>& func);
781 
782  // Apply the functions to the given row.
783  void apply (const TableExprId& id);
784 
785  // Get the vector of functions.
786  const vector<CountedPtr<TableExprGroupFuncBase> >& getFuncs() const
787  { return itsFuncs; }
788 
789  // Get the TableExprId.
790  const TableExprId& getId() const
791  { return itsId; }
792 
793  private:
794  // Copying is not needed, thus not allowed.
797 
798  //# Data members.
799  vector<CountedPtr<TableExprGroupFuncBase> > itsFuncs;
800  TableExprId itsId; //# row containing the non-aggregate variables
801  };
802 
803 } //# NAMESPACE CASACORE - END
804 
805 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
TableExprGroupFuncDate(TableExprNodeRep *node, const MVTime &initValue=MVTime())
Definition: ExprGroup.h:550
TableExprNodeRep * itsNode
Definition: ExprGroup.h:250
uInt seqnr() const
Get the function&#39;s sequence nr.
Definition: ExprGroup.h:212
A 1-D Specialization of the Array class.
Definition: ArrayIO.h:45
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
Abstract base class for aggregate functions giving a dcomplex scalar.
Definition: ExprGroup.h:520
TableExprGroupKey(TableExprNodeRep::NodeDataType dtype)
Construct for a given data type.
Definition: ExprGroup.h:56
Non-templated base class for templated Array class.
Definition: ArrayBase.h:74
Class holding the results of groupby and aggregation.
Definition: ExprGroup.h:144
vector< TableExprGroupKey > itsKeys
Definition: ExprGroup.h:125
TableExprGroupFuncArrayString(TableExprNodeRep *node)
Definition: ExprGroup.h:744
TableExprNodeRep * itsOperand
Definition: ExprGroup.h:251
uInt ngroup() const
Get the nr of groups.
Definition: ExprGroup.h:157
Class derived from TableExprGroupFuncBase representing a no function.
Definition: ExprGroup.h:266
CountedPtr< vector< TableExprId > > itsIds
Definition: ExprGroup.h:346
TableExprGroupFuncString(TableExprNodeRep *node, const String &initValue=String())
Definition: ExprGroup.h:577
TableExprGroupFuncBool(TableExprNodeRep *node)
Definition: ExprGroup.h:440
Abstract base class for aggregate functions giving a string scalar.
Definition: ExprGroup.h:574
bool operator==(const TableExprGroupKey &) const
Compare this and that key.
TableExprGroupFuncArrayDComplex(TableExprNodeRep *node)
Definition: ExprGroup.h:688
Class derived from TableExprGroupFuncBase collecting the ids in a group.
Definition: ExprGroup.h:337
PtrHolder< T > & operator=(const PtrHolder< T > &other)
bool operator<(const TableExprGroupKey &) const
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
Abstract base class for aggregate functions giving a double scalar.
Definition: ExprGroup.h:493
const TableExprId & getId() const
Get the TableExprId.
Definition: ExprGroup.h:790
Class collecting the arrays in a group.
Definition: ExprGroup.h:378
Iterate an Array cursor through another Array.
Definition: Array.h:54
TableExprGroupFuncBool(TableExprNodeRep *node, Bool initValue)
Definition: ExprGroup.h:443
void append(const IPosition &other)
Append this IPosition with another one (causing a resize).
TableExprGroupFuncInt(TableExprNodeRep *node, Int64 initValue=0)
Definition: ExprGroup.h:469
Class derived from TableExprGroupFuncBase for the first value in a group.
Definition: ExprGroup.h:285
TableExprNodeRep::NodeDataType dataType() const
Get the data type.
Definition: ExprGroup.h:61
TableExprGroupFuncSet & funcSet(uInt group) const
Get the set of functions (and their results) for the given group.
Definition: ExprGroup.h:160
void setSeqnr(uInt seqnr)
Set the function&#39;s sequence nr.
Definition: ExprGroup.h:215
Abstract base class for aggregate functions giving a double array.
Definition: ExprGroup.h:657
Abstract base class for aggregate functions giving a date/time scalar.
Definition: ExprGroup.h:547
TableExprGroupFuncArrayInt(TableExprNodeRep *node)
Definition: ExprGroup.h:632
TableExprGroupFuncArrayDate(TableExprNodeRep *node)
Definition: ExprGroup.h:716
Referenced counted pointer for constant data.
Definition: CountedPtr.h:86
Abstract base class for aggregate functions giving a bool array.
Definition: ExprGroup.h:601
uInt ndim() const
The dimensionality of this array.
Definition: ArrayBase.h:94
Abstract base class for aggregate functions giving a bool scalar.
Definition: ExprGroup.h:437
vector< CountedPtr< TableExprGroupFuncBase > > itsFuncs
Definition: ExprGroup.h:799
double Double
Definition: aipstype.h:52
Class derived from TableExprGroupFuncBase for the first value in a group.
Definition: ExprGroup.h:318
vector< CountedPtr< vector< TableExprId > > > itsIds
Definition: ExprGroup.h:167
TableExprNodeRep::NodeDataType itsDT
Definition: ExprGroup.h:83
TableExprGroupFuncArrayBool(TableExprNodeRep *node)
Definition: ExprGroup.h:604
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
Abstract base class for aggregate functions giving a date/time array.
Definition: ExprGroup.h:713
const vector< TableExprId > & ids(uInt group) const
Get the set of TableExprIds for the given group.
Definition: ExprGroup.h:163
vector< CountedPtr< TableExprGroupFuncSet > > itsFuncSets
Definition: ExprGroup.h:166
Class containing the results of aggregated values in a group.
Definition: ExprGroup.h:769
Array< T > getArray(const vector< TableExprId > &ids)
Definition: ExprGroup.h:393
TableExprGroupFuncArrayDouble(TableExprNodeRep *node)
Definition: ExprGroup.h:660
Abstract base class for classes calculating an aggregated group result.
Definition: ExprGroup.h:201
void addKey(TableExprNodeRep::NodeDataType dtype)
Add a key to end the set.
Definition: ExprGroup.h:112
The identification of a TaQL selection subject.
Definition: TableExprId.h:98
Class representing all keys in the groupby clause.
Definition: ExprGroup.h:105
Abstract base class for aggregate functions giving a dcomplex array.
Definition: ExprGroup.h:685
Class representing a key in the groupby clause.
Definition: ExprGroup.h:52
Abstract base class for aggregate functions giving an integer scalar.
Definition: ExprGroup.h:466
String: the storage and methods of handling collections of characters.
Definition: String.h:223
TableExprGroupFuncDComplex(TableExprNodeRep *node, const DComplex &initValue=DComplex())
Definition: ExprGroup.h:523
Abstract base class for aggregate functions giving an integer array.
Definition: ExprGroup.h:629
Array< T > & array()
Return the cursor.
Definition: ArrayIter.h:118
Class to handle date/time type conversions and I/O.
Definition: MVTime.h:266
Class collecting the rowids of entries in a group.
Definition: ExprGroup.h:358
Abstract base class for aggregate functions giving a string array.
Definition: ExprGroup.h:741
TableExprGroupFuncDouble(TableExprNodeRep *node, Double initValue=0)
Definition: ExprGroup.h:496
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48
const IPosition & shape() const
The length of each axis.
Definition: ArrayBase.h:121
const vector< CountedPtr< TableExprGroupFuncBase > > & getFuncs() const
Get the vector of functions.
Definition: ExprGroup.h:786