casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExprNodeRep.h
Go to the documentation of this file.
1 //# ExprNodeRep.h: Abstract base class for a node in a table column expression tree
2 //# Copyright (C) 1994,1995,1996,1997,1998,2000,2001,2003
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: ExprNodeRep.h 21262 2012-09-07 12:38:36Z gervandiepen $
27 
28 #ifndef TABLES_EXPRNODEREP_H
29 #define TABLES_EXPRNODEREP_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
44 #include <casacore/casa/iosfwd.h>
45 #include <vector>
46 
47 namespace casacore { //# NAMESPACE CASACORE - BEGIN
48 
49 //# Forward Declarations
50 class TableExprNode;
51 class TableExprNodeColumn;
52 class TableExprGroupFuncBase;
53 template<class T> class Block;
54 
55 //# Define a shared pointer to the Rep class.
58 
59 
60 // <summary>
61 // Class to handle a Regex or StringDistance.
62 // </summary>
63 
64 // <use visibility=local>
65 
66 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
67 // </reviewed>
68 
69 // <prerequisite>
70 //# Classes you should understand before using this one.
71 // <li> <linkto class=Regex>Regex</linkto>
72 // <li> <linkto class=StringDistance>StringDistance</linkto>
73 // </prerequisite>
74 
75 // <synopsis>
76 // A StringDistance (Levensthein distance) in TaQL is given in the same way
77 // as a Regex. This class is needed to have a single object in the parse tree
78 // objects containing them (in class TableExprNodeConstRegex).
79 // </synopsis>
80 
81 class TaqlRegex
82 {
83 public:
84  // Construct from a regex.
85  explicit TaqlRegex (const Regex& regex)
86  : itsRegex(regex)
87  {}
88 
89  // Construct from a StringDistance.
90  explicit TaqlRegex (const StringDistance& dist)
91  : itsDist(dist)
92  {}
93 
94  // Does the regex or maximum string distance match?
95  Bool match (const String& str) const
96  { return itsRegex.regexp().empty() ?
97  itsDist.match(str) : str.matches(itsRegex);
98  }
99 
100  // Return the regular expression.
101  const Regex& regex() const
102  { return itsRegex; }
103 
104 private:
107 };
108 
109 
110 
111 // <summary>
112 // Abstract base class for a node in a table column expression tree
113 // </summary>
114 
115 // <use visibility=local>
116 
117 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
118 // </reviewed>
119 
120 // <prerequisite>
121 //# Classes you should understand before using this one.
122 // <li> <linkto class=TableExprNode>TableExprNode</linkto>
123 // </prerequisite>
124 
125 // <etymology>
126 // TableExprNodeRep is the (abstract) REPresentation of a node in a table
127 // expression tree.
128 // </etymology>
129 
130 // <synopsis>
131 // TableExprNodeRep is the base class for all nodes in a table
132 // expression tree. It is used by the handle class TableExprNode.
133 // <p>
134 // The objects of this class are reference-counted to make it possible
135 // that the same object is reused.
136 // </synopsis>
137 
138 // <motivation>
139 // TableExprNodeRep and its derivations store a table select expression
140 // before actually evaluating it. It is also possible that the classes
141 // are used by the table expression parser defined in TableParse and
142 // TableGram.
143 // <br>
144 // For each operator a special derived class is implemented.
145 // Another approach could have been to store the operator as
146 // a flag and switch on that. However, that causes extra overhead
147 // and the C++ virtual function mechanism is designed for
148 // these purposes.
149 // </motivation>
150 
151 // <todo asof="$DATE:$">
152 //# A List of bugs, limitations, extensions or planned refinements.
153 // <li> add selection by comparing with a set of values
154 // </todo>
155 
156 
158 {
159 public:
160  // Define the data types of a node.
169  NTReal, //# NTInt or NTDouble
170  NTDouCom, //# NTDouble or NTComplex
171  NTNumeric, //# NTInt, NTDouble, or NTComplex
172  NTAny //# Any data type
173  };
174 
175  // Define the value types.
176  enum ValueType {
183  };
184 
185  // Define the operator types.
186  // LE and LT are handled as GE and GT with swapped operands.
193  };
194 
195  // Define the value types of the 2 arguments when arrays are involved.
196  enum ArgType {
198  };
199 
200  // Define (sub-)expression type
201  enum ExprType {
202  // A constant subexpression which can be evaluated immediately.
204  // A variable (i.e. row dependent) subexpression which
205  // has to be evaluated for each table row.
207  // An expensive constant subexpression which should only be
208  // evaluated when needed (e.g. a subquery).
209 // Lazy
210  };
211 
212  // Construct a node.
214  Int ndim, const IPosition& shape,
215  const Table& table);
216 
217  // This constructor is called from the derived TableExprNodeRep.
219 
220  // Copy constructor.
222 
223  // The destructor deletes all the underlying TableExprNode objects.
224  virtual ~TableExprNodeRep();
225 
226  // Do not apply the selection.
227  virtual void disableApplySelection();
228 
229  // Re-create the column object for a selection of rows.
230  // The default implementation does nothing.
231  virtual void applySelection (const Vector<uInt>& rownrs);
232 
233  // Get the unit conversion factor.
234  // Default 1 is returned.
235  virtual Double getUnitFactor() const;
236 
237  // Throw an exception if an aggregate function is used in
238  // the expression node or its children.
239  void checkAggrFuncs();
240 
241  // Get the nodes representing an aggregate function.
242  virtual void getAggrNodes (std::vector<TableExprNodeRep*>& aggr);
243 
244  // Get the nodes representing a table column.
245  virtual void getColumnNodes (std::vector<TableExprNodeRep*>& cols);
246 
247  // Create the correct immediate aggregate function object.
248  // The default implementation throws an exception, because it should
249  // only be called for TableExprAggrNode(Array).
251 
252  // Is the aggregate function a lazy or an immediate one?
253  // The default implementation returns True
254  // (because all UDF aggregate functions have to be lazy).
255  virtual Bool isLazyAggregate() const;
256 
257  // Get a scalar value for this node in the given row.
258  // The appropriate functions are implemented in the derived classes and
259  // will usually invoke the get in their children and apply the
260  // operator on the resulting values.
261  // <group>
262  virtual Bool getBool (const TableExprId& id);
263  virtual Int64 getInt (const TableExprId& id);
264  virtual Double getDouble (const TableExprId& id);
265  virtual DComplex getDComplex (const TableExprId& id);
266  virtual String getString (const TableExprId& id);
267  virtual TaqlRegex getRegex (const TableExprId& id);
268  virtual MVTime getDate (const TableExprId& id);
269  // </group>
270 
271  // Get an array value for this node in the given row.
272  // The appropriate functions are implemented in the derived classes and
273  // will usually invoke the get in their children and apply the
274  // operator on the resulting values.
275  // <group>
276  virtual MArray<Bool> getArrayBool (const TableExprId& id);
277  virtual MArray<Int64> getArrayInt (const TableExprId& id);
278  virtual MArray<Double> getArrayDouble (const TableExprId& id);
279  virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
280  virtual MArray<String> getArrayString (const TableExprId& id);
281  virtual MArray<MVTime> getArrayDate (const TableExprId& id);
282  // </group>
283 
284  // General get functions for template purposes.
285  // <group>
286  void get (const TableExprId& id, Bool& value)
287  { value = getBool (id); }
288  void get (const TableExprId& id, Int64& value)
289  { value = getInt (id); }
290  void get (const TableExprId& id, Double& value)
291  { value = getDouble (id); }
292  void get (const TableExprId& id, DComplex& value)
293  { value = getDComplex (id); }
294  void get (const TableExprId& id, MVTime& value)
295  { value = getDate (id); }
296  void get (const TableExprId& id, String& value)
297  { value = getString (id); }
298  void get (const TableExprId& id, MArray<Bool>& value)
299  { value = getArrayBool (id); }
300  void get (const TableExprId& id, MArray<Int64>& value)
301  { value = getArrayInt (id); }
302  void get (const TableExprId& id, MArray<Double>& value)
303  { value = getArrayDouble (id); }
304  void get (const TableExprId& id, MArray<DComplex>& value)
305  { value = getArrayDComplex (id); }
306  void get (const TableExprId& id, MArray<MVTime>& value)
307  { value = getArrayDate (id); }
308  void get (const TableExprId& id, MArray<String>& value)
309  { value = getArrayString (id); }
310  // </group>
311 
312  // Get a value as an array, even it it is a scalar.
313  // This is useful if one could give an argument as scalar or array.
314  // <group>
315  MArray<Bool> getBoolAS (const TableExprId& id);
316  MArray<Int64> getIntAS (const TableExprId& id);
321  // </group>
322 
323  // Does a value occur in an array or set?
324  // The default implementation tests if it is in an array.
325  // <group>
326  virtual Bool hasBool (const TableExprId& id, Bool value);
327  virtual Bool hasInt (const TableExprId& id, Int64 value);
328  virtual Bool hasDouble (const TableExprId& id, Double value);
329  virtual Bool hasDComplex (const TableExprId& id, const DComplex& value);
330  virtual Bool hasString (const TableExprId& id, const String& value);
331  virtual Bool hasDate (const TableExprId& id, const MVTime& value);
332  virtual MArray<Bool> hasArrayBool (const TableExprId& id,
333  const MArray<Bool>& value);
334  virtual MArray<Bool> hasArrayInt (const TableExprId& id,
335  const MArray<Int64>& value);
336  virtual MArray<Bool> hasArrayDouble (const TableExprId& id,
337  const MArray<Double>& value);
338  virtual MArray<Bool> hasArrayDComplex (const TableExprId& id,
339  const MArray<DComplex>& value);
340  virtual MArray<Bool> hasArrayString (const TableExprId& id,
341  const MArray<String>& value);
342  virtual MArray<Bool> hasArrayDate (const TableExprId& id,
343  const MArray<MVTime>& value);
344  // </group>
345 
346  // Get the number of rows in the table associated with this expression.
347  // One is returned if the expression is a constant.
348  // Zero is returned if no table is associated with it.
349  uInt nrow() const;
350 
351  // Get the data type of the column.
352  // It returns True when it could set the data type (which it can
353  // if the expression is a scalar column or a constant array column pixel).
354  // Otherwise it returns False.
355  virtual Bool getColumnDataType (DataType&) const;
356 
357  // Get the value of the expression evaluated for the entire column.
358  // The data of function called should match the data type as
359  // returned by function <src>getColumnDataType</src>.
360  // <group>
361  virtual Array<Bool> getColumnBool (const Vector<uInt>& rownrs);
362  virtual Array<uChar> getColumnuChar (const Vector<uInt>& rownrs);
363  virtual Array<Short> getColumnShort (const Vector<uInt>& rownrs);
364  virtual Array<uShort> getColumnuShort (const Vector<uInt>& rownrs);
365  virtual Array<Int> getColumnInt (const Vector<uInt>& rownrs);
366  virtual Array<uInt> getColumnuInt (const Vector<uInt>& rownrs);
367  virtual Array<Int64> getColumnInt64 (const Vector<uInt>& rownrs);
368  virtual Array<Float> getColumnFloat (const Vector<uInt>& rownrs);
369  virtual Array<Double> getColumnDouble (const Vector<uInt>& rownrs);
370  virtual Array<Complex> getColumnComplex (const Vector<uInt>& rownrs);
371  virtual Array<DComplex> getColumnDComplex (const Vector<uInt>& rownrs);
372  virtual Array<String> getColumnString (const Vector<uInt>& rownrs);
373  // </group>
374 
375  // Convert the tree to a number of range vectors which at least
376  // select the same things.
377  // This function is very useful to convert the expression to
378  // some intervals covering the select expression. This can
379  // be used to do a rough fast selection via an index and do the
380  // the slower final selection on that much smaller subset.
381  // The function can only convert direct comparisons of columns
382  // with constants (via ==, !=, >, >=, < or <=) and their combinations
383  // using && or ||.
384  virtual void ranges (Block<TableExprRange>&);
385 
386  // Get the data type of the derived TableExprNode object.
387  // This is the data type of the resulting value. E.g. a compare
388  // of 2 numeric values results in a Bool, thus the data type
389  // of, say, TableExprNodeEQ<T> is always Bool.
390  // Function getInternalDT gives the internal data type, thus in
391  // the example above the data type of T.
392  NodeDataType dataType() const;
393 
394  // Is the data type real (i.e., integer or double)?
395  Bool isReal() const;
396 
397  // Get the value type.
398  ValueType valueType() const;
399 
400  // Set the value type.
401  void setValueType (ValueType vtype);
402 
403  // Get the operator type.
404  OperType operType() const;
405 
406  // Get the expression type.
407  ExprType exprType() const;
408 
409  // Is the expression a constant?
410  Bool isConstant() const;
411 
412  // Get the unit.
413  const Unit& unit() const;
414 
415  // Set the unit.
416  // It also sets the datatype to NTDouble if it is NTInt.
417  void setUnit (const Unit& unit);
418 
419  // Get the attributes.
420  const Record& attributes() const;
421 
422  // Set the attributes.
423  void setAttributes (const Record&);
424 
425  // Get the fixed dimensionality (same for all rows).
426  Int ndim() const;
427 
428  // Get the fixed shape (same for all rows).
429  const IPosition& shape() const;
430 
431  // Get the shape for the given row.
432  // It returns the fixed shape if defined, otherwise getShape(id).
433  const IPosition& shape (const TableExprId& id);
434 
435  // Is the value in the given row defined?
436  // The default implementation returns True.
437  virtual Bool isDefined (const TableExprId& id);
438 
439  // Show the expression tree.
440  virtual void show (ostream&, uInt indent) const;
441 
442  // Get table. This gets the Table object to which a
443  // TableExprNode belongs. A TableExprNode belongs to the Table to
444  // which the first column used in an expression belongs.
445  // <group>
446  Table& table();
447  const Table& table() const;
448  // </group>
449 
450  // Replace a node with a constant expression by node with its value.
451  static TENShPtr replaceConstNode (const TENShPtr& node);
452 
453  // Let a set node convert itself to the given unit.
454  // The default implementation does nothing.
455  virtual void adaptSetUnits (const Unit&);
456 
457  // Create a range object from a column and an interval.
458  static void createRange (Block<TableExprRange>&,
460 
461  // Create a empty range object.
462  static void createRange (Block<TableExprRange>&);
463 
464  // Convert a NodeDataType to a string.
465  static String typeString (NodeDataType);
466 
467  // Convert a ValueType to a string.
468  static String typeString (ValueType);
469 
470 protected:
471  Table table_p; //# Table from which node is "derived"
472  NodeDataType dtype_p; //# data type of the operation
473  ValueType vtype_p; //# value type of the result
474  OperType optype_p; //# operator type
475  ArgType argtype_p; //# argument types
476  ExprType exprtype_p; //# Constant or Variable
477  Int ndim_p; //# Fixed dimensionality of node values
478  //# -1 = variable dimensionality
479  IPosition shape_p; //# Fixed shape of node values
480  Unit unit_p; //# Unit of the values
481  Record attributes_p; //# Possible attributes (for UDFs)
482 
483  // Get the shape for the given row.
484  virtual const IPosition& getShape (const TableExprId& id);
485 
486  // If one of the children is a constant, convert its data type
487  // to that of the other operand (if appropriate).
488  // This avoids that conversions are done for each get.
489  // The default implementation does nothing.
490  virtual void convertConstChild();
491 
492  // Check if this node uses the same table pointer.
493  // Fill the Table object if it is still null.
494  // <group>
495  void checkTablePtr (const TENShPtr& node);
496  static void checkTablePtr (Table& table, const TENShPtr& node);
497  // </group>
498 
499  // Set expression type to Variable if node is Variable.
500  // <group>
501  void fillExprType (const TENShPtr& node);
502  static void fillExprType (ExprType&, const TENShPtr& node);
503  // </group>
504 
505  // If the node is constant, it is evaluated and replaced by
506  // the appropriate TableExprNodeConst object.
507  // If not constant, it calls the virtual ConvertConstChild function
508  // which can convert a constant child if appropriate.
509  static TENShPtr convertNode (const TENShPtr& thisNode,
510  Bool convertConstType);
511 
512 private:
513  // A copy of a TableExprNodeRep cannot be made.
515 };
516 
517 
518 
519 
520 
521 // <summary>
522 // Abstract base class for a node having 0, 1, or 2 child nodes.
523 // </summary>
524 
525 // <use visibility=local>
526 
527 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
528 // </reviewed>
529 
530 // <prerequisite>
531 //# Classes you should understand before using this one.
532 // <li> <linkto class=TableExprNodeRep>TableExprNodeRep</linkto>
533 // </prerequisite>
534 
535 // <etymology>
536 // TableExprNodeBinary is a node in the table expression tree
537 // representing a binary node (i.e. having up to 2 operands).
538 // </etymology>
539 
540 // <synopsis>
541 // TableExprNodeBinary is the abstract base class for all nodes in a table
542 // expression tree using up to 2 operands.
543 // It is used as the base class for the node classes representing
544 // operator +, -, etc..
545 // </synopsis>
546 
547 // <motivation>
548 // This class contains the common functionality for the classes
549 // representing a binary (or unary) operator.
550 // </motivation>
551 
552 //# <todo asof="$DATE:$">
553 //# A List of bugs, limitations, extensions or planned refinements.
554 //# <li> to be filled in
555 //# </todo>
556 
557 
559 {
560 public:
561  // Constructor
564 
565  // Destructor
566  virtual ~TableExprNodeBinary();
567 
568  // Show the expression tree.
569  virtual void show (ostream&, uInt indent) const;
570 
571  // Get the nodes representing an aggregate function.
572  virtual void getAggrNodes (std::vector<TableExprNodeRep*>& aggr);
573 
574  // Get the nodes representing a table column.
575  virtual void getColumnNodes (std::vector<TableExprNodeRep*>& cols);
576 
577  // Check the data types and get the common one.
578  static NodeDataType getDT (NodeDataType leftDtype,
579  NodeDataType rightDype,
581 
582  // Check the data and value types and get the common one.
583  static TableExprNodeRep getCommonTypes (const TENShPtr& left,
584  const TENShPtr& right,
585  OperType operType);
586 
587  // Set the children.
588  // If needed, their properties like data type and unit are adapted.
589  void setChildren (const TENShPtr& left, const TENShPtr& right,
590  Bool adapt=True);
591 
592  // Handle the units of the children and possibly set the parent's unit.
593  // The default implementation make the units of the children equal and
594  // set the parent unit to that unit if the parent is not a Bool value.
595  virtual void handleUnits();
596 
597  // If one of the children is a constant, convert its data type
598  // to that of the other operand. This avoids that conversions are
599  // done for each get.
600  void adaptDataTypes();
601 
602  // Get the child nodes.
603  // <group>
604  const TENShPtr& getLeftChild() const
605  { return lnode_p; }
606  const TENShPtr& getRightChild() const
607  { return rnode_p; }
608  // </group>
609 
610 protected:
611  // Make the units equal.
612  // Replace the right node if needed.
613  static const Unit& makeEqualUnits (const TENShPtr& left,
614  TENShPtr& right);
615 
616  TENShPtr lnode_p; //# left operand
617  TENShPtr rnode_p; //# right operand
618 };
619 
620 
621 
622 
623 // <summary>
624 // Abstract base class for a node having multiple child nodes.
625 // </summary>
626 
627 // <use visibility=local>
628 
629 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
630 // </reviewed>
631 
632 // <prerequisite>
633 //# Classes you should understand before using this one.
634 // <li> <linkto class=TableExprNodeRep>TableExprNodeRep</linkto>
635 // </prerequisite>
636 
637 // <etymology>
638 // TableExprNodeMulti is a node in the table expression tree
639 // which can have MULTIple child nodes.
640 // </etymology>
641 
642 // <synopsis>
643 // TableExprNodeMulti is the abstract base class for all nodes in a table
644 // expression tree using multiple operands.
645 // It is used as the base class for the node classes representing
646 // functions, sets, indices, etc..
647 // </synopsis>
648 
649 // <motivation>
650 // This class contains the common functionality for the classes
651 // representing a node with multiple operands.
652 // </motivation>
653 
654 //# <todo asof="$DATE:$">
655 //# A List of bugs, limitations, extensions or planned refinements.
656 //# <li> to be filled in
657 //# </todo>
658 
659 
661 {
662 public:
663  // Constructor
665  const TableExprNodeRep& source);
666 
667  // Destructor
668  virtual ~TableExprNodeMulti();
669 
670  // Show the expression tree.
671  virtual void show (ostream&, uInt indent) const;
672 
673  // Get the nodes representing an aggregate function.
674  virtual void getAggrNodes (std::vector<TableExprNodeRep*>& aggr);
675 
676  // Get the nodes representing a table column.
677  virtual void getColumnNodes (std::vector<TableExprNodeRep*>& cols);
678 
679  // Check number of arguments
680  // low <= number_of_args <= high
681  // It throws an exception if wrong number of arguments.
682  static uInt checkNumOfArg (uInt low, uInt high,
683  const std::vector<TENShPtr>& nodes);
684 
685  // Get the child nodes.
686  const std::vector<TENShPtr>& getChildren() const
687  { return operands_p; }
688 
689  // Check datatype of nodes and return output type.
690  // It also sets the expected data type of the operands (from dtIn).
691  // Conversion of Int,Double.String to Date is by default possible.
692  static NodeDataType checkDT (Block<Int>& dtypeOper,
693  NodeDataType dtIn, NodeDataType dtOut,
694  const std::vector<TENShPtr>& nodes,
695  Bool dateConv=True);
696 
697 protected:
698  std::vector<TENShPtr> operands_p;
699 };
700 
701 
702 
703 //# Get the data type of the node.
705  { return dtype_p; }
706 
708  { return dtype_p==NTInt || dtype_p==NTDouble; }
709 
710 //# Get the value type of the node.
712  { return vtype_p; }
713 
714 //# Set the value type of the node.
716  { vtype_p = vtype; }
717 
718 //# Get the operator type of the node.
720  { return optype_p; }
721 
722 //# Get the expression type of the node.
724  { return exprtype_p; }
725 
726 //# Is the expression a constant?
728  { return (exprtype_p == Constant); }
729 
730 //# Get the unit of the node.
731 inline const Unit& TableExprNodeRep::unit() const
732  { return unit_p; }
733 
735  { return attributes_p; }
736 
737 inline void TableExprNodeRep::setAttributes (const Record& attributes)
738  { attributes_p = attributes; }
739 
740 //# Get the fixed dimensionality of the node.
742  { return ndim_p; }
743 
744 //# Get the fixed shape of the node.
745 inline const IPosition& TableExprNodeRep::shape() const
746  { return shape_p; }
747 
748 //# Get the table from which the node is derived.
750  { return table_p; }
751 inline const Table& TableExprNodeRep::table() const
752  { return table_p; }
753 
754 inline void TableExprNodeRep::checkTablePtr (const TENShPtr& node)
755  { checkTablePtr (table_p, node); }
756 inline void TableExprNodeRep::fillExprType (const TENShPtr& node)
757  { fillExprType (exprtype_p, node); }
758 
759 
760 } //# NAMESPACE CASACORE - END
761 
762 #endif
void setAttributes(const Record &)
Set the attributes.
Definition: ExprNodeRep.h:737
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
virtual void getAggrNodes(std::vector< TableExprNodeRep * > &aggr)
Get the nodes representing an aggregate function.
CountedPtr< TableExprNodeRep > TENShPtr
Definition: ExprNodeRep.h:56
virtual Bool isDefined(const TableExprId &id)
Is the value in the given row defined? The default implementation returns True.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
MArray< Double > getDoubleAS(const TableExprId &id)
int Int
Definition: aipstype.h:50
virtual MArray< Bool > hasArrayString(const TableExprId &id, const MArray< String > &value)
virtual Array< uInt > getColumnuInt(const Vector< uInt > &rownrs)
Int ndim() const
Get the fixed dimensionality (same for all rows).
Definition: ExprNodeRep.h:741
TaqlRegex(const Regex &regex)
Construct from a regex.
Definition: ExprNodeRep.h:85
ExprType exprType() const
Get the expression type.
Definition: ExprNodeRep.h:723
virtual Array< Bool > getColumnBool(const Vector< uInt > &rownrs)
Get the value of the expression evaluated for the entire column.
static uInt checkNumOfArg(uInt low, uInt high, const std::vector< TENShPtr > &nodes)
Check number of arguments low &lt;= number_of_args &lt;= high It throws an exception if wrong number of arg...
Main interface class to a read/write table.
Definition: Table.h:153
void adaptDataTypes()
If one of the children is a constant, convert its data type to that of the other operand.
const Record & attributes() const
Get the attributes.
Definition: ExprNodeRep.h:734
const TENShPtr & getLeftChild() const
Get the child nodes.
Definition: ExprNodeRep.h:604
MArray< String > getStringAS(const TableExprId &id)
virtual MArray< Bool > getArrayBool(const TableExprId &id)
Get an array value for this node in the given row.
virtual Double getUnitFactor() const
Get the unit conversion factor.
virtual MArray< MVTime > getArrayDate(const TableExprId &id)
virtual MVTime getDate(const TableExprId &id)
void fillExprType(const TENShPtr &node)
Set expression type to Variable if node is Variable.
Definition: ExprNodeRep.h:756
virtual void show(ostream &, uInt indent) const
Show the expression tree.
A constant subexpression which can be evaluated immediately.
Definition: ExprNodeRep.h:203
virtual ~TableExprNodeMulti()
Destructor.
Bool isConstant() const
Is the expression a constant?
Definition: ExprNodeRep.h:727
virtual Int64 getInt(const TableExprId &id)
Scalar column in table select expression tree.
Definition: ExprDerNode.h:299
virtual Array< Double > getColumnDouble(const Vector< uInt > &rownrs)
void setChildren(const TENShPtr &left, const TENShPtr &right, Bool adapt=True)
Set the children.
virtual Array< uShort > getColumnuShort(const Vector< uInt > &rownrs)
OperType operType() const
Get the operator type.
Definition: ExprNodeRep.h:719
virtual Array< Float > getColumnFloat(const Vector< uInt > &rownrs)
static void createRange(Block< TableExprRange > &, TableExprNodeColumn *, Double start, Double end)
Create a range object from a column and an interval.
virtual MArray< Bool > hasArrayDComplex(const TableExprId &id, const MArray< DComplex > &value)
MArray< Int64 > getIntAS(const TableExprId &id)
TaqlRegex(const StringDistance &dist)
Construct from a StringDistance.
Definition: ExprNodeRep.h:90
virtual void getAggrNodes(std::vector< TableExprNodeRep * > &aggr)
Get the nodes representing an aggregate function.
NodeDataType
Define the data types of a node.
Definition: ExprNodeRep.h:161
virtual Array< DComplex > getColumnDComplex(const Vector< uInt > &rownrs)
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:157
MArray< MVTime > getDateAS(const TableExprId &id)
virtual void convertConstChild()
If one of the children is a constant, convert its data type to that of the other operand (if appropri...
virtual void getColumnNodes(std::vector< TableExprNodeRep * > &cols)
Get the nodes representing a table column.
virtual Bool hasDComplex(const TableExprId &id, const DComplex &value)
virtual Bool hasInt(const TableExprId &id, Int64 value)
virtual CountedPtr< TableExprGroupFuncBase > makeGroupAggrFunc()
Create the correct immediate aggregate function object.
const_iterator end() const
void setValueType(ValueType vtype)
Set the value type.
Definition: ExprNodeRep.h:715
virtual void applySelection(const Vector< uInt > &rownrs)
Re-create the column object for a selection of rows.
virtual Array< Int > getColumnInt(const Vector< uInt > &rownrs)
virtual ~TableExprNodeBinary()
Destructor.
defines physical units
Definition: Unit.h:189
virtual MArray< Double > getArrayDouble(const TableExprId &id)
virtual void getColumnNodes(std::vector< TableExprNodeRep * > &cols)
Get the nodes representing a table column.
StringDistance itsDist
Definition: ExprNodeRep.h:106
virtual Double getDouble(const TableExprId &id)
ExprType
Define (sub-)expression type.
Definition: ExprNodeRep.h:201
const TENShPtr & getRightChild() const
Definition: ExprNodeRep.h:606
ArgType
Define the value types of the 2 arguments when arrays are involved.
Definition: ExprNodeRep.h:196
virtual MArray< DComplex > getArrayDComplex(const TableExprId &id)
virtual MArray< Bool > hasArrayDate(const TableExprId &id, const MArray< MVTime > &value)
virtual void adaptSetUnits(const Unit &)
Let a set node convert itself to the given unit.
virtual void getAggrNodes(std::vector< TableExprNodeRep * > &aggr)
Get the nodes representing an aggregate function.
Abstract base class for a node having multiple child nodes.
Definition: ExprNodeRep.h:660
NodeDataType dataType() const
Get the data type of the derived TableExprNode object.
Definition: ExprNodeRep.h:704
double Double
Definition: aipstype.h:55
OperType
Define the operator types.
Definition: ExprNodeRep.h:187
Regular expression class.
Definition: Regex.h:198
static NodeDataType getDT(NodeDataType leftDtype, NodeDataType rightDype, OperType operType)
Check the data types and get the common one.
virtual MArray< Bool > hasArrayInt(const TableExprId &id, const MArray< Int64 > &value)
virtual const IPosition & getShape(const TableExprId &id)
Get the shape for the given row.
virtual void show(ostream &, uInt indent) const
Show the expression tree.
virtual Bool hasDate(const TableExprId &id, const MVTime &value)
virtual Array< String > getColumnString(const Vector< uInt > &rownrs)
virtual Bool hasBool(const TableExprId &id, Bool value)
Does a value occur in an array or set? The default implementation tests if it is in an array...
static TENShPtr replaceConstNode(const TENShPtr &node)
Replace a node with a constant expression by node with its value.
ValueType valueType() const
Get the value type.
Definition: ExprNodeRep.h:711
const std::vector< TENShPtr > & getChildren() const
Get the child nodes.
Definition: ExprNodeRep.h:686
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual MArray< Bool > hasArrayDouble(const TableExprId &id, const MArray< Double > &value)
ValueType
Define the value types.
Definition: ExprNodeRep.h:176
TableExprNodeMulti(NodeDataType, ValueType, OperType, const TableExprNodeRep &source)
Constructor.
virtual void handleUnits()
Handle the units of the children and possibly set the parent&#39;s unit.
virtual void ranges(Block< TableExprRange > &)
Convert the tree to a number of range vectors which at least select the same things.
virtual MArray< Int64 > getArrayInt(const TableExprId &id)
virtual Bool getBool(const TableExprId &id)
Get a scalar value for this node in the given row.
void checkTablePtr(const TENShPtr &node)
Check if this node uses the same table pointer.
Definition: ExprNodeRep.h:754
Bool match(const String &str) const
Does the regex or maximum string distance match?
Definition: ExprNodeRep.h:95
std::vector< TENShPtr > operands_p
Definition: ExprNodeRep.h:698
virtual void disableApplySelection()
Do not apply the selection.
virtual void getColumnNodes(std::vector< TableExprNodeRep * > &cols)
Get the nodes representing a table column.
const Unit & unit() const
Get the unit.
Definition: ExprNodeRep.h:731
virtual Array< Complex > getColumnComplex(const Vector< uInt > &rownrs)
simple 1-D array
const Regex & regex() const
Return the regular expression.
Definition: ExprNodeRep.h:101
MArray< Bool > getBoolAS(const TableExprId &id)
Get a value as an array, even it it is a scalar.
virtual Bool hasDouble(const TableExprId &id, Double value)
const String & regexp() const
Get the regular expression string.
Definition: Regex.h:259
void checkAggrFuncs()
Throw an exception if an aggregate function is used in the expression node or its children...
static String typeString(NodeDataType)
Convert a NodeDataType to a string.
virtual ~TableExprNodeRep()
The destructor deletes all the underlying TableExprNode objects.
TableExprNodeBinary(NodeDataType, ValueType, OperType, const Table &)
Constructor.
The identification of a TaQL selection subject.
Definition: TableExprId.h:97
Bool match(const String &target) const
Test if the given target string is within the maximum distance.
virtual String getString(const TableExprId &id)
Table & table()
Get table.
Definition: ExprNodeRep.h:749
virtual MArray< Bool > hasArrayBool(const TableExprId &id, const MArray< Bool > &value)
Class to handle a Regex or StringDistance.
Definition: ExprNodeRep.h:81
static NodeDataType checkDT(Block< Int > &dtypeOper, NodeDataType dtIn, NodeDataType dtOut, const std::vector< TENShPtr > &nodes, Bool dateConv=True)
Check datatype of nodes and return output type.
virtual TaqlRegex getRegex(const TableExprId &id)
virtual MArray< String > getArrayString(const TableExprId &id)
Bool matches(const string &str, Int pos=0) const
Matches entire string from pos (or till pos if negative pos).
TableExprNodeRep(NodeDataType, ValueType, OperType, ArgType, ExprType, Int ndim, const IPosition &shape, const Table &table)
Construct a node.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual Bool isLazyAggregate() const
Is the aggregate function a lazy or an immediate one? The default implementation returns True (becaus...
static TENShPtr convertNode(const TENShPtr &thisNode, Bool convertConstType)
If the node is constant, it is evaluated and replaced by the appropriate TableExprNodeConst object...
Class to deal with Levensthein distance of strings.
MArray< DComplex > getDComplexAS(const TableExprId &id)
virtual void show(ostream &, uInt indent) const
Show the expression tree.
uInt nrow() const
Get the number of rows in the table associated with this expression.
virtual DComplex getDComplex(const TableExprId &id)
virtual Array< uChar > getColumnuChar(const Vector< uInt > &rownrs)
Class to handle date/time type conversions and I/O.
Definition: MVTime.h:269
static const Unit & makeEqualUnits(const TENShPtr &left, TENShPtr &right)
Make the units equal.
void setUnit(const Unit &unit)
Set the unit.
virtual Bool getColumnDataType(DataType &) const
Get the data type of the column.
Bool isReal() const
Is the data type real (i.e., integer or double)?
Definition: ExprNodeRep.h:707
const IPosition & shape() const
Get the fixed shape (same for all rows).
Definition: ExprNodeRep.h:745
virtual Bool hasString(const TableExprId &id, const String &value)
Abstract base class for a node having 0, 1, or 2 child nodes.
Definition: ExprNodeRep.h:558
const Bool True
Definition: aipstype.h:43
virtual Array< Short > getColumnShort(const Vector< uInt > &rownrs)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
TableExprNodeRep & operator=(const TableExprNodeRep &)
A copy of a TableExprNodeRep cannot be made.
static TableExprNodeRep getCommonTypes(const TENShPtr &left, const TENShPtr &right, OperType operType)
Check the data and value types and get the common one.
virtual Array< Int64 > getColumnInt64(const Vector< uInt > &rownrs)
Bool empty() const
Test for empty.
Definition: String.h:375
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42