20 #include <gtest/gtest.h>
59 EXPECT_TRUE(status.
ok());
61 EXPECT_TRUE(status.ok());
66 EXPECT_TRUE(status.ok());
68 EXPECT_TRUE(status.ok());
79 *
reinterpret_cast<int32_t*
>(tuple_mem) = val;
98 while (iter != table->
End()) {
100 int32_t val = *
reinterpret_cast<int32_t*
>(
build_expr_ctxs_[0]->GetValue(row));
103 if (all_unique) EXPECT_TRUE(results[val] == NULL);
113 EXPECT_TRUE(probe_row != build_row);
118 EXPECT_EQ(build_val, probe_val);
127 for (
int i = 0; i < num_data; ++i) {
131 iter = table->
Find(row);
133 if (data[i].expected_build_rows.size() == 0) {
134 EXPECT_TRUE(iter == table->
End());
137 map<TupleRow*, bool> matched;
138 while (iter != table->
End()) {
139 EXPECT_TRUE(matched.find(iter.
GetRow()) == matched.end());
140 matched[iter.
GetRow()] =
true;
145 EXPECT_TRUE(matched[data[i].expected_build_rows[j]]);
148 EXPECT_EQ(data[i].expected_build_rows.size(), 1);
150 data[i].expected_build_rows[0]->GetTuple(0) == iter.
GetRow()->
GetTuple(0));
159 TupleRow* build_row1 = CreateTupleRow(1);
160 TupleRow* build_row2 = CreateTupleRow(2);
161 TupleRow* probe_row3 = CreateTupleRow(3);
162 TupleRow* probe_row4 = CreateTupleRow(4);
165 reinterpret_cast<int32_t*
>(build_expr_ctxs_[0]->GetValue(build_row1));
166 EXPECT_EQ(*val_row1, 1);
168 reinterpret_cast<int32_t*
>(build_expr_ctxs_[0]->GetValue(build_row2));
169 EXPECT_EQ(*val_row2, 2);
171 reinterpret_cast<int32_t*
>(probe_expr_ctxs_[0]->GetValue(probe_row3));
172 EXPECT_EQ(*val_row3, 3);
174 reinterpret_cast<int32_t*
>(probe_expr_ctxs_[0]->GetValue(probe_row4));
175 EXPECT_EQ(*val_row4, 4);
187 for (
int i = 0; i < 5; ++i) {
188 build_rows[i] = CreateTupleRow(i);
191 ProbeTestData probe_rows[10];
192 for (
int i = 0; i < 10; ++i) {
193 probe_rows[i].probe_row = CreateTupleRow(i);
195 probe_rows[i].expected_build_rows.push_back(build_rows[i]);
201 OldHashTable hash_table(NULL, build_expr_ctxs_, probe_expr_ctxs_,
202 1,
false,
false, 0, &tracker);
203 for (
int i = 0; i < 5; ++i) {
204 hash_table.
Insert(build_rows[i]);
206 EXPECT_EQ(hash_table.
size(), 5);
209 FullScan(&hash_table, 0, 5,
true, scan_rows, build_rows);
210 ProbeTest(&hash_table, probe_rows, 10,
false);
213 ResizeTable(&hash_table, 64);
215 EXPECT_EQ(hash_table.
size(), 5);
216 memset(scan_rows, 0,
sizeof(scan_rows));
217 FullScan(&hash_table, 0, 5,
true, scan_rows, build_rows);
218 ProbeTest(&hash_table, probe_rows, 10,
false);
221 ResizeTable(&hash_table, 2);
223 EXPECT_EQ(hash_table.
size(), 5);
224 memset(scan_rows, 0,
sizeof(scan_rows));
225 FullScan(&hash_table, 0, 5,
true, scan_rows, build_rows);
226 ProbeTest(&hash_table, probe_rows, 10,
false);
229 ResizeTable(&hash_table, 1);
231 EXPECT_EQ(hash_table.
size(), 5);
232 memset(scan_rows, 0,
sizeof(scan_rows));
233 FullScan(&hash_table, 0, 5,
true, scan_rows, build_rows);
234 ProbeTest(&hash_table, probe_rows, 10,
false);
243 OldHashTable hash_table(NULL, build_expr_ctxs_, probe_expr_ctxs_,
244 1,
false,
false, 0, &tracker);
246 vector<TupleRow*> build_rows;
247 ProbeTestData probe_rows[15];
248 probe_rows[0].probe_row = CreateTupleRow(0);
249 for (
int val = 1; val <= 10; ++val) {
250 probe_rows[val].probe_row = CreateTupleRow(val);
251 for (
int i = 0; i < val; ++i) {
252 TupleRow* row = CreateTupleRow(val);
254 build_rows.push_back(row);
255 probe_rows[val].expected_build_rows.push_back(row);
260 for (
int val = 11; val < 15; ++val) {
261 probe_rows[val].probe_row = CreateTupleRow(val);
265 ProbeTest(&hash_table, probe_rows, 15,
true);
268 ResizeTable(&hash_table, 128);
270 ProbeTest(&hash_table, probe_rows, 15,
true);
272 ResizeTable(&hash_table, 16);
274 ProbeTest(&hash_table, probe_rows, 15,
true);
276 ResizeTable(&hash_table, 2);
278 ProbeTest(&hash_table, probe_rows, 15,
true);
287 int expected_size = 0;
289 OldHashTable hash_table(NULL, build_expr_ctxs_, probe_expr_ctxs_,
290 1,
false,
false, 0, &tracker,
false, num_to_add);
295 int build_row_val = 0;
296 for (
int i = 0; i < 20; ++i) {
297 for (
int j = 0; j < num_to_add; ++build_row_val, ++j) {
298 hash_table.
Insert(CreateTupleRow(build_row_val));
300 expected_size += num_to_add;
307 for (
int i = 0; i < expected_size * 5; i += 100000) {
308 TupleRow* probe_row = CreateTupleRow(i);
310 if (i < hash_table.
size()) {
311 EXPECT_TRUE(iter != hash_table.
End());
312 ValidateMatch(probe_row, iter.
GetRow());
314 EXPECT_TRUE(iter == hash_table.
End());
323 int main(
int argc,
char** argv) {
324 ::testing::InitGoogleTest(&argc, argv);
326 return RUN_ALL_TESTS();
stl-like iterator interface.
TupleRow * CreateTupleRow(int32_t val)
TEST_F(InstructionCounterTest, Count)
Tuple * GetTuple(int tuple_idx)
void ProbeTest(OldHashTable *table, ProbeTestData *data, int num_data, bool scan)
static Status Open(const std::vector< ExprContext * > &ctxs, RuntimeState *state)
Convenience function for opening multiple expr trees.
A tuple with 0 materialised slots is represented as NULL.
vector< ExprContext * > build_expr_ctxs_
void FullScan(OldHashTable *table, int min, int max, bool all_unique, TupleRow **results, TupleRow **expected)
static Tuple * Create(int size, MemPool *pool)
initialize individual tuple with data residing in mem pool
int64_t size() const
Returns number of elements in the hash table.
int main(int argc, char **argv)
static void Close(const std::vector< ExprContext * > &ctxs, RuntimeState *state)
Convenience function for closing multiple expr trees.
bool mem_limit_exceeded() const
void ResizeTable(OldHashTable *table, int64_t new_size)
void ValidateMatch(TupleRow *probe_row, TupleRow *build_row)
The hash table does not support removes. The hash table is not thread safe.
This is the superclass of all expr evaluation nodes.
bool IR_ALWAYS_INLINE Insert(TupleRow *row)
This class is thread-safe.
Iterator End()
Returns end marker.
void IR_ALWAYS_INLINE Next()
void Close()
Call to cleanup any resources. Must be called once.
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void ResizeBuckets(int64_t num_buckets)
Resize the hash table to 'num_buckets'.
void SetTuple(int tuple_idx, Tuple *tuple)
Iterator IR_ALWAYS_INLINE Find(TupleRow *probe_row)
Reference to a single slot of a tuple.
vector< TupleRow * > expected_build_rows
static void Init()
Initialize CpuInfo.
static Status Prepare(const std::vector< ExprContext * > &ctxs, RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
int64_t num_buckets() const
Returns the number of buckets.
vector< ExprContext * > probe_expr_ctxs_
uint8_t * Allocate(int size)