casacore
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: 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_TAQLNODEHANDLER_H
29#define TABLES_TAQLNODEHANDLER_H
30
31//# Includes
32#include <casacore/casa/aips.h>
33#include <casacore/tables/TaQL/TaQLNodeVisitor.h>
34#include <casacore/tables/TaQL/TaQLNodeDer.h>
35#include <casacore/tables/TaQL/TableParse.h>
36#include <casacore/tables/TaQL/ExprNode.h>
37#include <casacore/tables/TaQL/ExprNodeSet.h>
38#include <casacore/casa/Containers/Record.h>
39#include <casacore/casa/Containers/ValueHolder.h>
40#include <vector>
41
42namespace casacore { //# NAMESPACE CASACORE - BEGIN
43
44//# Forward Declarations
45class TaQLNodeHRValue;
46
47
48// <summary>
49// Class to handle the nodes in the raw TaQL parse tree.
50// </summary>
51
52// <use visibility=local>
53
54// <reviewed reviewer="" date="" tests="tTableGram">
55// </reviewed>
56
57// <prerequisite>
58//# Classes you should understand before using this one.
59// <li> <linkto class=TaQLNode>TaQLNode</linkto>
60// <li> Note 199 describing
61// <a href="../notes/199.html">
62// TaQL</a>
63// </prerequisite>
64
65// <synopsis>
66// TaQLNodeHandler is a specialization of class
67// <linkto class=TaQLNodeVisitor>TaQLNodeVisitor</linkto>.
68// It processes the raw TaQL parse tree generated by TableGram.
69// The processing is done in a recursive way. It starts at the top
70// (which is a SELECT, UPDATE, etc. expression) and the processing
71// results of a query are stored in a TableParseSelect object.
72// These objects are kept in a stack for possible nested queries.
73// After a query is fully processed, it is executed. Usually the result
74// is a table; only a CALC command gives a TableExprNode as result.
75// </synopsis>
76
77// <motivation>
78// Separating the raw query parsing from the query processing has
79// several advantages compared to the old situation where parsing
80// and processing were combined.
81// <ul>
82// <li> The full command is parsed before any processing is done.
83// So in case of a parse error, no possibly expensive processing
84// has been done yet.
85// <li> In the future query optimization can be done in an easier way.
86// <li> Nested parsing is not possible. In case a Table is opened
87// with a virtual TaQL column, the parsing of that TaQL string
88// does not interfere with parsing the TaQL command.
89// <li> It is possible to use expressions in the column list.
90// That could not be done before, because the column list was
91// parsed/processed before the table list.
92// </ul>
93// </motivation>
94
96{
97public:
99
100 // Handle and process the raw parse tree.
101 // The result contains a Table or TableExprNode object.
103 const std::vector<const Table*>&);
104
105 // Define the functions to visit each node type.
106 // <group>
145 // </group>
146
147 // Get the actual result object from the result.
148 static const TaQLNodeHRValue& getHR (const TaQLNodeResult&);
149
150private:
151 // Push a new TableParseSelect on the stack.
153
154 // Get the top of the TableParseSelect stack.
156
157 // Pop the top from the TableParseSelect stack.
158 void popStack();
159
160 // Clear the select stack.
162
163 // Handle the select command.
164 // Optionally the command is not executed (needed for the EXISTS operator).
166
167 // Handle a table name or temptable number in the given node
168 // and put it in the value result.
169 void handleTableName (TaQLNodeHRValue* hrval, const TaQLNode& node);
170
171 // Handle a MultiNode containing table info.
172 void handleTables (const TaQLMultiNode&, Bool addToFromList=True);
173
174 // Make a ConcatTable from a nested set of tables.
176
177 // Handle the WHERE clause.
178 void handleWhere (const TaQLNode&);
179
180 // Handle the HAVING clause.
181 void handleHaving (const TaQLNode&);
182
183 // Handle the UPDATE SET clause.
185
186 // Handle the INSERT columns.
188
189 // Handle the INSERT values.
190 void handleInsVal (const TaQLNode&);
191
192 // Handle the possible LIKE table DROP COLUMN part.
193 void handleLikeDrop (const TaQLMultiNode& node);
194
195 // Handle a column specification in a create table or add column.
197
198 // Handle a Multi RecFld representing a Record.
200
201
202 //# Use vector instead of stack because it has random access
203 //# (which is used in TableParse.cc).
204 std::vector<TableParseSelect*> itsStack;
205 //# The temporary tables referred to by $i in the TaQL string.
206 std::vector<const Table*> itsTempTables;
207};
208
209
210// <summary>
211// Class containing the result value of the handling of a TaQLNode.
212// </summary>
213
214// <use visibility=local>
215
216// <reviewed reviewer="" date="" tests="tTableGram">
217// </reviewed>
218
219// <prerequisite>
220//# Classes you should understand before using this one.
221// <li> <linkto class=TaQLNode>TaQLNodeResult</linkto>
222// <li> <linkto class=TaQLNode>TaQLNodeHandler</linkto>
223// <li> Note 199 describing
224// <a href="../notes/199.html">
225// TaQL</a>
226// </prerequisite>
227
228// <synopsis>
229// TaQLNodeHRValue is a specialization of class
230// <linkto class=TaQLNodeResultRep>TaQLNodeResultRep</linkto>.
231// It contains the values resulting from handling a particular node.
232// The object is effectively a collection of all possible values that
233// need to be returned. Which values are filled in, depends on which node
234// has been processed.
235// <note> The getHR function in TaQLNodeHandler is very useful to
236// extract/cast the TaQLNodeHRValue object from the general
237// TaQLNodeResult object.
238// </note>
239// </synopsis>
240
242{
243public:
245 : itsInt(-1), itsElem(0), itsSet(0), itsNames(0) {}
247 : itsInt(-1), itsExpr(expr), itsElem(0), itsSet(0), itsNames(0) {}
249
250 // Get the values.
251 // <group>
252 Int getInt() const
253 { return itsInt; }
254 const String& getString() const
255 { return itsString; }
256 const String& getAlias() const
257 { return itsAlias; }
258 const String& getNameMask() const
259 { return itsNameMask; }
260 const String& getDtype() const
261 { return itsDtype; }
262 const Record& getRecord() const
263 { return itsRecord; }
265 { return itsVH; }
266 const Table& getTable() const
267 { return itsTable; }
268 const TableExprNode& getExpr() const
269 { return itsExpr; }
271 { return itsElem; }
273 { return *itsSet; }
275 { return itsNames; }
276 // </group>
277
278 // Set the values.
279 // If a pointer is given, it takes over the pointer.
280 // <group>
281 void setInt (Int ival)
282 { itsInt = ival; }
283 void setString (const String& str)
284 { itsString = str; }
285 void setAlias (const String& alias)
286 { itsAlias = alias; }
287 void setNameMask (const String& nameMask)
288 { itsNameMask = nameMask; }
289 void setDtype (const String& dtype)
290 { itsDtype = dtype; }
291 void setRecord (const Record& record)
292 { itsRecord = record; }
294 { itsVH = vh; }
295 void setTable (const Table& table)
296 { itsTable = table; }
297 void setExpr (const TableExprNode& expr)
298 { itsExpr = expr; }
300 { itsElem = elem; }
302 { itsSet = set; }
304 { itsNames = names; }
305 // </group>
306
307private:
320};
321
322
323//# This function can only be implemented after TaQLNodeHRBase is declared.
325{
326 return *(TaQLNodeHRValue*)(res.getRep());
327}
328
329
330
331} //# NAMESPACE CASACORE - END
332
333#endif
String: the storage and methods of handling collections of characters.
Definition: String.h:225
Raw TaQL parse tree node defining an alter table add column command.
Definition: TaQLNodeDer.h:1168
Raw TaQL parse tree node defining an alter table add rows command.
Definition: TaQLNodeDer.h:1251
Raw TaQL parse tree node defining an alter table command.
Definition: TaQLNodeDer.h:1137
Raw TaQL parse tree node defining a binary operator.
Definition: TaQLNodeDer.h:192
Raw TaQL parse tree node defining a calc command.
Definition: TaQLNodeDer.h:974
Raw TaQL parse tree node defining a select column expression.
Definition: TaQLNodeDer.h:481
Raw TaQL parse tree node defining a create column specification.
Definition: TaQLNodeDer.h:1044
Raw TaQL parse tree node defining a select column list.
Definition: TaQLNodeDer.h:513
Raw TaQL parse tree node defining an alter table command.
Definition: TaQLNodeDer.h:1278
Raw TaQL parse tree node defining an alter table copy column command.
Definition: TaQLNodeDer.h:1336
Raw TaQL parse tree node defining a count command.
Definition: TaQLNodeDer.h:836
Raw TaQL parse tree node defining a create table command.
Definition: TaQLNodeDer.h:1008
Raw TaQL parse tree node defining a delete command.
Definition: TaQLNodeDer.h:941
Raw TaQL parse tree node defining a DROP TABLE command.
Definition: TaQLNodeDer.h:1364
Raw TaQL parse tree node defining a function.
Definition: TaQLNodeDer.h:295
Raw TaQL parse tree node defining a giving expression list.
Definition: TaQLNodeDer.h:669
Raw TaQL parse tree node defining a groupby list.
Definition: TaQLNodeDer.h:542
Raw TaQL parse tree node defining an index in a array.
Definition: TaQLNodeDer.h:359
Raw TaQL parse tree node defining an insert command.
Definition: TaQLNodeDer.h:906
Raw TaQL parse tree node defining a join operation.
Definition: TaQLNodeDer.h:390
Raw TaQL parse tree node defining a keyword or column name.
Definition: TaQLNodeDer.h:419
Raw TaQL parse tree node defining a limit/offset expression.
Definition: TaQLNodeDer.h:640
Raw TaQL parse tree node defining a list of nodes.
Definition: TaQLNodeDer.h:248
Envelope class for a node containing a list of nodes.
Definition: TaQLNode.h:229
Class containing the result value of the handling of a TaQLNode.
void setTable(const Table &table)
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
TableExprNodeSet * itsSet
Vector< String > * itsNames
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)
const Vector< String > * getNames() const
void setInt(Int ival)
Set the values.
const Table & getTable() const
Int getInt() const
Get the values.
TableExprNodeSetElem * itsElem
const String & getAlias() const
void setNames(Vector< String > *names)
const String & getString() const
std::vector< TableParseSelect * > itsStack
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.
TableParseSelect * pushStack(TableParseSelect::CommandType)
Push a new TableParseSelect 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)
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)
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 TableParseSelect stack.
TableParseSelect * topStack() const
Get the top of the TableParseSelect stack.
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.
Definition: TaQLNodeDer.h:325
Raw TaQL parse tree node defining a record field.
Definition: TaQLNodeDer.h:1075
Raw TaQL parse tree node defining a constant regex value.
Definition: TaQLNodeDer.h:119
Raw TaQL parse tree node defining an alter table rename or drop command.
Definition: TaQLNodeDer.h:1196
Raw TaQL parse tree node defining a select command.
Definition: TaQLNodeDer.h:789
Raw TaQL parse tree node defining an alter table set keyword command.
Definition: TaQLNodeDer.h:1224
Raw TaQL parse tree node defining a show command.
Definition: TaQLNodeDer.h:1309
Raw TaQL parse tree node defining a sort key.
Definition: TaQLNodeDer.h:574
Raw TaQL parse tree node defining a sort list.
Definition: TaQLNodeDer.h:607
Raw TaQL parse tree node defining a table.
Definition: TaQLNodeDer.h:449
Raw TaQL parse tree node defining a unary operator.
Definition: TaQLNodeDer.h:155
Raw TaQL parse tree node defining a unit.
Definition: TaQLNodeDer.h:1109
Raw TaQL parse tree node defining a column update expression.
Definition: TaQLNodeDer.h:702
Raw TaQL parse tree node defining an update command.
Definition: TaQLNodeDer.h:869
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:311
Select-class for flex/bison scanner/parser for TableParse.
Definition: TableParse.h:389
this file contains all the compiler specific defines
Definition: mainpage.dox:28
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43