-
Notifications
You must be signed in to change notification settings - Fork 0
/
a1-test.h
93 lines (76 loc) · 2.51 KB
/
a1-test.h
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
#ifndef TEST_H
#define TEST_H
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "DBFile.h"
#include "Record.h"
#include "Schema.h"
using namespace std;
extern "C" {
int yyparse(void); // defined in y.tab.c
}
extern struct AndList *final;
class relation {
private:
const char *rname;
const char *prefix;
char rpath[100];
Schema *rschema;
public:
relation(const char *_name, Schema *_schema, const char *_prefix) :
rname(_name), rschema(_schema), prefix(_prefix) {
sprintf(rpath, "%s%s.bin", prefix, rname);
}
const char *name() { return rname; }
const char *path() { return rpath; }
Schema *schema() { return rschema; }
void info() {
cout << " relation info\n";
cout << "\t name: " << name() << endl;
cout << "\t path: " << path() << endl;
}
void get_cnf(CNF &cnf_pred, Record &literal) {
cout << " Enter CNF predicate (when done press ctrl-D):\n\t";
if (yyparse() != 0) {
std::cout << "Can't parse your CNF.\n";
exit(1);
}
cnf_pred.GrowFromParseTree(final, schema(), literal); // constructs CNF predicate
}
};
char *supplier = "supplier";
char *partsupp = "partsupp";
char *part = "part";
char *nation = "nation";
char *customer = "customer";
char *orders = "orders";
char *region = "region";
char *lineitem = "lineitem";
relation *s, *p, *ps, *n, *li, *r, *o, *c;
void setup(char *catalog_path, const char *dbfile_dir, const char *tpch_dir) {
cout << " \n** IMPORTANT: MAKE SURE THE INFORMATION BELOW IS CORRECT **\n";
cout << " catalog location: \t" << catalog_path << endl;
cout << " tpch files dir: \t" << tpch_dir << endl;
cout << " heap files dir: \t" << dbfile_dir << endl;
cout << " \n\n";
s = new relation(supplier, new Schema(catalog_path, supplier), dbfile_dir);
ps = new relation(partsupp, new Schema(catalog_path, partsupp), dbfile_dir);
p = new relation(part, new Schema(catalog_path, part), dbfile_dir);
n = new relation(nation, new Schema(catalog_path, nation), dbfile_dir);
li = new relation(lineitem, new Schema(catalog_path, lineitem), dbfile_dir);
r = new relation(region, new Schema(catalog_path, region), dbfile_dir);
o = new relation(orders, new Schema(catalog_path, orders), dbfile_dir);
c = new relation(customer, new Schema(catalog_path, customer), dbfile_dir);
}
void cleanup() {
delete s;
delete p;
delete ps;
delete n;
delete li;
delete r;
delete o;
delete c;
}
#endif