casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
43 #include <map>
44 #include <vector>
45 #include <limits>
46 
47 namespace casacore { //# NAMESPACE CASACORE - BEGIN
48 
49 //# Forward Declarations
50 class TableExprNodeSet;
51 class TableExprNodeSetElem;
52 class TableExprNodeIndex;
53 class TableColumn;
54 class AipsIO;
55 template<class T> class ArrayColumn;
56 
57 
58 // <summary>
59 // Class to hold values from table grammar parser
60 // </summary>
61 
62 // <use visibility=local>
63 
64 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTableGram">
65 // </reviewed>
66 
67 // <prerequisite>
68 //# Classes you should understand before using this one.
69 // </prerequisite>
70 
71 // <etymology>
72 // TableParse is the class used to parse a table command.
73 // </etymology>
74 
75 // <synopsis>
76 // TableParse is used by the parser of table select statements.
77 // The parser is written in Bison and Flex in files TableGram.y and .l.
78 // The statements in there use the routines in this file to act
79 // upon a reduced rule.
80 // Since multiple tables can be given (with a shorthand), the table
81 // names are stored in a container. The variable names can be qualified
82 // by the table name and will be looked up in the appropriate table.
83 //
84 // A select command is similar to SQL and can look like:
85 // SELECT columns FROM tab1 sh1, tab2 sh2, tab3 WHERE
86 // sh1.field == 3*sh1.field2 ... ORDERBY columns GIVING table
87 // This is described in more detail in TableGram.l.
88 //
89 // The class TableParse only contains information about a table
90 // used in the table command.
91 //
92 // Global functions are used to operate on the information.
93 // The main function is the global function tableCommand.
94 // It executes the given TaQL command and returns the resulting table.
95 // This is, in fact, the only function to be used by a user.
96 // </synopsis>
97 
98 // <motivation>
99 // It is necessary to be able to give a table select command in ASCII.
100 // This can be used in a CLI or in the table browser to get a subset
101 // of a table or to sort a table.
102 // </motivation>
103 
104 //# <todo asof="$DATE:$">
105 //# A List of bugs, limitations, extensions or planned refinements.
106 //# </todo>
107 
108 
110 {
111 
112 public:
113  // Default constructor for container class.
114  TableParse();
115 
116  // Associate the table and the shorthand.
117  TableParse (const Table& table, Int tabnr, const String& name,
118  const String& shorthand);
119 
120  // Test if shorthand matches. If also matches if the given shorthand is empty.
121  Bool test (const String& shortHand) const;
122 
123  // Get the given table number (of $i tables in TempTables)
124  Int tabnr() const;
125 
126  // Get the given table name.
127  const String& name() const;
128 
129  // Get the shorthand.
130  const String& shorthand() const;
131 
132  // Get table object.
133  const Table& table() const;
134  Table& table();
135 
136  // Replace the Table object.
137  void replaceTable (const Table&);
138 
139 private:
144 };
145 
146 
147 
148 // <synopsis>
149 // Parse and execute the given command.
150 // It will open (and close) all tables needed.
151 // It returns the resulting table.
152 // The command type (select or update) and the selected or updated
153 // column names can be returned.
154 // Zero or more temporary tables can be used in the command
155 // using the $nnn syntax.
156 // </synopsis>
157 // <group name=tableCommand>
158 TaQLResult tableCommand (const String& command);
159 
160 TaQLResult tableCommand (const String& command,
161  const Table& tempTable);
162 TaQLResult tableCommand (const String& command,
163  const std::vector<const Table*>& tempTables);
164 TaQLResult tableCommand (const String& command,
165  Vector<String>& columnNames);
166 TaQLResult tableCommand (const String& command,
167  Vector<String>& columnNames,
168  String& commandType);
169 TaQLResult tableCommand (const String& command,
170  const std::vector<const Table*>& tempTables,
171  Vector<String>& columnNames);
172 TaQLResult tableCommand (const String& command,
173  const std::vector<const Table*>& tempTables,
174  Vector<String>& columnNames,
175  String& commandType);
176 // </group>
177 
178 
179 
180 
181 // <summary>
182 // Helper class for sort keys in TableParse
183 // </summary>
184 
185 // <use visibility=local>
186 
187 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
188 // </reviewed>
189 
190 // <prerequisite>
191 //# Classes you should understand before using this one.
192 // <li> TableParse
193 // </prerequisite>
194 
195 // <etymology>
196 // TableParseSort holds a sort expression and order.
197 // </etymology>
198 
199 // <synopsis>
200 // A table command is parsed.
201 // An object of this class is used to hold the sort expression
202 // and sort order.
203 // </synopsis>
204 
205 
207 {
208 public:
209  // Construct from a given expression.
210  // The order is not given.
211  TableParseSort();
212 
213  // Construct from a given expression.
214  // The order is not given.
215  explicit TableParseSort (const TableExprNode&);
216 
217  // Construct from a given expression and for the given order.
219 
220  ~TableParseSort();
221 
222  // Get the expression node.
223  const TableExprNode& node() const;
224 
225  // Get the sort order.
226  Sort::Order order() const;
227 
228  // Is the order given?
229  Bool orderGiven() const;
230 
231 private:
232  // Check if the node results in a scalar and does not contain
233  // aggregate functions.
234  void checkNode() const;
235 
239 };
240 
241 
242 
243 
244 // <summary>
245 // Helper class for updates in TableParse
246 // </summary>
247 
248 // <use visibility=local>
249 
250 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
251 // </reviewed>
252 
253 // <prerequisite>
254 //# Classes you should understand before using this one.
255 // <li> TableParse
256 // </prerequisite>
257 
258 // <etymology>
259 // TableParseUpdate holds a column name, optional indices, optional mask,
260 // and an update expression.
261 // </etymology>
262 
263 // <synopsis>
264 // A table command is parsed.
265 // An object of this class is used to hold the column name, optional indices,
266 // and value expression for the UPDATE command.
267 // </synopsis>
268 
269 
271 {
272 public:
274  : indexPtr_p(0) {}
275 
276  // Construct from a column name and expression.
277  // By default it checks if no aggregate functions are used.
279  const String& columnNameMask,
280  const TableExprNode&,
281  Bool checkAggr=True);
282 
283  // Construct from a column name, subscripts or mask, and expression.
284  // It checks if no aggregate functions are used.
286  const String& columnNameMask,
287  const TableExprNodeSet& indices,
288  const TableExprNode&,
289  const TaQLStyle&);
290 
291  // Construct from a column name, subscripts and mask, and expression.
292  // It checks if no aggregate functions are used.
293  // It checks if one of the indices represents subscripts, the other a mask.
295  const String& columnNameMask,
296  const TableExprNodeSet& indices1,
297  const TableExprNodeSet& indices2,
298  const TableExprNode&,
299  const TaQLStyle&);
300  // Handle the subscripts or mask.
301  // It checks if subscripts or mask was not already used.
302  void handleIndices (const TableExprNodeSet& indices,
303  const TaQLStyle& style);
305 
306  // Set the column name.
307  void setColumnName (const String& name);
308 
309  // Set the column name forthe mask.
310  void setColumnNameMask (const String& name);
311 
312  // Get the column name.
313  const String& columnName() const;
314 
315  // Get the possible column name for the mask.
316  const String& columnNameMask() const;
317 
318  // Tell if the mask is given first (i.e., before slice).
319  Bool maskFirst() const
320  { return maskFirst_p; }
321 
322  // Get the pointer to the indices.
323  TableExprNodeIndex* indexPtr() const;
324 
325  // Get the index expression node.
326  const TableExprNode& indexNode() const;
327 
328  // Get the expression node.
329  // <group>
330  const TableExprNode& node() const;
331  TableExprNode& node();
332  // </group>
333 
334  // Get the mask.
335  const TableExprNode& mask() const
336  { return mask_p; }
337 
338  // Adapt the possible unit of the expression to the possible unit
339  // of the column.
340  void adaptUnit (const Unit& columnUnit);
341 
342 private:
345  Bool maskFirst_p; //# True = mask is given before slice
346  TableExprNodeIndex* indexPtr_p; //# copy of pointer in indexNode_p
350 };
351 
352 
353 
354 
355 // <summary>
356 // Select-class for flex/bison scanner/parser for TableParse
357 // </summary>
358 
359 // <use visibility=local>
360 
361 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
362 // </reviewed>
363 
364 // <prerequisite>
365 //# Classes you should understand before using this one.
366 // <li> TableParse
367 // <li> TableGram.l and .y (flex and bison grammar)
368 // </prerequisite>
369 
370 // <synopsis>
371 // This class is needed for the the actions in the flex scanner
372 // and bison parser.
373 // This stores the information by constructing TableParse objects
374 // as needed and storing them in a vector.
375 // </synopsis>
376 
377 // <motivation>
378 // It is necessary to be able to give a table select command in ASCII.
379 // This can be used in a CLI or in the table browser to get a subset
380 // of a table or to sort a table.
381 // </motivation>
382 
383 //# <todo asof="$DATE:$">
384 //# A List of bugs, limitations, extensions or planned refinements.
385 //# </todo>
386 
387 
389 {
390 public:
391  enum CommandType {
402  };
403 
408  };
409 
410  // Construct.
412 
413  // Destructor.
415 
416  // Return the command type.
418  { return commandType_p; }
419 
420  // Return the expression node.
422  { return node_p; }
423 
424  // Create a temporary table if no tables are given in FROM.
425  void makeTableNoFrom (const std::vector<TableParseSelect*>& stack);
426 
427  // Execute the select command (select/sort/projection/groupby/having/giving).
428  // The setInGiving flag tells if a set in the GIVING part is allowed.
429  // The mustSelect flag tells if a SELECT command must do something.
430  // Usually that is required, but not for a SELECT in an INSERT command.
431  // Optionally the maximum nr of rows to be selected can be given.
432  // It will be used as the default value for the LIMIT clause.
433  // 0 = no maximum.
434  void execute (Bool showTimings, Bool setInGiving,
435  Bool mustSelect, rownr_t maxRow, Bool doTracing=False,
436  const std::vector<const Table*>& tempTables = std::vector<const Table*>(),
437  const std::vector<TableParseSelect*>& stack = std::vector<TableParseSelect*>());
438 
439  // Execute a query in a from clause resulting in a Table.
440  Table doFromQuery (Bool showTimings);
441 
442  // Execute a subquery and create an appropriate node for the result.
443  TableExprNode doSubQuery (Bool showTimings);
444 
445  // Test if a subquery has sufficient elements.
446  // It uses default LIMIT=1, but that can be overidden in the subquery.
447  // The flag tells if NOT EXISTS or EXISTS was given.
448  TableExprNode doExists (Bool noexists, Bool showTimings);
449 
450  // Show the expression tree.
451  void show (ostream& os) const;
452 
453  // Keep the selection expression.
454  void handleWhere (const TableExprNode&);
455 
456  // Keep the groupby expressions.
457  // It checks if they are all scalar expressions.
458  void handleGroupby (const std::vector<TableExprNode>&, Bool rollup);
459 
460  // Keep the having expression.
461  void handleHaving (const TableExprNode&);
462 
463  // Keep the expression of a calculate command.
464  void handleCalcComm (const TableExprNode&);
465 
466  // Handle the DROP TABLE command.
467  void handleDropTab (const std::vector<const Table*>& tempTables,
468  const std::vector<TableParseSelect*>& stack);
469 
470  // Keep the create table command.
471  void handleCreTab (const Record& dmInfo,
472  const std::vector<const Table*>& tempTables,
473  const std::vector<TableParseSelect*>& stack);
474 
475  // Keep the column specification in a create table command.
476  void handleColSpec (const String& columnName, const String& likeColName,
477  const String& dataType,
478  const Record& spec, Bool isCOrder=False);
479 
480  // Reopen the table (for update) used in the ALTER TABLE command.
481  void handleAltTab();
482 
483  // Add columns to the table of ALTER TABLE.
484  // The column descriptions have already been added to tableDesc_p.
485  void handleAddCol (const Record& dmInfo);
486 
487  // Initialize the table and data manager descriptions.
488  void initDescriptions (const TableDesc&, const Record& dminfo);
489 
490  // Add a keyword or replace a keyword with the value of another keyword.
491  // The keywords can be table or column keywords (col::key).
492  ValueHolder getRecFld (const String& name);
493 
494  // Define a field with the given data type in the Record.
495  static void setRecFld (RecordInterface& rec,
496  const String& name,
497  const String& dtype,
498  const ValueHolder& vh);
499 
500  // Get the type string. If empty, it is made from the given
501  // data type.
502  static String getTypeString (const String& typeStr, DataType type);
503 
504  // Handle copying of columns.
505  void handleCopyCol (Bool showTimings);
506 
507  // Add a keyword or replace a keyword with a value.
508  // The keyword can be a table or column keyword (col::key).
509  // The data type string can be empty leaving the data type unchanged.
510  void handleSetKey (const String& name, const String& dtype,
511  const ValueHolder& value);
512 
513  // Rename a table or column keyword.
514  void handleRenameKey (const String& oldName, const String& newName);
515 
516  // Remove a table or column keyword.
517  void handleRemoveKey (const String& name);
518 
519  // Split the given name into optional shorthand, column and fields.
520  // Find the keywordset for it and fill in the final keyword name.
521  // It is a helper function for handleSetKey, etc.
522  // If update=True, rwKeywordSet() is used to ensure the table is updated.
523  TableRecord& findKeyword (const String& name, String& keyName,
524  Bool update=True);
525 
526  // Add an update object.
527  void addUpdate (const CountedPtr<TableParseUpdate>& upd);
528 
529  // Set the insert expressions for all rows.
530  void setInsertExprs (const std::vector<TableExprNode> exprs)
531  { insertExprs_p = exprs; }
532 
533  // Keep the update expressions.
534  void handleUpdate();
535 
536  // Make ready for the insert expression.
537  // The first one uses values (added via addUpdate),
538  // the second one a subquery.
539  // <group>
540  void handleInsert();
541  void handleInsert (TableParseSelect* sel);
542  // </group>
543 
544  // Make ready for a COUNT command.
545  // It checks if all column expressions are scalar.
546  void handleCount();
547 
548  // Keep the sort expressions.
549  void handleSort (const std::vector<TableParseSort>& sortList,
550  Bool noDuplicates, Sort::Order defaultSortOrder);
551 
552  // Evaluate and keep limit/offset/stride given as start:end:incr
553  void handleLimit (const TableExprNodeSetElem& expr);
554 
555  // Evaluate and keep the limit value.
556  void handleLimit (const TableExprNode& expr);
557 
558  // Evaluate and keep the offset value.
559  void handleOffset (const TableExprNode& expr);
560 
561  // Evaluate and add the rows.
562  void handleAddRow (const TableExprNode& expr);
563 
564  // Add a table nr, name, or object to the container.
565  Table addTable (Int tabnr, const String& name,
566  const Table& table,
567  const String& shorthand,
568  Bool addToFromList,
569  const std::vector<const Table*>& tempTables,
570  const std::vector<TableParseSelect*>& stack);
571 
572  // Make a Table object for given name, seqnr or so.
573  // If <src>alwaysOpen=False</src> the table will only be looked up,
574  // but not opened if not found. This is meant for concatenated tables
575  // in TaQLNodeHandler.
576  Table getTable (Int tabnr, const String& name,
577  const Table& ftab,
578  const std::vector<const Table*>& tempTables,
579  const std::vector<TableParseSelect*>& stack,
580  Bool alwaysOpen=True);
581 
582  // Replace the first table (used by CALC command).
583  void replaceTable (const Table& table);
584 
585  // Find the keyword or column name and create a TableExprNode from it.
586  // If <src>tryProj=True</src> it is first tried if the column is a coluymn
587  // in the projected table (i.e., result from the SELECT part).
588  TableExprNode handleKeyCol (const String& name, Bool tryProj);
589 
590  // Handle a slice operator.
592  const TableExprNodeSet& indices,
593  const TaQLStyle&);
594 
595  // Handle a function.
596  TableExprNode handleFunc (const String& name,
597  const TableExprNodeSet& arguments,
598  const TaQLStyle&);
599 
600  // Make a function object node for the given function name and arguments.
601  // The ignoreFuncs vector contains invalid function codes.
603  const String& name,
604  const TableExprNodeSet& arguments,
605  const Vector<int>& ignoreFuncs,
606  const Table& table,
607  const TaQLStyle&);
608 
609  // Add a column to the list of column names.
610  void handleColumn (Int type, const String& name, const TableExprNode& expr,
611  const String& newName, const String& nameMask,
612  const String& newDtype);
613 
614  // Finish the addition of columns to the list of column names.
615  void handleColumnFinish (Bool distinct);
616 
617  // Set the DataManager info for a new table.
618  void setDMInfo (const Record& dminfo)
619  { dminfo_p = dminfo;}
620 
621  // Handle the name and type given in a GIVING clause.
622  void handleGiving (const String& name, const Record& type);
623 
624  // Handle the set given in a GIVING clause.
625  void handleGiving (const TableExprNodeSet&);
626 
627  // Get the projected column names.
628  const Block<String>& getColumnNames() const;
629 
630  // Get the resulting table.
631  const Table& getTable() const;
632 
633  // An exception is thrown if the node uses an aggregate function.
634  static void checkAggrFuncs (const TableExprNode& node);
635 
636  // Show the structure of fromTables_p[0] using the options given in parts[2:].
637  String getTableInfo (const Vector<String>& parts, const TaQLStyle& style);
638 
639  // Split a name into its parts (shorthand, column and field names).
640  // If isKeyword is True, the first part of name is a keyword, even if no :: is given.
641  // True is returned if the name contains a keyword part.
642  // In that case fieldNames contains the keyword name and the possible
643  // subfields. The possible shorthand and the column name are
644  // filled in if it is a column keyword.
645  // If the name represents a column, fieldNames contains the subfields
646  // of the column (for the case where the column contains records).
647  // If allowNoKey is True, a single :: is allowed, otherwise the name is invalid.
648  // If the name is invalid, exceptions are only thrown if checkError=True.
649  // Otherwise the name is treated as a normal name without keyword.
650  static Bool splitName (String& shorthand, String& columnName,
651  Vector<String>& fieldNames, const String& name,
652  Bool checkError, Bool isKeyword, Bool allowNoKey);
653 
654 private:
655  // Test if groupby or aggregate functions are given.
656  // <br> bit 0: on = groupby is given
657  // <br> bit 1: on = aggregate functions are given
658  // <br> bit 2: on = only select count(*) aggregate function is given
659  Int testGroupAggr (std::vector<TableExprNodeRep*>& aggr) const;
660 
661  // Get the aggregate functions used in SELECT and HAVING.
662  std::vector<TableExprNodeRep*> getAggrNodes() const;
663 
664  // Try to make a UDF function node for the given function name and arguments.
666  const String& name,
667  const TableExprNodeSet& arguments,
668  const Table& table,
669  const TaQLStyle&);
670 
671  // Find the function code belonging to a function name.
672  // Functions to be ignored can be given (as function type values).
673  // If the function name is unknown, NRFUNC is returned.
674  static TableExprFuncNode::FunctionType findFunc (const String& name,
675  uInt narguments,
676  const Vector<Int>& ignoreFuncs);
677 
678  // Do the update step.
679  // Rows 0,1,2,.. in UpdTable are updated from the expression result
680  // for the rows in the given rownrs vector.
681  void doUpdate (Bool showTimings, const Table& origTable,
682  Table& updTable, const Vector<rownr_t>& rownrs,
683  const CountedPtr<TableExprGroupResult>& groups =
685 
686  // Do the insert step and return a selection containing the new rows.
687  Table doInsert (Bool showTimings, Table& table);
688 
689  // Do the delete step.
690  void doDelete (Bool showTimings, Table& table);
691 
692  // Do the count step returning a memory table containing the unique
693  // column values and the counts of the column values.
694  Table doCount (Bool showTimings, const Table&);
695 
696  // Do the projection step returning a table containing the projection.
697  Table doProject (Bool showTimings, const Table&,
698  const CountedPtr<TableExprGroupResult>& groups =
700 
701  // Do the projection containing column expressions.
702  // Use the selected or unselected columns depending on <src>useSel</src>.
703  Table doProjectExpr (Bool useSel,
704  const CountedPtr<TableExprGroupResult>& groups);
705 
706  // Create a table using the given parameters.
707  // The variables set by handleGiven are used for name and type.
708  Table createTable (const TableDesc& td,
709  Int64 nrow, const Record& dmInfo,
710  const std::vector<const Table*>& tempTables,
711  const std::vector<TableParseSelect*>& stack);
712  Table createSubTable (const String& subtableName,
713  const TableDesc& td, Int64 nrow,
714  const Record& dmInfo,
715  const std::vector<const Table*>& tempTables,
716  const std::vector<TableParseSelect*>& stack);
717 
718  // Open the parent table of a subtable.
719  Table openParentTable (const String& fullName,
720  const String& subTableName,
721  const std::vector<const Table*>& tempTables,
722  const std::vector<TableParseSelect*>& stack);
723 
724  // Make the (empty) table for the epxression in the SELECT clause.
725  void makeProjectExprTable();
726 
727  // Fill projectExprSelColumn_p telling the columns to be projected
728  // at the first stage.
729  void makeProjectExprSel();
730 
731  // Add a column node to applySelNodes_p.
732  void addApplySelNode (const TableExprNode& node)
733  { applySelNodes_p.push_back (node); }
734 
735  // Set the selected rows for the column objects in applySelNodes_p.
736  // These nodes refer the original table. They requires different row
737  // numbers than the selected groups and projected columns.
738  // rownrs_p is changed to use row 0..n.
739  // It returns the Table containing the subset of rows in the input Table.
741 
742  // Do the groupby/aggregate step and return its result.
744  (bool showTimings, const std::vector<TableExprNodeRep*> aggrNodes,
745  Int groupAggrUsed);
746 
747  // Do the HAVING step.
748  void doHaving (Bool showTimings,
749  const CountedPtr<TableExprGroupResult>& groups);
750 
751  // Do a groupby/aggregate step that only does a 'select count(*)'.
753 
754  // Do a full groupby/aggregate step.
756  (const std::vector<TableExprNodeRep*>& aggrNodes);
757 
758  // Do the sort step.
759  void doSort (Bool showTimings);
760 
761  // Do the limit/offset step.
762  void doLimOff (Bool showTimings);
763  Table doLimOff (Bool showTimings, const Table& table);
764 
765  // Do the 'select distinct' step.
766  Table doDistinct (Bool showTimings, const Table& table);
767 
768  // Finish the table (rename, copy, and/or flush).
769  Table doFinish (Bool showTimings, Table& table,
770  const std::vector<const Table*>& tempTables,
771  const std::vector<TableParseSelect*>& stack);
772 
773  // Update the values in the columns (helpers of doUpdate).
774  // <group>
775  template<typename TCOL, typename TNODE>
776  void updateValue (rownr_t row, const TableExprId& rowid,
777  Bool isScalarCol, const TableExprNode& node,
778  const Array<Bool>& mask, Bool maskFirst,
779  TableColumn& col, const Slicer* slicerPtr,
780  ArrayColumn<Bool>& maskCol);
781  template<typename TCOL, typename TNODE>
782  void updateScalar (rownr_t row, const TableExprId& rowid,
783  const TableExprNode& node,
784  TableColumn& col);
785  template<typename TCOL, typename TNODE>
786  void updateArray (rownr_t row, const TableExprId& rowid,
787  const TableExprNode& node,
788  const Array<TNODE>& res,
789  ArrayColumn<TCOL>& col);
790  template<typename TCOL, typename TNODE>
791  void updateSlice (rownr_t row, const TableExprId& rowid,
792  const TableExprNode& node,
793  const Array<TNODE>& res,
794  const Slicer& slice,
795  ArrayColumn<TCOL>& col);
796  template<typename TCOL, typename TNODE>
797  void copyMaskedValue (rownr_t row, ArrayColumn<TCOL>& acol,
798  const Slicer* slicerPtr,
799  const TNODE* val,
800  size_t incr, const Array<Bool>& mask);
802  Bool maskFirst,
803  const IPosition& shapeCol,
804  const Slicer* slicerPtr);
805  void checkMaskColumn (Bool hasMask,
806  const ArrayColumn<Bool>& maskCol,
807  const TableColumn& col);
808  // </group>
809 
810  // Make a data type from the string.
811  // It checks if it is compatible with the given (expression) data type.
812  DataType makeDataType (DataType dtype, const String& dtstr,
813  const String& colName);
814 
815  // Get the order for this key. Use the default order_p if not
816  // explicitly given with the key.
817  Sort::Order getOrder (const TableParseSort& key) const;
818 
819  // Make an array from the contents of a column in a subquery.
821 
822  // Make a set from the results of the subquery.
823  TableExprNode makeSubSet() const;
824 
825  // Evaluate an int scalar expression.
826  Int64 evalIntScaExpr (const TableExprNode& expr) const;
827 
828  // Find a table for the given shorthand.
829  // Optionally the WITH tables are searched as well.
830  // If no shorthand is given, the first table is returned (if there).
831  // If not found, a null Table object is returned.
832  Table findTable (const String& shorthand, Bool doWith) const;
833  Table findTable (const String& shorthand, Bool doWith,
834  const std::vector<TableParseSelect*>& stack) const;
835 
836  // Handle the selection of a wildcarded column name.
837  void handleWildColumn (Int stringType, const String& name);
838 
839  // Add the description of a column to the table description.
840  // ndim < 0 means a scalar column.
841  void addColumnDesc (TableDesc& td, DataType dtype,
842  const String& colName, Int options,
843  Int ndim, const IPosition& shape,
844  const String& dmType, const String& dmGroup,
845  const String& comment,
846  const TableRecord& keywordSet,
847  const Vector<String>& unitName,
848  const Record& attributes);
849 
850  // Find the ColumnDesc and data manager info of another column (a LIKE column).
851  // The LIKE column name can be qualified to use another table.
852  // It sets the new column name in the data manager info.
853  // An exception is thrown if colName is invalid or unknown.
854  std::pair<ColumnDesc,Record> findColumnInfo (const String& colName,
855  const String& newColName) const;
856 
857  // Find the names of all stored columns in a table.
858  Block<String> getStoredColumns (const Table& tab) const;
859 
860  // Check if the tables used in selection columns have the same
861  // size as the first table given in FROM.
862  void checkTableProjSizes() const;
863 
864  // Create the set of aggregate functions and groupby keys in case
865  // a single groupby key is given.
866  // This offers much faster map access then doGroupByAggrMultiple.
867  template<typename T>
868  std::vector<CountedPtr<TableExprGroupFuncSet> > doGroupByAggrSingleKey
869  (const std::vector<TableExprNodeRep*>& aggrNodes)
870  {
871  // We have to group the data according to the (possibly empty) groupby.
872  // We step through the table in the normal order which may not be the
873  // groupby order.
874  // A map<key,int> is used to keep track of the results where the int
875  // is the index in a vector of a set of aggregate function objects.
876  std::vector<CountedPtr<TableExprGroupFuncSet> > funcSets;
877  std::map<T, int> keyFuncMap;
878  T lastKey = std::numeric_limits<T>::max();
879  int groupnr = -1;
880  // Loop through all rows.
881  // For each row generate the key to get the right entry.
882  TableExprId rowid(0);
883  T key;
884  for (rownr_t i=0; i<rownrs_p.size(); ++i) {
885  rowid.setRownr (rownrs_p[i]);
886  groupbyNodes_p[0].get (rowid, key);
887  if (key != lastKey) {
888  typename std::map<T, int>::iterator iter = keyFuncMap.find (key);
889  if (iter == keyFuncMap.end()) {
890  groupnr = funcSets.size();
891  keyFuncMap[key] = groupnr;
892  funcSets.push_back (new TableExprGroupFuncSet (aggrNodes));
893  } else {
894  groupnr = iter->second;
895  }
896  }
897  rowid.setRownr (rownrs_p[i]);
898  funcSets[groupnr]->apply (rowid);
899  }
900  return funcSets;
901  }
902 
903  // Create the set of aggregate functions and groupby keys in case
904  // multiple keys are given.
905  std::vector<CountedPtr<TableExprGroupFuncSet> > doGroupByAggrMultipleKeys
906  (const std::vector<TableExprNodeRep*>& aggrNodes);
907 
908  //# Command type.
910  //# Table and data manager description for a series of column descriptions.
911  //# TableDesc has no copy ctor, so use a shared_ptr.
912  std::shared_ptr<TableDesc> tableDesc_p;
914  //# Vector of TableParse objects (from WITH and FROM clause).
915  //# This is needed for the functions above, otherwise they have no
916  //# way to communicate.
917  std::vector<TableParse> withTables_p;
918  std::vector<TableParse> fromTables_p;
919  //# Block of selected column names (new name in case of select).
921  //# Block of selected mask column names (for masked arrays).
923  //# Block of selected column expressions.
925  //# The old name for a selected column.
927  //# The new data type for a column.
929  //# The keywords used in a column.
931  //# Number of real expressions used in selected columns.
933  //# Distinct values in output?
935  //# Name and type of the resulting table (from GIVING part).
937  uInt resultType_p; //# 0-unknown 1=memory 2=scratch 3=plain
938  Bool resultCreated_p; //# Has the result table been created?
942  //# Resulting set (from GIVING part).
944  //# The WHERE expression tree.
946  //# The GROUPBY expressions.
947  std::vector<TableExprNode> groupbyNodes_p;
948  Bool groupbyRollup_p; //# use ROLLUP in GROUPBY?
949  //# The HAVING expression.
951  //# The possible limit (= max nr of selected rows) (0 means no limit).
953  //# The possible last row (0 means no end; can be <0).
954  //# limit_p and endrow_p cannot be both !=0.
956  //# The possible offset (= nr of selected rows to skip).
958  //# The possible stride in offset:endrow:stride.
960  //# The update and insert list.
961  std::vector<CountedPtr<TableParseUpdate>> update_p;
962  //# The insert expressions (possibly for multiple rows).
963  std::vector<TableExprNode> insertExprs_p;
964  //# The table selection to be inserted.
966  //# The sort list.
967  std::vector<TableParseSort> sort_p;
968  //# The noDuplicates sort switch.
970  //# The default sort order.
972  //# All nodes that need to be adjusted for a selection of rownrs.
973  //# It can consist of column nodes and the rowid function node.
974  //# Some nodes (in aggregate functions) can later be disabled for adjustment.
975  std::vector<TableExprNode> applySelNodes_p;
976  //# The resulting table.
978  //# The first table used when creating a column object.
979  //# All other tables used for them should have the same size.
982  //# The table resulting from a projection with expressions.
984  //# The projected columns used in the HAVING and ORDERBY clauses.
987  //# The resulting row numbers.
989 };
990 
991 
992 
993 //# Implement the inline functions.
994 inline Bool TableParse::test (const String& str) const
995  { return (str.empty() || shorthand_p == str); }
996 
997 inline Int TableParse::tabnr() const
998  { return tabnr_p; }
999 
1000 inline const String& TableParse::name() const
1001  { return name_p; }
1002 
1003 inline const String& TableParse::shorthand() const
1004  { return shorthand_p; }
1005 
1006 inline const Table& TableParse::table() const
1007  { return table_p; }
1008 
1010  { return table_p; }
1011 
1012 inline void TableParse::replaceTable (const Table& table)
1013  { table_p = table; }
1014 
1015 
1016 inline void TableParseUpdate::setColumnName (const String& name)
1017  { columnName_p = name; }
1019  { columnNameMask_p = name; }
1021  { return columnName_p; }
1023  { return columnNameMask_p; }
1025  { return indexPtr_p; }
1027  { return indexNode_p; }
1029  { return node_p; }
1031  { return node_p; }
1032 inline void TableParseUpdate::adaptUnit (const Unit& columnUnit)
1033  { node_p.adaptUnit (columnUnit); }
1034 
1036  { return node_p; }
1038  { return given_p; }
1040  { return order_p; }
1041 
1042 
1044  { return columnNames_p; }
1045 
1046 inline const Table& TableParseSelect::getTable() const
1047  { return table_p; }
1048 
1050  { update_p.push_back (upd); }
1051 
1053  { return (key.orderGiven() ? key.order() : order_p); }
1054 
1055 
1056 } //# NAMESPACE CASACORE - END
1057 
1058 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:118
Bool orderGiven() const
Is the order given?
Definition: TableParse.h:1037
Block< Bool > projectExprSelColumn_p
Definition: TableParse.h:986
void handleSort(const std::vector< TableParseSort > &sortList, Bool noDuplicates, Sort::Order defaultSortOrder)
Keep the sort expressions.
A 1-D Specialization of the Array class.
Definition: ArrayFwd.h:9
void updateSlice(rownr_t row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, const Slicer &slice, ArrayColumn< TCOL > &col)
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
void doUpdate(Bool showTimings, const Table &origTable, Table &updTable, const Vector< rownr_t > &rownrs, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the update step.
void setColumnName(const String &name)
Set the column name.
Definition: TableParse.h:1016
void updateArray(rownr_t row, const TableExprId &rowid, const TableExprNode &node, const Array< TNODE > &res, ArrayColumn< TCOL > &col)
void copyMaskedValue(rownr_t row, ArrayColumn< TCOL > &acol, const Slicer *slicerPtr, const TNODE *val, size_t incr, const Array< Bool > &mask)
int Int
Definition: aipstype.h:50
void addColumnDesc(TableDesc &td, DataType dtype, const String &colName, Int options, Int ndim, const IPosition &shape, const String &dmType, const String &dmGroup, const String &comment, const TableRecord &keywordSet, const Vector< String > &unitName, const Record &attributes)
Add the description of a column to the table description.
TableExprNodeSet * resultSet_p
Definition: TableParse.h:943
TableExprNode getNode() const
Return the expression node.
Definition: TableParse.h:421
TableParseSort()
Construct from a given expression.
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:196
static String getTypeString(const String &typeStr, DataType type)
Get the type string.
Sort::Order order() const
Get the sort order.
Definition: TableParse.h:1039
void handleColumn(Int type, const String &name, const TableExprNode &expr, const String &newName, const String &nameMask, const String &newDtype)
Add a column to the list of column names.
Int testGroupAggr(std::vector< TableExprNodeRep * > &aggr) const
Test if groupby or aggregate functions are given.
Table doProject(Bool showTimings, const Table &, const CountedPtr< TableExprGroupResult > &groups=CountedPtr< TableExprGroupResult >())
Do the projection step returning a table containing the projection.
Main interface class to a read/write table.
Definition: Table.h:157
TableExprNodeIndex * indexPtr_p
Definition: TableParse.h:346
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
void handleGroupby(const std::vector< TableExprNode > &, Bool rollup)
Keep the groupby expressions.
std::vector< TableExprNode > insertExprs_p
Definition: TableParse.h:963
void replaceTable(const Table &)
Replace the Table object.
Definition: TableParse.h:1012
TableExprNode indexNode_p
Definition: TableParse.h:347
ValueHolder getRecFld(const String &name)
Add a keyword or replace a keyword with the value of another keyword.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1929
static TableExprFuncNode::FunctionType findFunc(const String &name, uInt narguments, const Vector< Int > &ignoreFuncs)
Find the function code belonging to a function name.
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:310
void handleAddCol(const Record &dmInfo)
Add columns to the table of ALTER TABLE.
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
Handle class for a table column expression tree.
Definition: ExprNode.h:156
TableExprNode node_p
Definition: TableParse.h:236
void handleRenameKey(const String &oldName, const String &newName)
Rename a table or column keyword.
void handleColSpec(const String &columnName, const String &likeColName, const String &dataType, const Record &spec, Bool isCOrder=False)
Keep the column specification in a create table command.
void setRownr(rownr_t rownr)
Set the row number.
Definition: TableExprId.h:185
Order
Enumerate the sort order:
Definition: Sort.h:259
DataType makeDataType(DataType dtype, const String &dtstr, const String &colName)
Make a data type from the string.
void setColumnNameMask(const String &name)
Set the column name forthe mask.
Definition: TableParse.h:1018
const String & columnNameMask() const
Get the possible column name for the mask.
Definition: TableParse.h:1022
Table doFinish(Bool showTimings, Table &table, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Finish the table (rename, copy, and/or flush).
static TableExprNode makeFuncNode(TableParseSelect *, const String &name, const TableExprNodeSet &arguments, const Vector< int > &ignoreFuncs, const Table &table, const TaQLStyle &)
Make a function object node for the given function name and arguments.
void checkNode() const
Check if the node results in a scalar and does not contain aggregate functions.
void handleInsert()
Make ready for the insert expression.
void adaptUnit(const Unit &)
Adapt the unit of the expression to the given unit (if not empty).
void checkTableProjSizes() const
Check if the tables used in selection columns have the same size as the first table given in FROM...
TableExprNode handleKeyCol(const String &name, Bool tryProj)
Find the keyword or column name and create a TableExprNode from it.
CommandType commandType() const
Return the command type.
Definition: TableParse.h:417
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:157
void adaptUnit(const Unit &columnUnit)
Adapt the possible unit of the expression to the possible unit of the column.
Definition: TableParse.h:1032
void doHaving(Bool showTimings, const CountedPtr< TableExprGroupResult > &groups)
Do the HAVING step.
Table createSubTable(const String &subtableName, const TableDesc &td, Int64 nrow, const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Block< String > columnNameMasks_p
Definition: TableParse.h:922
const Table & table() const
Get table object.
Definition: TableParse.h:1006
void handleIndices(const TableExprNodeSet &indices, const TaQLStyle &style)
Handle the subscripts or mask.
static TableExprNode handleSlice(const TableExprNode &array, const TableExprNodeSet &indices, const TaQLStyle &)
Handle a slice operator.
Table adjustApplySelNodes(const Table &)
Set the selected rows for the column objects in applySelNodes_p.
void handleLimit(const TableExprNodeSetElem &expr)
Evaluate and keep limit/offset/stride given as start:end:incr.
Options defining how table files are organized.
Definition: StorageOption.h:76
String getTableInfo(const Vector< String > &parts, const TaQLStyle &style)
Show the structure of fromTables_p[0] using the options given in parts[2:].
Table doInsert(Bool showTimings, Table &table)
Do the insert step and return a selection containing the new rows.
defines physical units
Definition: Unit.h:189
const TableExprNode & node() const
Get the expression node.
Definition: TableParse.h:1035
void handleRemoveKey(const String &name)
Remove a table or column keyword.
const TableExprNode & indexNode() const
Get the index expression node.
Definition: TableParse.h:1026
static TableExprNode makeUDFNode(TableParseSelect *, const String &name, const TableExprNodeSet &arguments, const Table &table, const TaQLStyle &)
Try to make a UDF function node for the given function name and arguments.
std::vector< TableParse > fromTables_p
Definition: TableParse.h:918
void handleSetKey(const String &name, const String &dtype, const ValueHolder &value)
Add a keyword or replace a keyword with a value.
Select-class for flex/bison scanner/parser for TableParse.
Definition: TableParse.h:388
Block< String > getStoredColumns(const Table &tab) const
Find the names of all stored columns in a table.
Bool test(const String &shortHand) const
Test if shorthand matches.
Definition: TableParse.h:994
void makeTableNoFrom(const std::vector< TableParseSelect * > &stack)
Create a temporary table if no tables are given in FROM.
std::vector< TableExprNode > groupbyNodes_p
Definition: TableParse.h:947
void doDelete(Bool showTimings, Table &table)
Do the delete step.
static Bool splitName(String &shorthand, String &columnName, Vector< String > &fieldNames, const String &name, Bool checkError, Bool isKeyword, Bool allowNoKey)
Split a name into its parts (shorthand, column and field names).
Int64 evalIntScaExpr(const TableExprNode &expr) const
Evaluate an int scalar expression.
Referenced counted pointer for constant data.
Definition: CountedPtr.h:80
void handleCalcComm(const TableExprNode &)
Keep the expression of a calculate command.
Table::EndianFormat endianFormat_p
Definition: TableParse.h:940
Class to hold the table expression nodes for an element in a set.
Definition: ExprNodeSet.h:93
void updateScalar(rownr_t row, const TableExprId &rowid, const TableExprNode &node, TableColumn &col)
const String & columnName() const
Get the column name.
Definition: TableParse.h:1020
Array< Bool > makeMaskSlice(const Array< Bool > &mask, Bool maskFirst, const IPosition &shapeCol, const Slicer *slicerPtr)
Vector< rownr_t > rownrs_p
Definition: TableParse.h:988
const Table & getTable() const
Get the resulting table.
Definition: TableParse.h:1046
CountedPtr< TableExprGroupResult > doGroupby(bool showTimings, const std::vector< TableExprNodeRep * > aggrNodes, Int groupAggrUsed)
Do the groupby/aggregate step and return its result.
std::pair< ColumnDesc, Record > findColumnInfo(const String &colName, const String &newColName) const
Find the ColumnDesc and data manager info of another column (a LIKE column).
static void setRecFld(RecordInterface &rec, const String &name, const String &dtype, const ValueHolder &vh)
Define a field with the given data type in the Record.
Class to hold the result of a TaQL command.
Definition: TaQLResult.h:67
TableExprNode getColSet()
Make an array from the contents of a column in a subquery.
A holder for a value of any basic Casacore data type.
Definition: ValueHolder.h:68
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.
TableExprNodeIndex * indexPtr() const
Get the pointer to the indices.
Definition: TableParse.h:1024
Table findTable(const String &shorthand, Bool doWith) const
Find a table for the given shorthand.
std::vector< CountedPtr< TableExprGroupFuncSet > > doGroupByAggrMultipleKeys(const std::vector< TableExprNodeRep * > &aggrNodes)
Create the set of aggregate functions and groupby keys in case multiple keys are given.
void makeProjectExprSel()
Fill projectExprSelColumn_p telling the columns to be projected at the first stage.
void handleGiving(const String &name, const Record &type)
Handle the name and type given in a GIVING clause.
Block< uInt > projectExprSubset_p
Definition: TableParse.h:985
Block< String > columnDtypes_p
Definition: TableParse.h:928
Table openParentTable(const String &fullName, const String &subTableName, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Open the parent table of a subtable.
void show(ostream &os) const
Show the expression tree.
Block< TableRecord > columnKeywords_p
Definition: TableParse.h:930
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
~TableParseSelect()
Destructor.
void makeProjectExprTable()
Make the (empty) table for the epxression in the SELECT clause.
static void checkAggrFuncs(const TableExprNode &node)
An exception is thrown if the node uses an aggregate function.
void handleCount()
Make ready for a COUNT command.
Read/write access to a table column.
Definition: TableColumn.h:98
void handleUpdate()
Keep the update expressions.
Int tabnr() const
Get the given table number (of $i tables in TempTables)
Definition: TableParse.h:997
Class containing the results of aggregated values in a group.
Definition: ExprGroup.h:801
Block< String > columnNames_p
Definition: TableParse.h:920
const Bool False
Definition: aipstype.h:44
std::vector< TableParse > withTables_p
Definition: TableParse.h:917
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1987
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:185
Block< TableExprNode > columnExpr_p
Definition: TableParse.h:924
TableExprNode doExists(Bool noexists, Bool showTimings)
Test if a subquery has sufficient elements.
void handleColumnFinish(Bool distinct)
Finish the addition of columns to the list of column names.
TableParse()
Default constructor for container class.
Helper class for sort keys in TableParse.
Definition: TableParse.h:206
Bool maskFirst() const
Tell if the mask is given first (i.e., before slice).
Definition: TableParse.h:319
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:288
Table doProjectExpr(Bool useSel, const CountedPtr< TableExprGroupResult > &groups)
Do the projection containing column expressions.
simple 1-D array
Definition: Allocator.h:210
void handleCopyCol(Bool showTimings)
Handle copying of columns.
TableParseSelect(CommandType type)
Construct.
TableExprNode handleFunc(const String &name, const TableExprNodeSet &arguments, const TaQLStyle &)
Handle a function.
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
void addUpdate(const CountedPtr< TableParseUpdate > &upd)
Add an update object.
Definition: TableParse.h:1049
Class to hold values from table grammar parser.
Definition: TableParse.h:109
void updateValue(rownr_t row, const TableExprId &rowid, Bool isScalarCol, const TableExprNode &node, const Array< Bool > &mask, Bool maskFirst, TableColumn &col, const Slicer *slicerPtr, ArrayColumn< Bool > &maskCol)
Update the values in the columns (helpers of doUpdate).
TableExprNode havingNode_p
Definition: TableParse.h:950
TableParseSelect * insSel_p
Definition: TableParse.h:965
std::vector< TableExprNode > applySelNodes_p
Definition: TableParse.h:975
The identification of a TaQL selection subject.
Definition: TableExprId.h:97
std::vector< CountedPtr< TableParseUpdate > > update_p
Definition: TableParse.h:961
std::vector< CountedPtr< TableExprGroupFuncSet > > doGroupByAggrSingleKey(const std::vector< TableExprNodeRep * > &aggrNodes)
Create the set of aggregate functions and groupby keys in case a single groupby key is given...
Definition: TableParse.h:869
const TableExprNode & node() const
Get the expression node.
Definition: TableParse.h:1028
void doSort(Bool showTimings)
Do the sort step.
std::vector< TableExprNodeRep * > getAggrNodes() const
Get the aggregate functions used in SELECT and HAVING.
void handleHaving(const TableExprNode &)
Keep the having expression.
void setInsertExprs(const std::vector< TableExprNode > exprs)
Set the insert expressions for all rows.
Definition: TableParse.h:530
const Block< String > & getColumnNames() const
Get the projected column names.
Definition: TableParse.h:1043
Block< String > columnOldNames_p
Definition: TableParse.h:926
TableExprNode makeSubSet() const
Make a set from the results of the subquery.
TableExprNode doSubQuery(Bool showTimings)
Execute a subquery and create an appropriate node for the result.
Table doDistinct(Bool showTimings, const Table &table)
Do the &#39;select distinct&#39; step.
void handleAddRow(const TableExprNode &expr)
Evaluate and add the rows.
void handleOffset(const TableExprNode &expr)
Evaluate and keep the offset value.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
void replaceTable(const Table &table)
Replace the first table (used by CALC command).
const String & name() const
Get the given table name.
Definition: TableParse.h:1000
Define the structure of a Casacore table.
Definition: TableDesc.h:190
size_t size() const
Definition: ArrayBase.h:105
Table createTable(const TableDesc &td, Int64 nrow, const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Create a table using the given parameters.
void checkMaskColumn(Bool hasMask, const ArrayColumn< Bool > &maskCol, const TableColumn &col)
TaQLResult tableCommand(const String &command)
Abstract base class for Record classes.
std::shared_ptr< TableDesc > tableDesc_p
Definition: TableParse.h:912
void doLimOff(Bool showTimings)
Do the limit/offset step.
StorageOption storageOption_p
Definition: TableParse.h:939
void execute(Bool showTimings, Bool setInGiving, Bool mustSelect, rownr_t maxRow, Bool doTracing=False, const std::vector< const Table * > &tempTables=std::vector< const Table * >(), const std::vector< TableParseSelect * > &stack=std::vector< TableParseSelect * >())
Execute the select command (select/sort/projection/groupby/having/giving).
void handleAltTab()
Reopen the table (for update) used in the ALTER TABLE command.
void handleWildColumn(Int stringType, const String &name)
Handle the selection of a wildcarded column name.
Table doFromQuery(Bool showTimings)
Execute a query in a from clause resulting in a Table.
The index of an array element in a table select expression.
Table addTable(Int tabnr, const String &name, const Table &table, const String &shorthand, Bool addToFromList, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Add a table nr, name, or object to the container.
void handleDropTab(const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Handle the DROP TABLE command.
void addApplySelNode(const TableExprNode &node)
Add a column node to applySelNodes_p.
Definition: TableParse.h:732
const Bool True
Definition: aipstype.h:43
void handleWhere(const TableExprNode &)
Keep the selection expression.
CountedPtr< TableExprGroupResult > doGroupByAggr(const std::vector< TableExprNodeRep * > &aggrNodes)
Do a full groupby/aggregate step.
Sort::Order getOrder(const TableParseSort &key) const
Get the order for this key.
Definition: TableParse.h:1052
const String & shorthand() const
Get the shorthand.
Definition: TableParse.h:1003
Table doCount(Bool showTimings, const Table &)
Do the count step returning a memory table containing the unique column values and the counts of the ...
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
Helper class for updates in TableParse.
Definition: TableParse.h:270
const TableExprNode & mask() const
Get the mask.
Definition: TableParse.h:335
void initDescriptions(const TableDesc &, const Record &dminfo)
Initialize the table and data manager descriptions.
CountedPtr< TableExprGroupResult > doOnlyCountAll(TableExprNodeRep *aggrNode)
Do a groupby/aggregate step that only does a &#39;select count(*)&#39;.
Bool empty() const
Test for empty.
Definition: String.h:377
TableRecord & findKeyword(const String &name, String &keyName, Bool update=True)
Split the given name into optional shorthand, column and fields.
std::vector< TableParseSort > sort_p
Definition: TableParse.h:967
void setDMInfo(const Record &dminfo)
Set the DataManager info for a new table.
Definition: TableParse.h:618
void handleCreTab(const Record &dmInfo, const std::vector< const Table * > &tempTables, const std::vector< TableParseSelect * > &stack)
Keep the create table command.