-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cc
More file actions
113 lines (88 loc) · 2.43 KB
/
Copy pathtest.cc
File metadata and controls
113 lines (88 loc) · 2.43 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
109
110
111
112
113
#include <iostream>
#include "DBFile.h"
#include "test.h"
// make sure that the file path/dir information below is correct
const char *dbfile_dir = "./"; // dir where binary heap files should be stored
const char *tpch_dir ="./"; // dir where dbgen tpch files (extension *.tbl) can be found
const char *catalog_path = "catalog"; // full path of the catalog file
using namespace std;
relation *rel;
// load from a tpch file
void test1 () {
DBFile dbfile;
cout << " DBFile will be created at " << rel->path () << endl;
dbfile.Create (rel->path(), heap, NULL);
char tbl_path[100]; // construct path of the tpch flat text file
sprintf (tbl_path, "%s%s.tbl", tpch_dir, rel->name());
cout << " tpch file will be loaded from " << tbl_path << endl;
dbfile.Load (*(rel->schema ()), tbl_path);
dbfile.Close ();
}
// sequential scan of a DBfile
void test2 () {
DBFile dbfile;
dbfile.Open (rel->path());
dbfile.MoveFirst ();
Record temp;
int counter = 0;
while (dbfile.GetNext (temp) == 1) {
counter += 1;
temp.Print (rel->schema());
if (counter % 10000 == 0) {
cout << counter << "\n";
}
}
cout << " scanned " << counter << " recs \n";
dbfile.Close ();
}
// scan of a DBfile and apply a filter predicate
void test3 () {
cout << " Filter with CNF for : " << rel->name() << "\n";
CNF cnf;
Record literal;
rel->get_cnf (cnf, literal);
DBFile dbfile;
dbfile.Open (rel->path());
dbfile.MoveFirst ();
Record temp;
int counter = 0;
while (dbfile.GetNext (temp, cnf, literal) == 1) {
counter += 1;
temp.Print (rel->schema());
if (counter % 10000 == 0) {
cout << counter << "\n";
}
}
cout << " selected " << counter << " recs \n";
dbfile.Close ();
}
int main () {
setup (catalog_path, dbfile_dir, tpch_dir);
void (*test) ();
relation *rel_ptr[] = {n, r, c, p, ps, o, li};
void (*test_ptr[]) () = {&test1, &test2, &test3};
int tindx = 0;
while (tindx < 1 || tindx > 3) {
cout << " select test: \n";
cout << " \t 1. load file \n";
cout << " \t 2. scan \n";
cout << " \t 3. scan & filter \n \t ";
cin >> tindx;
}
int findx = 0;
while (findx < 1 || findx > 7) {
cout << "\n select table: \n";
cout << "\t 1. nation \n";
cout << "\t 2. region \n";
cout << "\t 3. customer \n";
cout << "\t 4. part \n";
cout << "\t 5. partsupp \n";
cout << "\t 6. orders \n";
cout << "\t 7. lineitem \n \t ";
cin >> findx;
}
rel = rel_ptr [findx - 1];
test = test_ptr [tindx - 1];
test ();
cleanup ();
}