-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpf_uda_test.cc
215 lines (177 loc) · 6.12 KB
/
gpf_uda_test.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <math.h>
#include <impala_udf/uda-test-harness.h>
#include "gpf_uda.h"
using namespace impala;
using namespace impala_udf;
bool TestFirst() {
UdaTestHarness<StringVal, StringVal, StringVal> test(
FirstInit, FirstUpdate, FirstMerge, FirstSerialize, FirstFinalize
);
std::vector<StringVal> empty;
if(!test.Execute(empty, StringVal::null())) {
std::cerr << "First empty:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<StringVal> tenValues(10, StringVal("other"));
tenValues[0] = StringVal("first");
if(!test.Execute(tenValues, StringVal("first"))) {
std::cerr << "Ten values:" << test.GetErrorMsg() << std::endl;
return false;
}
return true;
}
bool TestOr() {
UdaTestHarness<BooleanVal, BooleanVal, BooleanVal> test(
OrInit, OrUpdate, OrMerge, NULL, OrFinalize
);
std::vector<BooleanVal> empty;
if(!test.Execute(empty, BooleanVal(false))) {
std::cerr << "Or empty:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BooleanVal> sample1;
sample1.push_back(BooleanVal(false));
sample1.push_back(BooleanVal(true));
sample1.push_back(BooleanVal(false));
sample1.push_back(BooleanVal(true));
if(!test.Execute(sample1, BooleanVal(true))) {
std::cerr << "Or sample1:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BooleanVal> sample2;
sample2.push_back(BooleanVal(true));
sample2.push_back(BooleanVal(false));
sample2.push_back(BooleanVal(true));
sample2.push_back(BooleanVal(false));
if(!test.Execute(sample2, BooleanVal(true))) {
std::cerr << "Or sample2:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BooleanVal> allTrue(10, BooleanVal(true));
if(!test.Execute(allTrue, BooleanVal(true))) {
std::cerr << "Or all true:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BooleanVal> allFalse(10, BooleanVal(false));
if(!test.Execute(allFalse, BooleanVal(false))) {
std::cerr << "Or all false:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BooleanVal> allNull(10, BooleanVal::null());
if(!test.Execute(allNull, BooleanVal(false))) {
std::cerr << "Or all null:" << test.GetErrorMsg() << std::endl;
return false;
}
return true;
}
bool TestOrInt() {
UdaTestHarness<BooleanVal, BooleanVal, IntVal> test(
OrIntInit, OrIntUpdate, OrIntMerge, NULL, OrIntFinalize
);
std::vector<IntVal> empty;
if(!test.Execute(empty, BooleanVal(false))) {
std::cerr << "Or empty:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<IntVal> sample1;
sample1.push_back(IntVal(0));
sample1.push_back(IntVal(1));
sample1.push_back(IntVal(0));
sample1.push_back(IntVal(1));
if(!test.Execute(sample1, BooleanVal(true))) {
std::cerr << "Or int sample1:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<IntVal> sample2;
sample2.push_back(IntVal(1));
sample2.push_back(IntVal(0));
sample2.push_back(IntVal(1));
sample2.push_back(IntVal(0));
if(!test.Execute(sample2, BooleanVal(true))) {
std::cerr << "Or int sample2:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<IntVal> sample3;
sample3.push_back(IntVal(4));
sample3.push_back(IntVal(-1));
sample3.push_back(IntVal(0));
sample3.push_back(IntVal(9));
if(!test.Execute(sample3, BooleanVal(true))) {
std::cerr << "Or int sample3:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<IntVal> allTrue(10, IntVal(1));
if(!test.Execute(allTrue, BooleanVal(true))) {
std::cerr << "Or int all true:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<IntVal> allFalse(10, IntVal(0));
if(!test.Execute(allFalse, BooleanVal(false))) {
std::cerr << "Or int all false:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<IntVal> allNull(10, IntVal::null());
if(!test.Execute(allNull, BooleanVal(false))) {
std::cerr << "Or int all null:" << test.GetErrorMsg() << std::endl;
return false;
}
return true;
}
bool TestBitOr() {
UdaTestHarness<BigIntVal, BigIntVal, BigIntVal> test(
BitOrInit, BitOrUpdate, BitOrMerge, NULL, BitOrFinalize
);
std::vector<BigIntVal> empty;
if(!test.Execute(empty, BigIntVal(false))) {
std::cerr << "BitOr empty:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BigIntVal> sample1;
sample1.push_back(BigIntVal(0));
sample1.push_back(BigIntVal(1));
sample1.push_back(BigIntVal(2));
sample1.push_back(BigIntVal(4));
if(!test.Execute(sample1, BigIntVal(7))) {
std::cerr << "Or sample1:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BigIntVal> sample2;
sample2.push_back(BigIntVal(0));
sample2.push_back(BigIntVal(1));
sample2.push_back(BigIntVal(0));
sample2.push_back(BigIntVal(4));
if(!test.Execute(sample2, BigIntVal(5))) {
std::cerr << "BitOr sample2:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BigIntVal> sample3;
sample3.push_back(BigIntVal(3));
sample3.push_back(BigIntVal(1));
sample3.push_back(BigIntVal(12));
sample3.push_back(BigIntVal(0));
if(!test.Execute(sample3, BigIntVal(15))) {
std::cerr << "BitOr sample2:" << test.GetErrorMsg() << std::endl;
return false;
}
std::vector<BigIntVal> allNull(10, BigIntVal::null());
if(!test.Execute(allNull, BigIntVal(0))) {
std::cerr << "BitOr all null:" << test.GetErrorMsg() << std::endl;
return false;
}
return true;
}
int main(int argc, char** argv) {
bool passed = true;
passed &= TestFirst();
passed &= TestOr();
passed &= TestBitOr();
passed &= TestOrInt();
std::cerr << (passed ? "Tests passed." : "Tests failed.") << std::endl;
if(passed) {
return 0;
}
else {
return -1;
}
}