00001 //# ExprDerNode.h: Nodes representing scalars in table select expression tree 00002 //# Copyright (C) 1994,1995,1996,1997,1999,2000,2001 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: ExprDerNode.h 21521 2014-12-10 08:06:42Z gervandiepen $ 00027 00028 #ifndef TABLES_EXPRDERNODE_H 00029 #define TABLES_EXPRDERNODE_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/tables/TaQL/ExprNodeRep.h> 00034 #include <casacore/tables/Tables/TableColumn.h> 00035 #include <casacore/casa/Arrays/Vector.h> 00036 #include <casacore/casa/BasicMath/Random.h> 00037 00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00039 00040 //# Forward Declarations 00041 class TableColumn; 00042 class Table; 00043 00044 //# This file defines classes derived from TableExprNode representing 00045 //# the data type and operator in a table expression. 00046 //# 00047 //# Data types Bool, Int64, Double, DComplex and String are used. 00048 //# Char, uChar, Short, uShort, Int, and uInt are converted to Int64, 00049 //# Float to Double, and Complex to DComplex. 00050 //# Binary operators +, -, *, /, ==, >=, >, <, <= and != are recognized. 00051 //# Also &&, ||, parentheses and unary +, - and ! are recognized. 00052 00053 00054 00055 // <summary> 00056 // Constant Bool in table select expression tree 00057 // </summary> 00058 00059 // <use visibility=local> 00060 00061 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00062 // </reviewed> 00063 00064 // <prerequisite> 00065 //# Classes you should understand before using this one. 00066 // <li> TableExprNode 00067 // </prerequisite> 00068 00069 // <synopsis> 00070 // This class represents a constant in a table select expression tree. 00071 // This is also used to hold the value of a table keyword, which is 00072 // constant over the entire table. 00073 // </synopsis> 00074 00075 class TableExprNodeConstBool : public TableExprNodeBinary 00076 { 00077 public: 00078 TableExprNodeConstBool (const Bool& value); 00079 ~TableExprNodeConstBool(); 00080 Bool getBool (const TableExprId& id); 00081 private: 00082 Bool value_p; 00083 }; 00084 00085 00086 // <summary> 00087 // Constant Int64 in table select expression tree 00088 // </summary> 00089 00090 // <use visibility=local> 00091 00092 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00093 // </reviewed> 00094 00095 // <prerequisite> 00096 //# Classes you should understand before using this one. 00097 // <li> TableExprNode 00098 // </prerequisite> 00099 00100 // <synopsis> 00101 // This class represents a constant in a table select expression tree. 00102 // This is also used to hold the value of a table keyword, which is 00103 // constant over the entire table. 00104 // </synopsis> 00105 00106 class TableExprNodeConstInt : public TableExprNodeBinary 00107 { 00108 public: 00109 TableExprNodeConstInt (const Int64& value); 00110 ~TableExprNodeConstInt(); 00111 Int64 getInt (const TableExprId& id); 00112 Double getDouble (const TableExprId& id); 00113 DComplex getDComplex (const TableExprId& id); 00114 private: 00115 Int64 value_p; 00116 }; 00117 00118 00119 // <summary> 00120 // Constant Double in table select expression tree 00121 // </summary> 00122 00123 // <use visibility=local> 00124 00125 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00126 // </reviewed> 00127 00128 // <prerequisite> 00129 //# Classes you should understand before using this one. 00130 // <li> TableExprNode 00131 // </prerequisite> 00132 00133 // <synopsis> 00134 // This class represents a constant in a table select expression tree. 00135 // This is also used to hold the value of a table keyword, which is 00136 // constant over the entire table. 00137 // </synopsis> 00138 00139 class TableExprNodeConstDouble : public TableExprNodeBinary 00140 { 00141 public: 00142 TableExprNodeConstDouble (const Double& value); 00143 ~TableExprNodeConstDouble(); 00144 Double getDouble (const TableExprId& id); 00145 DComplex getDComplex (const TableExprId& id); 00146 private: 00147 Double value_p; 00148 }; 00149 00150 00151 // <summary> 00152 // Constant DComplex in table select expression tree 00153 // </summary> 00154 00155 // <use visibility=local> 00156 00157 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00158 // </reviewed> 00159 00160 // <prerequisite> 00161 //# Classes you should understand before using this one. 00162 // <li> TableExprNode 00163 // </prerequisite> 00164 00165 // <synopsis> 00166 // This class represents a constant in a table select expression tree. 00167 // This is also used to hold the value of a table keyword, which is 00168 // constant over the entire table. 00169 // </synopsis> 00170 00171 class TableExprNodeConstDComplex : public TableExprNodeBinary 00172 { 00173 public: 00174 TableExprNodeConstDComplex (const DComplex& value); 00175 ~TableExprNodeConstDComplex(); 00176 DComplex getDComplex (const TableExprId& id); 00177 private: 00178 DComplex value_p; 00179 }; 00180 00181 00182 // <summary> 00183 // Constant String in table select expression tree 00184 // </summary> 00185 00186 // <use visibility=local> 00187 00188 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00189 // </reviewed> 00190 00191 // <prerequisite> 00192 //# Classes you should understand before using this one. 00193 // <li> TableExprNode 00194 // </prerequisite> 00195 00196 // <synopsis> 00197 // This class represents a constant in a table select expression tree. 00198 // This is also used to hold the value of a table keyword, which is 00199 // constant over the entire table. 00200 // </synopsis> 00201 00202 class TableExprNodeConstString : public TableExprNodeBinary 00203 { 00204 public: 00205 TableExprNodeConstString (const String& value); 00206 ~TableExprNodeConstString(); 00207 String getString (const TableExprId& id); 00208 private: 00209 String value_p; 00210 }; 00211 00212 00213 // <summary> 00214 // Constant Regex or StringDistance in table select expression tree 00215 // </summary> 00216 00217 // <use visibility=local> 00218 00219 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00220 // </reviewed> 00221 00222 // <prerequisite> 00223 //# Classes you should understand before using this one. 00224 // <li> TableExprNode 00225 // </prerequisite> 00226 00227 // <synopsis> 00228 // This class represents a constant in a table select expression tree. 00229 // This is also used to hold the value of a table keyword, which is 00230 // constant over the entire table. 00231 // </synopsis> 00232 00233 class TableExprNodeConstRegex : public TableExprNodeBinary 00234 { 00235 public: 00236 TableExprNodeConstRegex (const TaqlRegex& value); 00237 ~TableExprNodeConstRegex(); 00238 TaqlRegex getRegex (const TableExprId& id); 00239 private: 00240 TaqlRegex value_p; 00241 StringDistance dist_p; 00242 }; 00243 00244 00245 // <summary> 00246 // Constant Date in table select expression tree 00247 // </summary> 00248 00249 // <use visibility=local> 00250 00251 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00252 // </reviewed> 00253 00254 // <prerequisite> 00255 //# Classes you should understand before using this one. 00256 // <li> TableExprNode 00257 // </prerequisite> 00258 00259 // <synopsis> 00260 // This class represents a constant in a table select expression tree. 00261 // This is also used to hold the value of a table keyword, which is 00262 // constant over the entire table. 00263 // </synopsis> 00264 00265 class TableExprNodeConstDate : public TableExprNodeBinary 00266 { 00267 public: 00268 TableExprNodeConstDate (const MVTime& value); 00269 ~TableExprNodeConstDate(); 00270 Double getDouble(const TableExprId& id); 00271 MVTime getDate (const TableExprId& id); 00272 private: 00273 MVTime value_p; 00274 }; 00275 00276 00277 00278 // <summary> 00279 // Scalar column in table select expression tree 00280 // </summary> 00281 00282 // <use visibility=local> 00283 00284 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00285 // </reviewed> 00286 // 00287 // <prerequisite> 00288 //# Classes you should understand before using this one. 00289 // <li> TableExprNode 00290 // </prerequisite> 00291 00292 // <synopsis> 00293 // This class represents a scalar column in a table select expression tree. 00294 // When the select expression gets evaluated, the value of the 00295 // given row in the column is used. 00296 // </synopsis> 00297 00298 00299 class TableExprNodeColumn : public TableExprNodeBinary 00300 { 00301 public: 00302 TableExprNodeColumn (const Table&, const String& columnName); 00303 ~TableExprNodeColumn(); 00304 00305 // This node represents a table column. 00306 virtual void getColumnNodes (vector<TableExprNodeRep*>& cols); 00307 00308 // Do not apply the selection. 00309 virtual void disableApplySelection(); 00310 00311 // Re-create the column object for a selection of rows. 00312 virtual void applySelection (const Vector<uInt>& rownrs); 00313 00314 // Get the data type of this scalar column. 00315 Bool getColumnDataType (DataType&) const; 00316 00317 // Get the data for the given id. 00318 Bool getBool (const TableExprId& id); 00319 Int64 getInt (const TableExprId& id); 00320 Double getDouble (const TableExprId& id); 00321 DComplex getDComplex (const TableExprId& id); 00322 String getString (const TableExprId& id); 00323 const TableColumn& getColumn() const; 00324 00325 // Get the data for the given rows. 00326 Array<Bool> getColumnBool (const Vector<uInt>& rownrs); 00327 Array<uChar> getColumnuChar (const Vector<uInt>& rownrs); 00328 Array<Short> getColumnShort (const Vector<uInt>& rownrs); 00329 Array<uShort> getColumnuShort (const Vector<uInt>& rownrs); 00330 Array<Int> getColumnInt (const Vector<uInt>& rownrs); 00331 Array<uInt> getColumnuInt (const Vector<uInt>& rownrs); 00332 Array<Float> getColumnFloat (const Vector<uInt>& rownrs); 00333 Array<Double> getColumnDouble (const Vector<uInt>& rownrs); 00334 Array<Complex> getColumnComplex (const Vector<uInt>& rownrs); 00335 Array<DComplex> getColumnDComplex (const Vector<uInt>& rownrs); 00336 Array<String> getColumnString (const Vector<uInt>& rownrs); 00337 00338 // Get the column unit (can be empty). 00339 static Unit getColumnUnit (const TableColumn&); 00340 00341 protected: 00342 Table selTable_p; 00343 TableColumn tabCol_p; 00344 Bool applySelection_p; 00345 }; 00346 00347 00348 00349 // <summary> 00350 // Rownumber in table select expression tree 00351 // </summary> 00352 00353 // <use visibility=local> 00354 00355 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00356 // </reviewed> 00357 00358 // <prerequisite> 00359 //# Classes you should understand before using this one. 00360 // <li> TableExprNode 00361 // </prerequisite> 00362 00363 // <synopsis> 00364 // This class represents the rownumber() function in a table 00365 // select expression tree. 00366 // The origin is stored to indicate whether the first rownumber 00367 // should be zero (in C++) or an other value (1 in TaQL) 00368 // </synopsis> 00369 00370 class TableExprNodeRownr : public TableExprNodeBinary 00371 { 00372 public: 00373 TableExprNodeRownr (const Table&, uInt origin); 00374 ~TableExprNodeRownr(); 00375 Int64 getInt (const TableExprId& id); 00376 private: 00377 uInt origin_p; 00378 }; 00379 00380 00381 00382 // <summary> 00383 // Rowid in table select expression tree 00384 // </summary> 00385 00386 // <use visibility=local> 00387 00388 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00389 // </reviewed> 00390 00391 // <prerequisite> 00392 //# Classes you should understand before using this one. 00393 // <li> TableExprNode 00394 // </prerequisite> 00395 00396 // <synopsis> 00397 // This class represents the rowid() function in a table 00398 // select expression tree. 00399 // It is meant to get the original row number in a GIVING clause, 00400 // but, of course, it can also be used in the SELECT clause. 00401 // The row number returned is 0-based. 00402 // </synopsis> 00403 00404 class TableExprNodeRowid : public TableExprNodeBinary 00405 { 00406 public: 00407 TableExprNodeRowid (const Table&); 00408 ~TableExprNodeRowid(); 00409 virtual void applySelection (const Vector<uInt>& rownrs); 00410 Int64 getInt (const TableExprId& id); 00411 private: 00412 Vector<uInt> rownrs_p; 00413 }; 00414 00415 00416 00417 // <summary> 00418 // Random number in table select expression tree 00419 // </summary> 00420 00421 // <use visibility=local> 00422 00423 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00424 // </reviewed> 00425 00426 // <prerequisite> 00427 //# Classes you should understand before using this one. 00428 // <li> TableExprNode 00429 // </prerequisite> 00430 00431 // <synopsis> 00432 // This class represents the rand() function in a table 00433 // select expression tree. 00434 // </synopsis> 00435 00436 class TableExprNodeRandom : public TableExprNodeBinary 00437 { 00438 public: 00439 TableExprNodeRandom (const Table&); 00440 ~TableExprNodeRandom(); 00441 Double getDouble (const TableExprId& id); 00442 private: 00443 MLCG generator_p; 00444 Uniform random_p; 00445 }; 00446 00447 00448 00449 } //# NAMESPACE CASACORE - END 00450 00451 #endif