casacore
TableParse.h
Go to the documentation of this file.
1 //# TableParse.h: Classes to hold results from table grammar parser
2 //# Copyright (C) 1994,1995,1997,1998,1999,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$
27 
28 #ifndef TABLES_TABLEPARSE_H
29 #define TABLES_TABLEPARSE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/Tables/Table.h>
34 #include <casacore/tables/Tables/TableDesc.h>
35 #include <casacore/tables/TaQL/ExprNode.h>
36 #include <casacore/tables/TaQL/TaQLResult.h>
37 #include <casacore/tables/TaQL/ExprGroup.h>
38 #include <casacore/casa/BasicSL/String.h>
39 #include <casacore/casa/Utilities/Sort.h>
40 #include <casacore/casa/Containers/Block.h>
41 #include <map>
42 #include <vector>
43 #include <limits>
44 
45 namespace casacore { //# NAMESPACE CASACORE - BEGIN
46 
47 //# Forward Declarations
48 class TableExprNodeSet;
49 class TableExprNodeSetElem;
50 class TableExprNodeIndex;
51 class TableColumn;
52 class AipsIO;
53 template<class T> class Vector;
54 
55 
56 // <summary>
57 // Class to hold values from table grammar parser
58 // </summary>
59 
60 // <use visibility=local>
61 
62 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTableGram">
63 // </reviewed>
64 
65 // <prerequisite>
66 //# Classes you should understand before using this one.
67 // </prerequisite>
68 
69 // <etymology>
70 // TableParse is the class used to parse a table command.
71 // </etymology>
72 
73 // <synopsis>
74 // TableParse is used by the parser of table select statements.
75 // The parser is written in Bison and Flex in files TableGram.y and .l.
76 // The statements in there use the routines in this file to act
77 // upon a reduced rule.
78 // Since multiple tables can be given (with a shorthand), the table
79 // names are stored in a container. The variable names can be qualified
80 // by the table name and will be looked up in the appropriate table.
81 //
82 // A select command is similar to SQL and can look like:
83 // SELECT columns FROM tab1 sh1, tab2 sh2, tab3 WHERE
84 // sh1.field == 3*sh1.field2 ... ORDERBY columns GIVING table
85 // This is described in more detail in TableGram.l.
86 //
87 // The class TableParse only contains information about a table
88 // used in the table command.
89 //
90 // Global functions are used to operate on the information.
91 // The main function is the global function tableCommand.
92 // It executes the given TaQL command and returns the resulting table.
93 // This is, in fact, the only function to be used by a user.
94 // </synopsis>
95 
96 // <motivation>
97 // It is necessary to be able to give a table select command in ASCII.
98 // This can be used in a CLI or in the table browser to get a subset
99 // of a table or to sort a table.
100 // </motivation>
101 
102 //# <todo asof="$DATE:$">
103 //# A List of bugs, limitations, extensions or planned refinements.
104 //# </todo>
105 
106 
108 {
109 
110 public:
111  // Default constructor for container class.
112  TableParse();
113 
114  // Copy constructor (copy semantics).
115  TableParse (const TableParse&);
116 
117  // Assignment (copy semantics).
119 
120  // Associate the table and the shorthand.
121  TableParse (const Table& table, const String& shorthand);
122 
123  // Test if shorthand matches.
124  Bool test (const String& shortHand) const;
125 
126  // Get the shorthand.
127  const String& shorthand() const;
128 
129  // Get table object.
130  const Table& table() const;
131 
132 private:
135 };
136 
137 
138 
139 // <synopsis>
140 // Parse and execute the given command.
141 // It will open (and close) all tables needed.
142 // It returns the resulting table.
143 // The command type (select or update) and the selected or updated
144 // column names can be returned.
145 // Zero or more temporary tables can be used in the command
146 // using the $nnn syntax.
147 // </synopsis>
148 // <group name=tableCommand>
149 TaQLResult tableCommand (const String& command);
150 
151 TaQLResult tableCommand (const String& command,
152  const Table& tempTable);
153 TaQLResult tableCommand (const String& command,
154  const std::vector<const Table*>& tempTables);
155 TaQLResult tableCommand (const String& command,
156  Vector<String>& columnNames);
157 TaQLResult tableCommand (const String& command,
158  Vector<String>& columnNames,
159  String& commandType);
160 TaQLResult tableCommand (const String& command,
161  const std::vector<const Table*>& tempTables,
162  Vector<String>& columnNames);
163 TaQLResult tableCommand (const String& command,
164  const std::vector<const Table*>& tempTables,
165  Vector<String>& columnNames,
166  String& commandType);
167 // </group>
168 
169 
170 
171 
172 // <summary>
173 // Helper class for sort keys in TableParse
174 // </summary>
175 
176 // <use visibility=local>
177 
178 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
179 // </reviewed>
180 
181 // <prerequisite>
182 //# Classes you should understand before using this one.
183 // <li> TableParse
184 // </prerequisite>
185 
186 // <etymology>
187 // TableParseSort holds a sort expression and order.
188 // </etymology>
189 
190 // <synopsis>
191 // A table command is parsed.
192 // An object of this class is used to hold the sort expression
193 // and sort order.
194 // </synopsis>
195 
196 
198 {
199 public:
200  // Construct from a given expression.
201  // The order is not given.
202  TableParseSort();
203 
204  // Construct from a given expression.
205  // The order is not given.
206  explicit TableParseSort (const TableExprNode&);
207 
208  // Construct from a given expression and for the given order.
210 
211  ~TableParseSort();
212 
213  // Get the expression node.
214  const TableExprNode& node() const;
215 
216  // Get the sort order.
217  Sort::Order order() const;
218 
219  // Is the order given?
220  Bool orderGiven() const;
221 
222 private:
223  // Check if the node results in a scalar and does not contain
224  // aggregate functions.
225  void checkNode() const;
226 
230 };
231 
232 
233 
234 
235 // <summary>
236 // Helper class for updates in TableParse
237 // </summary>
238 
239 // <use visibility=local>
240 
241 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
242 // </reviewed>
243 
244 // <prerequisite>
245 //# Classes you should understand before using this one.
246 // <li> TableParse
247 // </prerequisite>
248 
249 // <etymology>
250 // TableParseUpdate holds a column name, optional indices, and an
251 // update expression.
252 // </etymology>
253 
254 // <synopsis>
255 // A table command is parsed.
256 // An object of this class is used to hold the column name, optional indices,
257 // and value expression for the UPDATE command.
258 // </synopsis>
259 
260 
262 {
263 public:
265  : indexPtr_p(0) {}
266 
267  // Construct from a column name and expression.
268  // By default it checks if no aggregate functions are used.
269  TableParseUpdate (const String& columnName, const TableExprNode&,
270  Bool checkAggr=True);
271 
272  // Construct from a column name, subscripts, and expression.
273  // It checks if no aggregate functions are used.
274  TableParseUpdate (const String& columnName,
275  const TableExprNodeSet& indices,
276  const TableExprNode&,
277  const TaQLStyle&);
278 
279  ~TableParseUpdate();
280 
281  // Set the column name.
282  void setColumnName (const String& name);
283 
284  // Get the column name.
285  const String& columnName() const;
286 
287  // Get the pointer to the indices.
288  TableExprNodeIndex* indexPtr() const;
289 
290  // Get the index expression node.
291  const TableExprNode& indexNode() const;
292 
293  // Get the expression node.
294  // <group>
295  const TableExprNode& node() const;
296  TableExprNode& node();
297  // </group>
298 
299  // Adapt the possible unit of the expression to the possible unit
300  // of the column.
301  void adaptUnit (const Unit& columnUnit);
302 
303 private:
305  TableExprNodeIndex* indexPtr_p; //# copy of pointer in indexNode_p
308 };
309 
310 
311 
312 
313 // <summary>
314 // Select-class for flex/bison scanner/parser for TableParse
315 // </summary>
316 
317 // <use visibility=local>
318 
319 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
320 // </reviewed>
321 
322 // <prerequisite>
323 //# Classes you should understand before using this one.
324 // <li> TableParse
325 // <li> TableGram.l and .y (flex and bison grammar)
326 // </prerequisite>
327 
328 // <synopsis>
329 // This class is needed for the the actions in the flex scanner
330 // and bison parser.
331 // This stores the information by constructing TableParse objects
332 // as needed and storing them in a vector.
333 // </synopsis>
334 
335 // <motivation>
336 // It is necessary to be able to give a table select command in ASCII.
337 // This can be used in a CLI or in the table browser to get a subset
338 // of a table or to sort a table.
339 // </motivation>
340 
341 //# <todo asof="$DATE:$">
342 //# A List of bugs, limitations, extensions or planned refinements.
343 //# </todo>
344 
345 
347 {
348 public:
349  enum CommandType {
356  PCRETAB
357  };
358 
360  GROUPBY=1,
361  AGGR_FUNCS=2,
362  ONLY_COUNTALL=4
363  };
364 
365  // Construct.
367 
368  // Destructor.
369  ~TableParseSelect();
370 
371  // Return the command type.
373  { return commandType_p; }
374 
375  // Return the expression node.
377  { return node_p; }
378 
379  // Execute the select command (select/sort/projection/groupby/having/giving).
380  // The setInGiving flag tells if a set in the GIVING part is allowed.
381  // The mustSelect flag tells if a SELECT command must do something.
382  // Usually that is required, but not for a SELECT in an INSERT command.
383  // Optionally the maximum nr of rows to be selected can be given.
384  // It will be used as the default value for the LIMIT clause.
385  // 0 = no maximum.
386  void execute (Bool showTimings, Bool setInGiving,
387  Bool mustSelect, uInt maxRow, Bool doTracing=False);
388 
389  // Execute a query in a from clause resulting in a Table.
390  Table doFromQuery (Bool showTimings);
391 
392  // Execute a subquery and create an appropriate node for the result.
393  TableExprNode doSubQuery (Bool showTimings);
394 
395  // Test if a subquery has sufficient elements.
396  // It uses default LIMIT=1, but that can be overidden in the subquery.
397  // The flag tells if NOT EXISTS or EXISTS was given.
398  TableExprNode doExists (Bool noexists, Bool showTimings);
399 
400  // Show the expression tree.
401  void show (ostream& os) const;
402 
403  // Keep the selection expression.
404  void handleWhere (const TableExprNode&);
405 
406  // Keep the groupby expressions.
407  // It checks if they are all scalar expressions.
408  void handleGroupby (const vector<TableExprNode>&, Bool rollup);
409 
410  // Keep the having expression.
411  void handleHaving (const TableExprNode&);
412 
413  // Keep the expression of a calculate command.
414  void handleCalcComm (const TableExprNode&);
415 
416  // Keep the create table command.
417  void handleCreTab (const String& tableName, const Record& dmInfo);
418 
419  // Keep the column specification in a create table command.
420  void handleColSpec (const String& columnName, const String& dataType,
421  const Record& spec, Bool isCOrder=False);
422 
423  // Add an update object.
424  void addUpdate (TableParseUpdate* upd);
425 
426  // Keep the update expressions.
427  void handleUpdate();
428 
429  // Make ready for the insert expression.
430  // The first one uses values (added via addUpdate),
431  // the second one a subquery.
432  // <group>
433  void handleInsert();
434  void handleInsert (TableParseSelect* sel);
435  // </group>
436 
437  // Make ready for a COUNT command.
438  // It checks if all column expressions are scalar.
439  void handleCount();
440 
441  // Keep the sort expressions.
442  void handleSort (const std::vector<TableParseSort>& sortList,
443  Bool noDuplicates, Sort::Order defaultSortOrder);
444 
445  // Evaluate and keep limit/offset/stride given as start:end:incr
446  void handleLimit (const TableExprNodeSetElem& expr);
447 
448  // Evaluate and keep the limit value.
449  void handleLimit (const TableExprNode& expr);
450 
451  // Evaluate and keep the offset value.
452  void handleOffset (const TableExprNode& expr);
453 
454  // Add a table nr, name, or object to the container.
455  void addTable (Int tabnr, const String& name,
456  const Table& table,
457  const String& shorthand,
458  const vector<const Table*> tempTables,
459  const vector<TableParseSelect*>& stack);
460 
461  // Replace the first table (used by CALC command).
462  void replaceTable (const Table& table);
463 
464  // Find the keyword or column name and create a TableExprNode from it.
465  // If <src>tryProj=True</src> it is first tried if the column is a coluymn
466  // in the projected table (i.e., result from the SELECT part).
467  TableExprNode handleKeyCol (const String& name, Bool tryProj);
468 
469  // Handle a slice operator.
470  static TableExprNode handleSlice (const TableExprNode& array,
471  const TableExprNodeSet& indices,
472  const TaQLStyle&);
473 
474  // Handle a function.
475  TableExprNode handleFunc (const String& name,
476  const TableExprNodeSet& arguments,
477  const TaQLStyle&);
478 
479  // Make a function object node for the given function name and arguments.
480  // The ignoreFuncs vector contains invalid function codes.
481  static TableExprNode makeFuncNode (TableParseSelect*,
482  const String& name,
483  const TableExprNodeSet& arguments,
484  const Vector<int>& ignoreFuncs,
485  const Table& table,
486  const TaQLStyle&);
487 
488  // Add a column to the list of column names.
489  void handleColumn (Int type, const String& name, const TableExprNode& expr,
490  const String& newName, const String& newDtype);
491 
492  // Finish the addition of columns to the list of column names.
493  void handleColumnFinish (Bool distinct);
494 
495  // Handle the name and type given in a GIVING clause.
496  void handleGiving (const String& name, Int type);
497 
498  // Handle the set given in a GIVING clause.
499  void handleGiving (const TableExprNodeSet&);
500 
501  // Get the projected column names.
502  const Block<String>& getColumnNames() const;
503 
504  // Get the resulting table.
505  const Table& getTable() const;
506 
507  // An exception is thrown if the node uses an aggregate function.
508  static void checkAggrFuncs (const TableExprNode& node);
509 
510 private:
511  // Test if groupby or aggregate functions are given.
512  // <br> bit 0: on = groupby is given
513  // <br> bit 1: on = aggregate functions are given
514  // <br> bit 2: on = only select count(*) aggregate function is given
515  Int testGroupAggr (vector<TableExprNodeRep*>& aggr) const;
516 
517  // Get the aggregate functions used in SELECT and HAVING.
518  vector<TableExprNodeRep*> getAggrNodes() const;
519 
520  // Try to make a UDF function node for the given function name and arguments.
521  static TableExprNode makeUDFNode (TableParseSelect*,
522  const String& name,
523  const TableExprNodeSet& arguments,
524  const Table& table,
525  const TaQLStyle&);
526 
527  // Find the function code belonging to a function name.
528  // Functions to be ignored can be given (as function type values).
529  // If the function name is unknown, NRFUNC is returned.
530  static TableExprFuncNode::FunctionType findFunc
531  (const String& name,
532  uInt narguments,
533  const Vector<Int>& ignoreFuncs);
534 
535  // Do the update step.
536  // Rows 0,1,2,.. in UpdTable are updated from the expression result
537  // for the rows in the given rownrs vector.
538  void doUpdate (Bool showTimings, const Table& origTable,
539  Table& updTable, const Vector<uInt>& rownrs,
540  const CountedPtr<TableExprGroupResult>& groups =
542 
543  // Do the insert step and return a selection containing the new rows.
544  Table doInsert (Bool showTimings, Table& table);
545 
546  // Do the delete step.
547  void doDelete (Bool showTimings, Table& table);
548 
549  // Do the count step returning a memory table containing the unique
550  // column values and the counts of the column values.
551  Table doCount (Bool showTimings, const Table&);
552 
553  // Do the projection step returning a table containing the projection.
554  Table doProject (Bool showTimings, const Table&,
555  const CountedPtr<TableExprGroupResult>& groups =
557 
558  // Do the projection containing column expressions.
559  // Use the selected or unselected columns depending on <src>useSel</src>.
560  Table doProjectExpr (Bool useSel,
561  const CountedPtr<TableExprGroupResult>& groups);
562 
563  // Make the (empty) table for the epxression in the SELECT clause.
564  void makeProjectExprTable();
565 
566  // Fill projectExprSelColumn_p telling the columns to be projected
567  // at the first stage.
568  void makeProjectExprSel();
569 
570  // Add a column node to applySelNodes_p.
571  void addApplySelNode (const TableExprNode& node)
572  { applySelNodes_p.push_back (node); }
573 
574  // Set the selected rows for the column objects in applySelNodes_p.
575  // These nodes refer the original table. They requires different row
576  // numbers than the selected groups and projected columns.
577  // rownrs_p is changed to use row 0..n.
578  // It returns the Table containing the subset of rows in the input Table.
579  Table adjustApplySelNodes (const Table&);
580 
581  // Do the groupby/aggregate step and return its result.
583  (bool showTimings, vector<TableExprNodeRep*> aggrNodes,
584  Int groupAggrUsed);
585 
586  // Do the HAVING step.
587  void doHaving (Bool showTimings,
588  const CountedPtr<TableExprGroupResult>& groups);
589 
590  // Do a groupby/aggregate step that only does a 'select count(*)'.
591  CountedPtr<TableExprGroupResult> doOnlyCountAll (TableExprNodeRep* aggrNode);
592 
593  // Do a full groupby/aggregate step.
595  (const vector<TableExprNodeRep*>& aggrNodes);
596 
597  // Do the sort step.
598  void doSort (Bool showTimings);
599 
600  // Do the limit/offset step.
601  void doLimOff (Bool showTimings);
602  Table doLimOff (Bool showTimings, const Table& table);
603 
604  // Do the 'select distinct' step.
605  Table doDistinct (Bool showTimings, const Table& table);
606 
607  // Finish the table (rename, copy, and/or flush).
608  Table doFinish (Bool showTimings, Table& table);
609 
610  // Update the values in the columns (helpers of doUpdate).
611  // <group>
612  template<typename TCOL, typename TNODE>
613  void updateValue2 (uInt row, const TableExprId& rowid, Bool isScalarCol,
614  const TableExprNode& node, TableColumn& col,
615  const Slicer* slicerPtr,
616  IPosition& blc, IPosition& trc, IPosition& inc);
617  template<typename T>
618  void updateValue1 (uInt row, const TableExprId& rowid, Bool isScalarCol,
619  const TableExprNode& node, TableColumn& col,
620  const Slicer* slicerPtr,
621  IPosition& blc, IPosition& trc, IPosition& inc);
622  // </group>
623 
624  // Make a data type from the string.
625  // It checks if it is compatible with the given (expression) data type.
626  DataType makeDataType (DataType dtype, const String& dtstr,
627  const String& colName);
628 
629  // Get the order for this key. Use the default order_p if not
630  // explicitly given with the key.
631  Sort::Order getOrder (const TableParseSort& key) const;
632 
633  // Make an array from the contents of a column in a subquery.
634  TableExprNode getColSet();
635 
636  // Make a set from the results of the subquery.
637  TableExprNode makeSubSet() const;
638 
639  // Evaluate an int scalar expression.
640  Int64 evalIntScaExpr (const TableExprNode& expr) const;
641 
642  // Split a name into its parts (shorthand, column and field names).
643  // True is returned when the name contained a keyword part.
644  // In that case fieldNames contains the keyword name and the possible
645  // subfields. The possible shorthand and the column name are
646  // filled in if it is a column keyword.
647  // If the name represents a column, fieldNames contains the subfields
648  // of the column (for the case where the column contains records).
649  // If the name is invalid, an exception is thrown if checkError=True.
650  // Otherwise the name is treated as a normal name without keyword.
651  Bool splitName (String& shorthand, String& columnName,
652  Vector<String>& fieldNames, const String& name,
653  Bool checkError) const;
654 
655  // Find a table for the given shorthand.
656  // If no shorthand is given, the first table is returned (if there).
657  // If not found, a null Table object is returned.
658  Table findTable (const String& shorthand) const;
659 
660  // Handle the selection of a wildcarded column name.
661  void handleWildColumn (Int stringType, const String& name);
662 
663  // Add the description of a column to the table description.
664  // ndim < 0 means a scalar column.
665  void addColumnDesc (TableDesc& td, DataType dtype,
666  const String& colName, Int options,
667  Int ndim, const IPosition& shape,
668  const String& dmType, const String& dmGroup,
669  const String& comment,
670  const TableRecord& keywordSet,
671  const String& unitName);
672 
673  // Find the names of all stored columns in a table.
674  Block<String> getStoredColumns (const Table& tab) const;
675 
676  // Try to find the keyword representing a table in one of the tables
677  // in any select block (from inner to outer).
678  // If not found, an exception is thrown.
679  static Table tableKey (const String& fullName,
680  const String& shorthand, const String& columnName,
681  const Vector<String>& fieldNames,
682  const vector<TableParseSelect*>& stack);
683 
684  // Try to find the keyword representing a table in the given table.
685  // If the columnName is empty, the keyword is a table keyword.
686  // If not found, a null Table object is returned.
687  static Table findTableKey (const Table& table, const String& columnName,
688  const Vector<String>& keyNames);
689 
690  // Create the set of aggregate functions and groupby keys in case
691  // a single groupby key is given.
692  // This offers much faster map access then doGroupByAggrMultiple.
693  template<typename T>
694  vector<CountedPtr<TableExprGroupFuncSet> > doGroupByAggrSingleKey
695  (const vector<TableExprNodeRep*>& aggrNodes)
696  {
697  // We have to group the data according to the (possibly empty) groupby.
698  // We step through the table in the normal order which may not be the
699  // groupby order.
700  // A map<key,int> is used to keep track of the results where the int
701  // is the index in a vector of a set of aggregate function objects.
702  vector<CountedPtr<TableExprGroupFuncSet> > funcSets;
703  std::map<T, int> keyFuncMap;
704  T lastKey = std::numeric_limits<T>::max();
705  int groupnr = -1;
706  // Loop through all rows.
707  // For each row generate the key to get the right entry.
708  TableExprId rowid(0);
709  T key;
710  for (uInt i=0; i<rownrs_p.size(); ++i) {
711  rowid.setRownr (rownrs_p[i]);
712  groupbyNodes_p[0].get (rowid, key);
713  if (key != lastKey) {
714  typename std::map<T, int>::iterator iter = keyFuncMap.find (key);
715  if (iter == keyFuncMap.end()) {
716  groupnr = funcSets.size();
717  keyFuncMap[key] = groupnr;
718  funcSets.push_back (new TableExprGroupFuncSet (aggrNodes));
719  } else {
720  groupnr = iter->second;
721  }
722  }
723  rowid.setRownr (rownrs_p[i]);
724  funcSets[groupnr]->apply (rowid);
725  }
726  return funcSets;
727  }
728 
729  // Create the set of aggregate functions and groupby keys in case
730  // multiple keys are given.
731  vector<CountedPtr<TableExprGroupFuncSet> > doGroupByAggrMultipleKeys
732  (const vector<TableExprNodeRep*>& aggrNodes);
733 
734  //# Command type.
736  //# Table description for a series of column descriptions.
738  //# Vector of TableParse objects.
739  //# This is needed for the functions above, otherwise they have no
740  //# way to communicate.
741  vector<TableParse> fromTables_p;
742  //# Block of selected column names (new name in case of select).
744  //# Block of selected column expressions.
746  //# The old name for a selected column.
748  //# The new data type for a column.
750  //# The keywords used in a column.
752  //# Number of real expressions used in selected columns.
754  //# Distinct values in output?
756  //# Name and type of the resulting table (from GIVING part).
759  //# Resulting set (from GIVING part).
761  //# The WHERE expression tree.
763  //# The GROUPBY expressions.
764  vector<TableExprNode> groupbyNodes_p;
765  Bool groupbyRollup_p; //# use ROLLUP in GROUPBY?
766  //# The HAVING expression.
768  //# The possible limit (= max nr of selected rows) (0 means no limit).
770  //# The possible last row (0 means no end; can be <0).
771  //# limit_p and endrow_p cannot be both !=0.
773  //# The possible offset (= nr of selected rows to skip).
775  //# The possible stride in offset:endrow:stride.
777  //# The update or insert expression list.
778  std::vector<TableParseUpdate*> update_p;
779  //# The table selection to be inserted.
781  //# The sort list.
782  std::vector<TableParseSort> sort_p;
783  //# The noDuplicates sort switch.
785  //# The default sort order.
787  //# All nodes that need to be adjusted for a selection of rownrs.
788  //# It can consist of column nodes and the rowid function node.
789  //# Some nodes (in aggregate functions) can later be disabled for adjustment.
790  vector<TableExprNode> applySelNodes_p;
791  //# The resulting table.
793  //# The first table used when creating a column object.
794  //# All other tables used for them should have the same size.
797  //# The table resulting from a projection with expressions.
799  //# The projected columns used in the HAVING and ORDERBY clauses.
802  //# The resulting row numbers.
804 };
805 
806 
807 
808 //# Implement the inline functions.
809 inline Bool TableParse::test (const String& str) const
810  { return (shorthand_p == str ? True : False); }
811 
812 inline const String& TableParse::shorthand() const
813  { return shorthand_p; }
814 
815 inline const Table& TableParse::table() const
816  { return table_p; }
817 
818 
819 inline void TableParseUpdate::setColumnName (const String& name)
820  { columnName_p = name; }
822  { return columnName_p; }
824  { return indexPtr_p; }
826  { return indexNode_p; }
828  { return node_p; }
830  { return node_p; }
831 inline void TableParseUpdate::adaptUnit (const Unit& columnUnit)
832  { node_p.adaptUnit (columnUnit); }
833 
834 inline const TableExprNode& TableParseSort::node() const
835  { return node_p; }
837  { return given_p; }
839  { return order_p; }
840 
841 
843  { return columnNames_p; }
844 
845 inline const Table& TableParseSelect::getTable() const
846  { return table_p; }
847 
849  { update_p.push_back (upd); }
850 
852  { return (key.orderGiven() ? key.order() : order_p); }
853 
854 
855 } //# NAMESPACE CASACORE - END
856 
857 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
Block< Bool > projectExprSelColumn_p
Definition: TableParse.h:801
A 1-D Specialization of the Array class.
Definition: ArrayIO.h:45
vector< TableExprNode > groupbyNodes_p
Definition: TableParse.h:764
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
void setColumnName(const String &name)
Set the column name.
Definition: TableParse.h:819
int Int
Definition: aipstype.h:47
TableExprNodeSet * resultSet_p
Definition: TableParse.h:760
Bool orderGiven() const
Is the order given?
Definition: TableParse.h:836
Main interface class to a read/write table.
Definition: Table.h:149
TableExprNodeIndex * indexPtr_p
Definition: TableParse.h:305
TableExprNode indexNode_p
Definition: TableParse.h:306
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1986
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:305
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
Handle class for a table column expression tree.
Definition: ExprNode.h:578
TableExprNode node_p
Definition: TableParse.h:227
Order
Enumerate the sort order:
Definition: Sort.h:260
void setRownr(uInt rownr)
Set the row number.
Definition: TableExprId.h:186
TableExprNodeIndex * indexPtr() const
Get the pointer to the indices.
Definition: TableParse.h:823
Sort::Order getOrder(const TableParseSort &key) const
Get the order for this key.
Definition: TableParse.h:851
void adaptUnit(const Unit &columnUnit)
Adapt the possible unit of the expression to the possible unit of the column.
Definition: TableParse.h:831
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:150
TableParse & operator=(const TableParse &)
Assignment (copy semantics).
const Table & table() const
Get table object.
Definition: TableParse.h:815
defines physical units
Definition: Unit.h:189
vector< TableExprNode > applySelNodes_p
Definition: TableParse.h:790
vector< TableParse > fromTables_p
Definition: TableParse.h:741
Select-class for flex/bison scanner/parser for TableParse.
Definition: TableParse.h:346
Sort::Order order() const
Get the sort order.
Definition: TableParse.h:838
Referenced counted pointer for constant data.
Definition: CountedPtr.h:86
const TableExprNode & node() const
Get the expression node.
Definition: TableParse.h:827
Class to hold the table expression nodes for an element in a set.
Definition: ExprNodeSet.h:93
Class to hold the result of a TaQL command.
Definition: TaQLResult.h:67
Vector< uInt > rownrs_p
Definition: TableParse.h:803
Class with static members defining the TaQL style.
Definition: TaQLStyle.h:64
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
CommandType commandType() const
Return the command type.
Definition: TableParse.h:372
Block< uInt > projectExprSubset_p
Definition: TableParse.h:800
Block< String > columnDtypes_p
Definition: TableParse.h:749
const Block< String > & getColumnNames() const
Get the projected column names.
Definition: TableParse.h:842
Block< TableRecord > columnKeywords_p
Definition: TableParse.h:751
A hierarchical collection of named fields of various types.
Definition: Record.h:181
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
Bool test(const String &shortHand) const
Test if shorthand matches.
Definition: TableParse.h:809
Read/write access to a table column.
Definition: TableColumn.h:98
Class containing the results of aggregated values in a group.
Definition: ExprGroup.h:769
Block< String > columnNames_p
Definition: TableParse.h:743
const Bool False
Definition: aipstype.h:41
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:2015
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
Block< TableExprNode > columnExpr_p
Definition: TableParse.h:745
TableExprNode getNode() const
Return the expression node.
Definition: TableParse.h:376
TableParse()
Default constructor for container class.
Helper class for sort keys in TableParse.
Definition: TableParse.h:197
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:275
simple 1-D array
Definition: ArrayIO.h:47
const TableExprNode & node() const
Get the expression node.
Definition: TableParse.h:834
Class to hold values from table grammar parser.
Definition: TableParse.h:107
TableExprNode havingNode_p
Definition: TableParse.h:767
TableParseSelect * insSel_p
Definition: TableParse.h:780
The identification of a TaQL selection subject.
Definition: TableExprId.h:98
void addUpdate(TableParseUpdate *upd)
Add an update object.
Definition: TableParse.h:848
Block< String > columnOldNames_p
Definition: TableParse.h:747
const TableExprNode & indexNode() const
Get the index expression node.
Definition: TableParse.h:825
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Define the structure of a Casacore table.
Definition: TableDesc.h:186
const Table & getTable() const
Get the resulting table.
Definition: TableParse.h:845
TaQLResult tableCommand(const String &command)
const String & shorthand() const
Get the shorthand.
Definition: TableParse.h:812
The index of an array element in a table select expression.
void addApplySelNode(const TableExprNode &node)
Add a column node to applySelNodes_p.
Definition: TableParse.h:571
const Bool True
Definition: aipstype.h:40
const String & columnName() const
Get the column name.
Definition: TableParse.h:821
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48
Helper class for updates in TableParse.
Definition: TableParse.h:261
std::vector< TableParseUpdate * > update_p
Definition: TableParse.h:778
std::vector< TableParseSort > sort_p
Definition: TableParse.h:782