-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathparsequery.cpp
More file actions
109 lines (88 loc) · 2.97 KB
/
parsequery.cpp
File metadata and controls
109 lines (88 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Copyright (C) 2013 Calpont Corp.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include <unistd.h>
#include <string>
#include <memory>
using namespace std;
#include <boost/thread/mutex.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
using namespace boost;
#include "cseputils.h"
#include "parsequery.h"
#include "calpontselectexecutionplan.h"
#include "simplecolumn.h"
#include "simplefilter.h"
#include "constantcolumn.h"
#include "calpontsystemcatalog.h"
#include "sessionmanager.h"
using namespace execplan;
#include "brmtypes.h"
using namespace BRM;
extern int qfeparse();
extern int qfedebug;
struct yy_buffer_state;
extern yy_buffer_state* qfe_scan_string(const char*);
extern void qfe_delete_buffer(yy_buffer_state*);
extern CalpontSelectExecutionPlan* ParserCSEP;
extern shared_ptr<CalpontSystemCatalog> ParserCSC;
namespace
{
mutex ParserMutex;
} //anon namespace
namespace qfe
{
extern string DefaultSchema;
CalpontSelectExecutionPlan* parseQuery(const string& query, const uint32_t sid)
{
//We're going to make parsing the query single-threaded for now. This makes it a lot
// easier to interface with the parser and doesn;t materially affect overall query
// performance (I think)
mutex::scoped_lock lk(ParserMutex);
shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sid);
CalpontSelectExecutionPlan* csep=0;
csep = new CalpontSelectExecutionPlan();
//we use an auto_ptr here with some trepidation. We only want auto delete on an execption.
//If the parseing and plan build succeed, we want the ptr to stay around. boost::scoped_ptr<>
//doesn't have an API to release ownership, so we use auto_ptr...
auto_ptr<CalpontSelectExecutionPlan> scsep(csep);
yy_buffer_state* ybs=0;
ybs = qfe_scan_string(query.c_str());
if (ybs != 0)
{
ParserCSEP = csep;
ParserCSC = csc;
if (qfeparse() != 0)
throw runtime_error("syntax error");
qfe_delete_buffer(ybs);
}
else
throw runtime_error("Internal parser memory error");
csep->data(query);
SessionManager sm;
TxnID txnID;
txnID = sm.getTxnID(sid);
if (!txnID.valid)
{
txnID.id = 0;
txnID.valid = true;
}
QueryContext verID;
verID = sm.verID();
csep->txnID(txnID.id);
csep->verID(verID);
csep->sessionID(sid);
//cout << *csep << endl;
scsep.release();
return csep;
}
}