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
46// <summary>
47// Class to handle the nodes in the raw TaQL parse tree.
48// </summary>
49
50// <use visibility=local>
51
52// <reviewed reviewer="" date="" tests="tTableGram">
53// </reviewed>
54
55// <prerequisite>
56//# Classes you should understand before using this one.
57// <li> <linkto class=TaQLNode>TaQLNode</linkto>
58// <li> Note 199 describing
59// <a href="../notes/199.html">
60// TaQL</a>
61// </prerequisite>
62
63// <synopsis>
64// TaQLNodeHandler is a specialization of class
65// <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>.
66// It processes the raw TaQL parse tree generated by TableGram.
67// The processing is done in a recursive way. It starts at the top
68// (which is a SELECT, UPDATE, etc. expression) and the processing
69// results of a query are stored in a TableParseQuery object.
70// These objects are kept in a stack for possible nested queries.
71// After a query is fully processed, it is executed. Usually the result
72// is a table; only a CALC command gives a TableExprNode as result.
73// </synopsis>
74
75// <motivation>
76// Separating the raw query parsing from the query processing has
77// several advantages compared to the old situation where parsing
78// and processing were combined.
79// <ul>
80// <li> The full command is parsed before any processing is done.
81// So in case of a parse error, no possibly expensive processing
82// has been done yet.
83// <li> In the future query optimization can be done in an easier way.
84// <li> Nested parsing is not possible. In case a Table is opened
85// with a virtual TaQL column, the parsing of that TaQL string
86// does not interfere with parsing the TaQL command.
87// <li> It is possible to use expressions in the column list.
88// That could not be done before, because the column list was
89// parsed/processed before the table list.
90// </ul>
91// </motivation>
92
94{
95public:
97
98 // Handle and process the raw parse tree.
99 // The result contains a Table or TableExprNode object.
101 const std::vector<const Table*>&);
102
103 // Define the functions to visit each node type.
104 // <group>
143 // </group>
144
145 // Get the actual result object from the result.
146 static const TaQLNodeHRValue& getHR (const TaQLNodeResult&);
147
148private:
149 // Push a new TableParseQuery on the stack.
151
152 // Get the top of the TableParseQuery stack.
154
155 // Pop the top from the TableParseQuery stack.
156 void popStack();
157
158 // Clear the select stack.
160
161 // Handle the select command.
162 // Optionally the command is not executed (needed for the EXISTS operator).
164
165 // Handle a table name or temptable number in the given node
166 // and put it in the value result.
167 void handleTableName (TaQLNodeHRValue* hrval, const TaQLNode& node);
168
169 // Handle a MultiNode containing table info.
170 void handleTables (const TaQLMultiNode&, Bool addToFromList=True);
171
172 // Handle a MultiNoide containing joins.
173 void handleJoins (const TaQLMultiNode& node);
174
175 // Make a ConcatTable from a nested set of tables.
177
178 // Handle the WHERE clause.
179 void handleWhere (const TaQLNode&);
180
181 // Handle the HAVING clause.
182 void handleHaving (const TaQLNode&);
183
184 // Handle the UPDATE SET clause.
186
187 // Handle the INSERT columns.
189
190 // Handle the INSERT values.
191 void handleInsVal (const TaQLNode&);
192
193 // Handle the possible LIKE table DROP COLUMN part.
194 void handleLikeDrop (const TaQLMultiNode& node);
195
196 // Handle a column specification in a create table or add column.
198
199 // Handle a Multi RecFld representing a Record.
201
202 // Handle the MSID function.
204
205 //# Data members
206 //# Use vector instead of stack because random access is needed.
207 std::vector<TableParseQuery*> itsStack;
208 //# The temporary tables referred to by $i in the TaQL string.
209 std::vector<const Table*> itsTempTables;
210};
211
212
213// <summary>
214// Class containing the result value of the handling of a TaQLNode.
215// </summary>
216
217// <use visibility=local>
218
219// <reviewed reviewer="" date="" tests="tTableGram">
220// </reviewed>
221
222// <prerequisite>
223//# Classes you should understand before using this one.
224// <li> <linkto class=TaQLNode>TaQLNodeResult</linkto>
225// <li> <linkto class=TaQLNode>TaQLNodeHandler</linkto>
226// <li> Note 199 describing
227// <a href="../notes/199.html">
228// TaQL</a>
229// </prerequisite>
230
231// <synopsis>
232// TaQLNodeHRValue is a specialization of class
233// <linkto class=TaQLNodeResultRep>TaQLNodeResultRep</linkto>.
234// It contains the values resulting from handling a particular node.
235// The object is effectively a collection of all possible values that
236// need to be returned. Which values are filled in, depends on which node
237// has been processed.
238// <note> The getHR function in TaQLNodeHandler is very useful to
239// extract/cast the TaQLNodeHRValue object from the general
240// TaQLNodeResult object.
241// </note>
242// </synopsis>
243
245{
246public:
248 : itsInt(-1), itsElem(0), itsSet(0), itsNames(0) {}
250 : itsInt(-1), itsExpr(expr), itsElem(0), itsSet(0), itsNames(0) {}
251 ~TaQLNodeHRValue() override = default;
252
253 // Get the values.
254 // <group>
255 Int getInt() const
256 { return itsInt; }
257 const String& getString() const
258 { return itsString; }
259 const String& getAlias() const
260 { return itsAlias; }
261 const String& getNameMask() const
262 { return itsNameMask; }
263 const String& getDtype() const
264 { return itsDtype; }
265 const Record& getRecord() const
266 { return itsRecord; }
268 { return itsVH; }
269 const Table& getTable() const
270 { return itsTable; }
271 const TableExprNode& getExpr() const
272 { return itsExpr; }
274 { return itsElem; }
276 { return *itsSet; }
278 { return itsNames; }
279 // </group>
280
281 // Set the values.
282 // If a pointer is given, it takes over the pointer.
283 // <group>
284 void setInt (Int ival)
285 { itsInt = ival; }
286 void setString (const String& str)
287 { itsString = str; }
288 void setAlias (const String& alias)
289 { itsAlias = alias; }
290 void setNameMask (const String& nameMask)
291 { itsNameMask = nameMask; }
292 void setDtype (const String& dtype)
293 { itsDtype = dtype; }
294 void setRecord (const Record& record)
295 { itsRecord = record; }
297 { itsVH = vh; }
298 void setTable (const Table& table)
299 { itsTable = table; }
300 void setExpr (const TableExprNode& expr)
301 { itsExpr = expr; }
303 { itsElem = elem; }
305 { itsSet = set; }
306 void setNames (const Vector<String>& names)
307 { itsNames = names; }
308 // </group>
309
310private:
320 TableExprNodeSetElem* itsElem; //# is counted in itsExpr
321 TableExprNodeSet* itsSet; //# is counted in itsExpr
323};
324
325
326//# This function can only be implemented after TaQLNodeHRValue is declared.
328{
329 return dynamic_cast<const TaQLNodeHRValue&>(res.getRep());
330}
331
332
333
334} //# NAMESPACE CASACORE - END
335
336#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
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:225
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)
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.
this file contains all the compiler specific defines
Definition mainpage.dox:28
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