rasdaman complete source
querytree.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 */
23 #ifndef _QUERYTREE_
24 #define _QUERYTREE_
25 
26 #ifndef CPPSTDLIB
27 #include <ospace/string.h> // STL<ToolKit>
28 #else
29 #include <string>
30 #endif
31 #include <algorithm>
32 
33 #include "mddmgr/mddcoll.hh"
34 
35 #include "qlparser/qtnode.hh"
36 #include "qlparser/qtatomicdata.hh"
38 #include "qlparser/qtconst.hh"
40 #include "qlparser/qtmarrayop2.hh"
41 #include "qlparser/qtpointop.hh"
42 #include "qlparser/symtab.hh"
43 
44 // forward declarations
45 class MDDObj;
46 class QtONCStream;
47 class QtDomainOperation;
48 
49 
50 /*************************************************************
51  *
52  *
53  * INCLUDE: querytree.hh
54  *
55  * MODULE: qlparser
56  * CLASS: QueryTree
57  *
58  * COMMENTS:
59  *
60  ************************************************************/
61 
62 //@ManMemo: Module: {\bf qlparser}
63 
64 /*@Doc:
65 
66 The Query Tree is the internal representation of a RasML query string. It
67 consists of instances of the above class hierarchy. The tree is created in
68 the Query Parser Modul in the action sections of the yacc grammar. According
69 to the parser semantics, the tree is built bottom up which means that the leaf
70 objects are created first. They are given up via the parse stack. Inner objects
71 get references to the subobjects after they are created. The whole tree is a
72 dynamic data structure. The semantics is that if an object is deleted also its
73 subobjects are deleted which means that the deletion of the root object cleans
74 up the whole tree.
75 
76 The class QueryTree encapsulates a query tree consisting of suclasses of type
77 QtNode. It consists of the entry point and methods working on the whole tree
78 (e.g. traversing).
79 
80 */
81 
82 class QueryTree
83 {
84 public:
85 
86 
88  {
93  };
94 
96  QueryTree();
97 
99  QueryTree( QtNode* root );
100 
102  ~QueryTree();
103 
105  void checkSemantics();
106 
108  vector<QtNode::QtNodeList>* seeSubexpression();
109 
110  /*@Doc:
111  The method returns a list of all common subexpressions in the query tree.
112  The private methods seeSubexpression(..) are used.
113  */
114 
116  void insertSubexpression( vector<QtNode::QtNodeList>* nodeList );
117 
118  /*@Doc:
119  The method manipulates the query tree to handle common subexpressions.
120  */
121 
123  vector<QtData*>* evaluateRetrieval() throw (r_Error, ParseInfo);
124 
125  /*@Doc:
126  The method evaluates a retrieval tree and returns the result collection. For this purpose,
127  first, the {\tt open()} message is sent to the root node of the tree. Then {\tt next()}
128  is invoked on the root node which, each time, returns one element of the result
129  collection. It indicates the end of the evaluation process through returning a null pointer.
130  At the end, {\tt close()} is called to clean up the ressources. If errors occur, various exceptions
131  are thrown.
132  */
133 
135  void evaluateUpdate() throw (r_Error,ParseInfo);
136 
138  void printTree( int tab, ostream& s = cout );
139 
140  //@Man: read/write methods
142 
145  inline QtNode* getRoot() const;
147  inline void setRoot( QtNode* root );
148 
150 
151 
152  //@Man: methods used to maintain pointers to dynamic data structures used in the parse process
154 
157  void addDynamicObject( QtNode* );
159  void removeDynamicObject( QtNode* );
161  void addDynamicObject( QtData* );
163  void removeDynamicObject( QtData* );
165  void addDynamicObject( ParseInfo* );
167  void removeDynamicObject( ParseInfo* );
169  void addDynamicObject( vector<QtONCStream*>* );
171  void removeDynamicObject( vector<QtONCStream*>* );
173  void releaseDynamicObjects();
177  void removeDomainObject( QtDomainOperation * );
179  void rewriteDomainObjects(r_Minterval *greatDomain, std::string *greatIterator, QtMarrayOp2::mddIntervalListType *greatList);
181  void printDomainObjects();
183  void releaseDomainObjects();
185  void addCString( char * );
187 
188 
190  static SymbolTable<int> symtab;
191 
192 private:
194  QtNode* rootNode;
195 
197  vector<QtNode::QtNodeList>* seeSubexpression( QtNode::QtNodeList* leafList );
198 
200  QtNode::QtNodeList* seeSubexpression( QtNode::QtNodeList* leafList, vector<QtNode::QtNodeList>* leafListsNew );
201 
203  static unsigned int nextCSENo;
204 
206  std::list<QtNode*> qtNodeList;
213  std::list<QtData*> qtDataList;
221  std::list<ParseInfo*> parseInfoList;
229  std::list<vector<QtONCStream*>*> vectorList;
237  std::list<QtDomainOperation *> dopList; // contains basically QtDomainOperation (everything else is evil :-) )
245  std::list<char *> lexedCStringList;
252 };
253 
254 #include "querytree.icc"
255 
256 #endif
257 
void rewriteDomainObjects(r_Minterval *greatDomain, std::string *greatIterator, QtMarrayOp2::mddIntervalListType *greatList)
void releaseDomainObjects()
void addDomainObject(QtDomainOperation *)
void addCString(char *)
Definition: qtmarrayop2.hh:57
Definition: parseinfo.hh:51
Definition: qtdata.hh:83
void evaluateUpdate()
executes an update tree and throws a ParseInfo if query does not begin with INSERT, DELETE, UPDATE, ...
void removeDynamicObject(QtNode *)
Definition: symtab.hh:56
void setRoot(QtNode *root)
QueryTree()
default constructor
Definition: qtdomainoperation.hh:53
Definition: querytree.hh:82
Definition: querytree.hh:89
vector< QtNode::QtNodeList > * seeSubexpression()
recognize common subexpressions
Definition: qtoncstream.hh:54
OptimizationLevel
Definition: querytree.hh:87
void removeDomainObject(QtDomainOperation *)
Definition: querytree.hh:92
void addDynamicObject(QtNode *)
Definition: qtnode.hh:73
void printTree(int tab, ostream &s=cout)
debugging method
Definition: querytree.hh:90
QtNode * getRoot() const
void checkSemantics()
checks semantics (e.g., type checking)
void releaseDynamicObjects()
Definition: querytree.hh:91
void printDomainObjects()
static SymbolTable< int > symtab
Definition: querytree.hh:190
~QueryTree()
destructor (deletes the whole query tree)
void insertSubexpression(vector< QtNode::QtNodeList > *nodeList)
build in common subexpressions in the query tree
vector< QtData * > * evaluateRetrieval()
executes a retrieval tree and gives back the result collection