-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
69 lines (51 loc) · 1.79 KB
/
main.cc
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
#include <iostream>
#include <string>
#include "Catalog.h"
#include "QueryParser.h"
#include "QueryOptimizer.h"
#include "QueryCompiler.h"
#include "RelOp.h"
using namespace std;
// these data structures hold the result of the parsing
extern struct FuncOperator* finalFunction; // the aggregate function
extern struct TableList* tables; // the list of tables in the query
extern struct AndList* predicate; // the predicate in WHERE
extern struct NameList* groupingAtts; // grouping attributes
extern struct NameList* attsToSelect; // the attributes in SELECT
extern int distinctAtts; // 1 if there is a DISTINCT in a non-aggregate query
extern "C" int yyparse();
extern "C" int yylex_destroy();
int main () {
// this is the catalog
string dbFile = "catalog.sqlite";
Catalog catalog(dbFile);
//catalog.HeapFile("");
// this is the query optimizer
// it is not invoked directly but rather passed to the query compiler
QueryOptimizer optimizer(catalog);
// this is the query compiler
// it includes the catalog and the query optimizer
QueryCompiler compiler(catalog, optimizer);
// the query parser is accessed directly through yyparse
// this populates the extern data structures
int parse = -1;
if (yyparse () == 0) {
cout << "OK!" << endl;
parse = 0;
}
else {
cout << "Error: Query is not correct!" << endl;
parse = -1;
}
yylex_destroy();
if (parse != 0) return -1;
// at this point we have the parse tree in the ParseTree data structures
// we are ready to invoke the query compiler with the given query
// the result is the execution tree built from the parse tree and optimized
QueryExecutionTree queryTree;
compiler.Compile(tables, attsToSelect, finalFunction, predicate,
groupingAtts, distinctAtts, queryTree);
cout << queryTree << endl;
queryTree.ExecuteQuery();
return 0;
}