casacore
Loading...
Searching...
No Matches
TaQLNodeHandler.h
Go to the documentation of this file.
1// # TaQLNodeHandler.h: Classes to handle the nodes in the raw TaQL parse tree
2// # Copyright (C) 2005
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: casa-feedback@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#ifndef TABLES_TAQLNODEHANDLER_H
27#define TABLES_TAQLNODEHANDLER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/TaQLNodeVisitor.h>
32#include <casacore/tables/TaQL/TaQLNodeDer.h>
33#include <casacore/tables/TaQL/TableParseQuery.h>
34#include <casacore/tables/TaQL/ExprNode.h>
35#include <casacore/tables/TaQL/ExprNodeSet.h>
36#include <casacore/casa/Containers/Record.h>
37#include <casacore/casa/Containers/ValueHolder.h>
38#include <vector>
39
40namespace casacore { // # NAMESPACE CASACORE - BEGIN
41
42// # Forward Declarations
43class TaQLNodeHRValue;
44
45// <summary>
46// Class to handle the nodes in the raw TaQL parse tree.
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="" date="" tests="tTableGram">
52// </reviewed>
53
54// <prerequisite>
55// # Classes you should understand before using this one.
56// <li> <linkto class=TaQLNode>TaQLNode</linkto>
57// <li> Note 199 describing
58// <a href="../notes/199.html">
59// TaQL</a>
60// </prerequisite>
61
62// <synopsis>
63// TaQLNodeHandler is a specialization of class
64// <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>.
65// It processes the raw TaQL parse tree generated by TableGram.
66// The processing is done in a recursive way. It starts at the top
67// (which is a SELECT, UPDATE, etc. expression) and the processing
68// results of a query are stored in a TableParseQuery object.
69// These objects are kept in a stack for possible nested queries.
70// After a query is fully processed, it is executed. Usually the result
71// is a table; only a CALC command gives a TableExprNode as result.
72// </synopsis>
73
74// <motivation>
75// Separating the raw query parsing from the query processing has
76// several advantages compared to the old situation where parsing
77// and processing were combined.
78// <ul>
79// <li> The full command is parsed before any processing is done.
80// So in case of a parse error, no possibly expensive processing
81// has been done yet.
82// <li> In the future query optimization can be done in an easier way.
83// <li> Nested parsing is not possible. In case a Table is opened
84// with a virtual TaQL column, the parsing of that TaQL string
85// does not interfere with parsing the TaQL command.
86// <li> It is possible to use expressions in the column list.
87// That could not be done before, because the column list was
88// parsed/processed before the table list.
89// </ul>
90// </motivation>
91
93 public:
95
96 // Handle and process the raw parse tree.
97 // The result contains a Table or TableExprNode object.
98 TaQLNodeResult handleTree(const TaQLNode& tree, const std::vector<const Table*>&);
99
100 // Define the functions to visit each node type.
101 // <group>
140 // </group>
141
142 // Get the actual result object from the result.
143 static const TaQLNodeHRValue& getHR(const TaQLNodeResult&);
144
145 private:
146 // Push a new TableParseQuery on the stack.
148
149 // Get the top of the TableParseQuery stack.
151
152 // Pop the top from the TableParseQuery stack.
153 void popStack();
154
155 // Clear the select stack.
157
158 // Handle the select command.
159 // Optionally the command is not executed (needed for the EXISTS operator).
161
162 // Handle a table name or temptable number in the given node
163 // and put it in the value result.
164 void handleTableName(TaQLNodeHRValue* hrval, const TaQLNode& node);
165
166 // Handle a MultiNode containing table info.
167 void handleTables(const TaQLMultiNode&, Bool addToFromList = True);
168
169 // Handle a MultiNoide containing joins.
170 void handleJoins(const TaQLMultiNode& node);
171
172 // Make a ConcatTable from a nested set of tables.
174
175 // Handle the WHERE clause.
176 void handleWhere(const TaQLNode&);
177
178 // Handle the HAVING clause.
179 void handleHaving(const TaQLNode&);
180
181 // Handle the UPDATE SET clause.
183
184 // Handle the INSERT columns.
186
187 // Handle the INSERT values.
188 void handleInsVal(const TaQLNode&);
189
190 // Handle the possible LIKE table DROP COLUMN part.
191 void handleLikeDrop(const TaQLMultiNode& node);
192
193 // Handle a column specification in a create table or add column.
195
196 // Handle a Multi RecFld representing a Record.
198
199 // Handle the MSID function.
201
202 // # Data members
203 // # Use vector instead of stack because random access is needed.
204 std::vector<TableParseQuery*> itsStack;
205 // # The temporary tables referred to by $i in the TaQL string.
206 std::vector<const Table*> itsTempTables;
207};
208
209// <summary>
210// Class containing the result value of the handling of a TaQLNode.
211// </summary>
212
213// <use visibility=local>
214
215// <reviewed reviewer="" date="" tests="tTableGram">
216// </reviewed>
217
218// <prerequisite>
219// # Classes you should understand before using this one.
220// <li> <linkto class=TaQLNode>TaQLNodeResult</linkto>
221// <li> <linkto class=TaQLNode>TaQLNodeHandler</linkto>
222// <li> Note 199 describing
223// <a href="../notes/199.html">
224// TaQL</a>
225// </prerequisite>
226
227// <synopsis>
228// TaQLNodeHRValue is a specialization of class
229// <linkto class=TaQLNodeResultRep>TaQLNodeResultRep</linkto>.
230// It contains the values resulting from handling a particular node.
231// The object is effectively a collection of all possible values that
232// need to be returned. Which values are filled in, depends on which node
233// has been processed.
234// <note> The getHR function in TaQLNodeHandler is very useful to
235// extract/cast the TaQLNodeHRValue object from the general
236// TaQLNodeResult object.
237// </note>
238// </synopsis>
239
241 public:
244 : itsInt(-1), itsExpr(expr), itsElem(0), itsSet(0), itsNames(0) {}
245 ~TaQLNodeHRValue() override = default;
246
247 // Get the values.
248 // <group>
249 Int getInt() const { return itsInt; }
250 const String& getString() const { return itsString; }
251 const String& getAlias() const { return itsAlias; }
252 const String& getNameMask() const { return itsNameMask; }
253 const String& getDtype() const { return itsDtype; }
254 const Record& getRecord() const { return itsRecord; }
255 const ValueHolder& getValueHolder() const { return itsVH; }
256 const Table& getTable() const { return itsTable; }
257 const TableExprNode& getExpr() const { return itsExpr; }
258 const TableExprNodeSetElem* getElem() const { return itsElem; }
259 const TableExprNodeSet& getExprSet() const { return *itsSet; }
260 const Vector<String>& getNames() const { return itsNames; }
261 // </group>
262
263 // Set the values.
264 // If a pointer is given, it takes over the pointer.
265 // <group>
266 void setInt(Int ival) { itsInt = ival; }
267 void setString(const String& str) { itsString = str; }
268 void setAlias(const String& alias) { itsAlias = alias; }
269 void setNameMask(const String& nameMask) { itsNameMask = nameMask; }
270 void setDtype(const String& dtype) { itsDtype = dtype; }
271 void setRecord(const Record& record) { itsRecord = record; }
272 void setValueHolder(const ValueHolder& vh) { itsVH = vh; }
273 void setTable(const Table& table) { itsTable = table; }
274 void setExpr(const TableExprNode& expr) { itsExpr = expr; }
275 void setElem(TableExprNodeSetElem* elem) { itsElem = elem; }
277 void setNames(const Vector<String>& names) { itsNames = names; }
278 // </group>
279
280 private:
290 TableExprNodeSetElem* itsElem; // # is counted in itsExpr
291 TableExprNodeSet* itsSet; // # is counted in itsExpr
293};
294
295// # This function can only be implemented after TaQLNodeHRValue is declared.
297 return dynamic_cast<const TaQLNodeHRValue&>(res.getRep());
298}
299
300} // namespace casacore
301
302#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
Raw TaQL parse tree node defining an alter table add column command.
Raw TaQL parse tree node defining an alter table add rows command.
Raw TaQL parse tree node defining an alter table command.
Raw TaQL parse tree node defining a binary operator.
Raw TaQL parse tree node defining a calc command.
Raw TaQL parse tree node defining a select column expression.
Raw TaQL parse tree node defining a create column specification.
Raw TaQL parse tree node defining a select column list.
Raw TaQL parse tree node defining an alter table command.
Raw TaQL parse tree node defining an alter table copy column command.
Raw TaQL parse tree node defining a count command.
Raw TaQL parse tree node defining a create table command.
Raw TaQL parse tree node defining a delete command.
Raw TaQL parse tree node defining a DROP TABLE command.
Raw TaQL parse tree node defining a function.
Raw TaQL parse tree node defining a giving expression list.
Raw TaQL parse tree node defining a groupby list.
Raw TaQL parse tree node defining an index in a array.
Raw TaQL parse tree node defining an insert command.
Raw TaQL parse tree node defining a join operation.
Raw TaQL parse tree node defining a keyword or column name.
Raw TaQL parse tree node defining a limit/offset expression.
Raw TaQL parse tree node defining a list of nodes.
Envelope class for a node containing a list of nodes.
Definition TaQLNode.h:215
Class containing the result value of the handling of a TaQLNode.
void setTable(const Table &table)
~TaQLNodeHRValue() override=default
void setString(const String &str)
void setExprSet(TableExprNodeSet *set)
const String & getNameMask() const
const TableExprNodeSetElem * getElem() const
TaQLNodeHRValue(const TableExprNode &expr)
const TableExprNode & getExpr() const
const Vector< String > & getNames() const
void setNames(const Vector< String > &names)
TableExprNodeSet * itsSet
void setRecord(const Record &record)
const TableExprNodeSet & getExprSet() const
void setValueHolder(const ValueHolder &vh)
void setNameMask(const String &nameMask)
void setDtype(const String &dtype)
const ValueHolder & getValueHolder() const
const Record & getRecord() const
const String & getDtype() const
void setElem(TableExprNodeSetElem *elem)
void setExpr(const TableExprNode &expr)
void setAlias(const String &alias)
void setInt(Int ival)
Set the values.
const Table & getTable() const
Int getInt() const
Get the values.
TableExprNodeSetElem * itsElem
const String & getAlias() const
const String & getString() const
virtual TaQLNodeResult visitCopyColNode(const TaQLCopyColNodeRep &node)
virtual TaQLNodeResult visitTableNode(const TaQLTableNodeRep &node)
virtual TaQLNodeResult visitRangeNode(const TaQLRangeNodeRep &node)
Record handleMultiRecFld(const TaQLNode &node)
Handle a Multi RecFld representing a Record.
TableParseQuery * pushStack(TableParseQuery::CommandType)
Push a new TableParseQuery on the stack.
virtual TaQLNodeResult visitMultiNode(const TaQLMultiNodeRep &node)
void handleInsCol(const TaQLMultiNode &)
Handle the INSERT columns.
void handleColSpecs(const TaQLMultiNode &)
Handle a column specification in a create table or add column.
virtual TaQLNodeResult visitInsertNode(const TaQLInsertNodeRep &node)
virtual TaQLNodeResult visitRegexNode(const TaQLRegexNodeRep &node)
virtual TaQLNodeResult visitCalcNode(const TaQLCalcNodeRep &node)
virtual TaQLNodeResult visitColNode(const TaQLColNodeRep &node)
virtual TaQLNodeResult visitUnitNode(const TaQLUnitNodeRep &node)
virtual TaQLNodeResult visitDropTabNode(const TaQLDropTabNodeRep &node)
TableParseQuery * topStack() const
Get the top of the TableParseQuery stack.
void handleHaving(const TaQLNode &)
Handle the HAVING clause.
virtual TaQLNodeResult visitJoinNode(const TaQLJoinNodeRep &node)
virtual TaQLNodeResult visitFuncNode(const TaQLFuncNodeRep &node)
virtual TaQLNodeResult visitColSpecNode(const TaQLColSpecNodeRep &node)
void handleUpdate(const TaQLMultiNode &)
Handle the UPDATE SET clause.
void handleTableName(TaQLNodeHRValue *hrval, const TaQLNode &node)
Handle a table name or temptable number in the given node and put it in the value result.
void clearStack()
Clear the select stack.
TaQLNodeResult handleTree(const TaQLNode &tree, const std::vector< const Table * > &)
Handle and process the raw parse tree.
virtual TaQLNodeResult visitBinaryNode(const TaQLBinaryNodeRep &node)
virtual TaQLNodeResult visitDeleteNode(const TaQLDeleteNodeRep &node)
virtual TaQLNodeResult visitSortNode(const TaQLSortNodeRep &node)
virtual TaQLNodeResult visitShowNode(const TaQLShowNodeRep &node)
virtual TaQLNodeResult visitKeyColNode(const TaQLKeyColNodeRep &node)
virtual TaQLNodeResult visitSortKeyNode(const TaQLSortKeyNodeRep &node)
void handleLikeDrop(const TaQLMultiNode &node)
Handle the possible LIKE table DROP COLUMN part.
Table makeConcatTable(const TaQLMultiNodeRep &node)
Make a ConcatTable from a nested set of tables.
virtual TaQLNodeResult visitAddRowNode(const TaQLAddRowNodeRep &node)
virtual TaQLNodeResult visitColumnsNode(const TaQLColumnsNodeRep &node)
virtual TaQLNodeResult visitLimitOffNode(const TaQLLimitOffNodeRep &node)
virtual TaQLNodeResult visitCreTabNode(const TaQLCreTabNodeRep &node)
virtual TaQLNodeResult visitRecFldNode(const TaQLRecFldNodeRep &node)
std::vector< TableParseQuery * > itsStack
virtual TaQLNodeResult visitConcTabNode(const TaQLConcTabNodeRep &node)
virtual TaQLNodeResult visitGivingNode(const TaQLGivingNodeRep &node)
virtual TaQLNodeResult visitSelectNode(const TaQLSelectNodeRep &node)
std::vector< const Table * > itsTempTables
virtual TaQLNodeResult visitIndexNode(const TaQLIndexNodeRep &node)
virtual TaQLNodeResult visitCountNode(const TaQLCountNodeRep &node)
virtual TaQLNodeResult visitAltTabNode(const TaQLAltTabNodeRep &node)
void handleTables(const TaQLMultiNode &, Bool addToFromList=True)
Handle a MultiNode containing table info.
virtual TaQLNodeResult visitAddColNode(const TaQLAddColNodeRep &node)
virtual TaQLNodeResult visitGroupNode(const TaQLGroupNodeRep &node)
virtual TaQLNodeResult visitUnaryNode(const TaQLUnaryNodeRep &node)
virtual TaQLNodeResult visitUpdExprNode(const TaQLUpdExprNodeRep &node)
void popStack()
Pop the top from the TableParseQuery stack.
void handleJoins(const TaQLMultiNode &node)
Handle a MultiNoide containing joins.
TableExprNode handleIdFunc(const TaQLFuncNodeRep &node)
Handle the MSID function.
void handleInsVal(const TaQLNode &)
Handle the INSERT values.
virtual TaQLNodeResult visitSetKeyNode(const TaQLSetKeyNodeRep &node)
static const TaQLNodeHRValue & getHR(const TaQLNodeResult &)
Get the actual result object from the result.
TaQLNodeResult handleSelect(const TaQLSelectNodeRep &node, Bool doExec)
Handle the select command.
virtual TaQLNodeResult visitRenDropNode(const TaQLRenDropNodeRep &node)
void handleWhere(const TaQLNode &)
Handle the WHERE clause.
virtual TaQLNodeResult visitConstNode(const TaQLConstNodeRep &node)
Define the functions to visit each node type.
virtual TaQLNodeResult visitUpdateNode(const TaQLUpdateNodeRep &node)
TaQLNodeResultRep()
Default constructor.
Envelope class to hold the result of a visit to the node tree.
const TaQLNodeResultRep & getRep() const
Get the actual underlying object.
Raw TaQL parse tree node defining a range.
Raw TaQL parse tree node defining a record field.
Raw TaQL parse tree node defining a constant regex value.
Raw TaQL parse tree node defining an alter table rename or drop command.
Raw TaQL parse tree node defining a select command.
Raw TaQL parse tree node defining an alter table set keyword command.
Raw TaQL parse tree node defining a show command.
Raw TaQL parse tree node defining a sort key.
Raw TaQL parse tree node defining a sort list.
Raw TaQL parse tree node defining a table.
Raw TaQL parse tree node defining a unary operator.
Raw TaQL parse tree node defining a unit.
Raw TaQL parse tree node defining a column update expression.
Raw TaQL parse tree node defining an update command.
Class to hold the table expression nodes for an element in a set.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
void set(const T &val)
Definition Block.h:541
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41