-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigQTest.cc
171 lines (132 loc) · 4.12 KB
/
BigQTest.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "gtest/gtest.h"
#include <iostream>
#include "ComparisonEngine.h"
#include "BigQ.h"
#include "Schema.h"
#include "Pipe.h"
#include "unistd.h"
#include "DBFile.h"
#include "pthread.h"
using namespace std;
extern "C" {
int yyparse(void); // defined in y.tab.c
}
struct params {
Pipe* pipe;
char *filename;
char *schema;
};
extern struct AndList *final;
void *producer(void *args) {
struct params *params = (struct params *)args;
Pipe *pipe = params->pipe;
FILE *tableFile = fopen(params->filename, "r");
Record temp;
Schema myschema("catalog", params->schema);
int i = 0;
while (temp.SuckNextRecord(&myschema, tableFile) == 1) {
pipe->Insert(&temp);
// cout << ++i << endl;
}
pipe->ShutDown();
pthread_exit(NULL);
return 0;
}
class BigQTest : public ::testing::Test {
protected:
FILE *tableFile;
DBFile *sortedFile;
Record temp, sortedRec;
Schema *myschema;
OrderMaker *sortorder;
Pipe *input, *output;
ComparisonEngine ceng;
};
TEST_F(BigQTest, SortOrderTest) {
tableFile = fopen("data/test.tbl", "r");
myschema = new Schema("catalog", "lineitem");
sortedFile = new DBFile();
sortedFile->Open("data/lineitemtest.bin");
sortedFile->MoveFirst();
sortorder = new OrderMaker(myschema);
input = new Pipe(100);
output = new Pipe(100);
int counter = 0;
while (temp.SuckNextRecord(myschema, tableFile) == 1) {
input->Insert(&temp);
counter++;
}
input->ShutDown();
BigQ *bq = new BigQ(*input, *output, *sortorder, 1);
counter = 0;
while (output->Remove(&temp) && sortedFile->GetNext(sortedRec)) {
counter++;
EXPECT_EQ(0, ceng.Compare(&temp, &sortedRec, sortorder));
}
}
// File is larger than runlen
TEST_F(BigQTest, SortSingleAttTest){
myschema = new Schema("catalog", "lineitem");
sortorder = new OrderMaker;
input = new Pipe(100);
output = new Pipe(100);
sortedFile = new DBFile();
sortedFile->Open("data/lineitem.bin.bigq");
sortedFile->MoveFirst();
cout << "Enter CNF (l_shipdate) AND (l_extendedprice) AND (l_quantity) (Press Ctrl+D when done)" << endl;
if (yyparse() != 0) {
cout << "Can't parse your sort CNF.\n";
exit(1);
}
struct params *params = new struct params;
params->pipe = input;
params->filename = "data/lineitem.tbl";
params->schema = "lineitem";
Record literal;
OrderMaker dummy;
CNF sort_pred;
sort_pred.GrowFromParseTree(final, myschema, literal); // constructs CNF predicate
sort_pred.GetSortOrders(*sortorder, dummy);
pthread_t thread1;
pthread_create(&thread1, NULL, producer, (void *)params);
BigQ *bq = new BigQ(*input, *output, *sortorder, 2);
int counter = 0;
while (output->Remove(&temp)&& sortedFile->GetNext(sortedRec)) {
// cout << counter++ << endl;
EXPECT_EQ(0, ceng.Compare(&temp, &sortedRec, sortorder));
}
pthread_join(bq->threadID, NULL);
}
// more runs than filelen
TEST_F(BigQTest, SortMergeTest) {
myschema = new Schema("catalog", "region");
sortorder = new OrderMaker;
input = new Pipe(100);
output = new Pipe(100);
sortedFile = new DBFile();
sortedFile->Open("data/region.bin.bigq");
sortedFile->MoveFirst();
cout << "Enter CNF (r_name) (Press Ctrl+D when done)" << endl;
if (yyparse() != 0) {
cout << "Can't parse your sort CNF.\n";
exit(1);
}
struct params *params = new struct params;
params->pipe = input;
params->filename = "data/region.tbl";
params->schema = "region";
Record literal;
CNF sort_pred;
OrderMaker dummy;
sort_pred.GrowFromParseTree(final, myschema, literal);
sort_pred.GetSortOrders(*sortorder, dummy);
pthread_t thread1;
pthread_create(&thread1, NULL, producer, (void *)params);
BigQ *bq = new BigQ(*input, *output, *sortorder, 5);
int counter = 0;
while (output->Remove(&temp)&& sortedFile->GetNext(sortedRec)) {
EXPECT_EQ(0, ceng.Compare(&temp, &sortedRec, sortorder));
}
pthread_join(thread1, NULL);
pthread_join(bq->threadID, NULL);
}