OmniSciDB  c07336695a
GroupByHashTest.cpp File Reference
#include "RuntimeFunctions.h"
#include <gtest/gtest.h>
#include <cstdint>
#include <numeric>
+ Include dependency graph for GroupByHashTest.cpp:

Go to the source code of this file.

Classes

class  GroupsBuffer
 

Namespaces

 anonymous_namespace{GroupByHashTest.cpp}
 

Functions

void anonymous_namespace{GroupByHashTest.cpp}::init_groups (int64_t *groups_buffer, const int32_t groups_buffer_entry_count, const int32_t key_qw_count, const int64_t *init_vals)
 
 TEST (InitTest, OneKey)
 
 TEST (SetGetTest, OneKey)
 
 TEST (SetGetTest, ManyKeys)
 
 TEST (SetGetTest, OneKeyCollision)
 
 TEST (SetGetTest, OneKeyRandom)
 
 TEST (SetGetTest, MultiKeyRandom)
 
 TEST (SetGetTest, OneKeyNoCollisions)
 
 TEST (SetGetTest, OneKeyAllCollisions)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 268 of file GroupByHashTest.cpp.

268  {
269  testing::InitGoogleTest(&argc, argv);
270  return RUN_ALL_TESTS();
271 }

◆ TEST() [1/8]

TEST ( InitTest  ,
OneKey   
)

Definition at line 57 of file GroupByHashTest.cpp.

References EMPTY_KEY_64, groups_buffer_entry_count, key_qw_count, and GroupsBuffer::qw_size().

57  {
58  const int32_t groups_buffer_entry_count{10};
59  const int32_t key_qw_count{1};
61  auto gb_raw = static_cast<int64_t*>(gb);
62  for (size_t i = 0; i < gb.qw_size(); i += 2) {
63  ASSERT_EQ(gb_raw[i], EMPTY_KEY_64);
64  }
65 }
#define EMPTY_KEY_64
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
+ Here is the call graph for this function:

◆ TEST() [2/8]

TEST ( SetGetTest  ,
OneKey   
)

Definition at line 67 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

67  {
68  const int32_t groups_buffer_entry_count{10};
69  const int32_t key_qw_count{1};
70  const int32_t row_size_quad{key_qw_count + 1};
72  int64_t key = 31;
73  auto gv1 = get_group_value(
74  gb, groups_buffer_entry_count, &key, key_qw_count, sizeof(int64_t), row_size_quad);
75  ASSERT_NE(gv1, nullptr);
76  auto gv2 = get_group_value(
77  gb, groups_buffer_entry_count, &key, key_qw_count, sizeof(int64_t), row_size_quad);
78  ASSERT_EQ(gv1, gv2);
79  int64_t val = 42;
80  *gv2 = val;
81  auto gv3 = get_group_value(
82  gb, groups_buffer_entry_count, &key, key_qw_count, sizeof(int64_t), row_size_quad);
83  ASSERT_NE(gv3, nullptr);
84  ASSERT_EQ(*gv3, val);
85 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function:

◆ TEST() [3/8]

TEST ( SetGetTest  ,
ManyKeys   
)

Definition at line 87 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

87  {
88  const int32_t groups_buffer_entry_count{10};
89  const int32_t key_qw_count{5};
90  const int32_t row_size_quad{key_qw_count + 1};
92  int64_t key[] = {31, 32, 33, 34, 35};
93  auto gv1 = get_group_value(
94  gb, groups_buffer_entry_count, key, key_qw_count, sizeof(int64_t), row_size_quad);
95  ASSERT_NE(gv1, nullptr);
96  auto gv2 = get_group_value(
97  gb, groups_buffer_entry_count, key, key_qw_count, sizeof(int64_t), row_size_quad);
98  ASSERT_EQ(gv1, gv2);
99  int64_t val = 42;
100  *gv2 = val;
101  auto gv3 = get_group_value(
102  gb, groups_buffer_entry_count, key, key_qw_count, sizeof(int64_t), row_size_quad);
103  ASSERT_NE(gv3, nullptr);
104  ASSERT_EQ(*gv3, val);
105 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function:

◆ TEST() [4/8]

TEST ( SetGetTest  ,
OneKeyCollision   
)

Definition at line 107 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

107  {
108  const int32_t groups_buffer_entry_count{10};
109  const int32_t key_qw_count{1};
110  const int32_t row_size_quad{key_qw_count + 1};
112  int64_t key1 = 31;
113  auto gv1 = get_group_value(
114  gb, groups_buffer_entry_count, &key1, key_qw_count, sizeof(int64_t), row_size_quad);
115  ASSERT_NE(gv1, nullptr);
116  int64_t val1 = 32;
117  *gv1 = val1;
118  int64_t key2 = 41;
119  auto gv2 = get_group_value(
120  gb, groups_buffer_entry_count, &key2, key_qw_count, sizeof(int64_t), row_size_quad);
121  ASSERT_NE(gv2, nullptr);
122  int64_t val2 = 42;
123  *gv2 = val2;
124  gv1 = get_group_value(
125  gb, groups_buffer_entry_count, &key1, key_qw_count, sizeof(int64_t), row_size_quad);
126  ASSERT_NE(gv1, nullptr);
127  ASSERT_EQ(*gv1, val1);
128  gv2 = get_group_value(
129  gb, groups_buffer_entry_count, &key2, key_qw_count, sizeof(int64_t), row_size_quad);
130  ASSERT_NE(gv2, nullptr);
131  ASSERT_EQ(*gv2, val2);
132 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function:

◆ TEST() [5/8]

TEST ( SetGetTest  ,
OneKeyRandom   
)

Definition at line 134 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

134  {
135  const int32_t groups_buffer_entry_count{10};
136  const int32_t key_qw_count{1};
137  const int32_t row_size_quad{key_qw_count + 1};
139  std::vector<int64_t> keys;
140  for (int32_t i = 0; i < groups_buffer_entry_count; ++i) {
141  int64_t key = rand() % 1000;
142  keys.push_back(key);
143  auto gv = get_group_value(gb,
144  groups_buffer_entry_count,
145  &key,
146  key_qw_count,
147  sizeof(int64_t),
148  row_size_quad);
149  ASSERT_NE(gv, nullptr);
150  *gv = key + 100;
151  }
152  for (const auto key : keys) {
153  auto gv = get_group_value(gb,
154  groups_buffer_entry_count,
155  &key,
156  key_qw_count,
157  sizeof(int64_t),
158  row_size_quad);
159  ASSERT_NE(gv, nullptr);
160  ASSERT_EQ(*gv, key + 100);
161  }
162 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function:

◆ TEST() [6/8]

TEST ( SetGetTest  ,
MultiKeyRandom   
)

Definition at line 164 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

164  {
165  const int32_t groups_buffer_entry_count{10};
166  const int32_t key_qw_count{5};
167  const int32_t row_size_quad{key_qw_count + 1};
169  std::vector<std::vector<int64_t>> keys;
170  for (int32_t i = 0; i < groups_buffer_entry_count; ++i) {
171  std::vector<int64_t> key;
172  for (int32_t i = 0; i < key_qw_count; ++i) {
173  key.push_back(rand() % 1000);
174  }
175  keys.push_back(key);
176  auto gv = get_group_value(gb,
177  groups_buffer_entry_count,
178  &key[0],
179  key_qw_count,
180  sizeof(int64_t),
181  row_size_quad);
182  ASSERT_NE(gv, nullptr);
183  *gv = std::accumulate(
184  key.begin(), key.end(), 100, [](int64_t x, int64_t y) { return x + y; });
185  }
186  for (const auto key : keys) {
187  auto gv = get_group_value(gb,
188  groups_buffer_entry_count,
189  &key[0],
190  key_qw_count,
191  sizeof(int64_t),
192  row_size_quad);
193  ASSERT_NE(gv, nullptr);
194  ASSERT_EQ(*gv, std::accumulate(key.begin(), key.end(), 100, [](int64_t x, int64_t y) {
195  return x + y;
196  }));
197  }
198 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function:

◆ TEST() [7/8]

TEST ( SetGetTest  ,
OneKeyNoCollisions   
)

Definition at line 200 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

200  {
201  const int32_t groups_buffer_entry_count{10};
202  const int32_t key_qw_count{1};
203  const int32_t row_size_quad{key_qw_count + 1};
205  int64_t key_start = 31;
206  for (int32_t i = 0; i < groups_buffer_entry_count; ++i) {
207  int64_t key = key_start + i;
208  auto gv = get_group_value(gb,
209  groups_buffer_entry_count,
210  &key,
211  key_qw_count,
212  sizeof(int64_t),
213  row_size_quad);
214  ASSERT_NE(gv, nullptr);
215  *gv = key + 100;
216  }
217  for (int32_t i = 0; i < groups_buffer_entry_count; ++i) {
218  int64_t key = key_start + i;
219  auto gv = get_group_value(gb,
220  groups_buffer_entry_count,
221  &key,
222  key_qw_count,
223  sizeof(int64_t),
224  row_size_quad);
225  ASSERT_NE(gv, nullptr);
226  ASSERT_EQ(*gv, key + 100);
227  }
228  int64_t key = key_start + groups_buffer_entry_count;
229  auto gv = get_group_value(
230  gb, groups_buffer_entry_count, &key, key_qw_count, sizeof(int64_t), row_size_quad);
231  ASSERT_EQ(gv, nullptr);
232 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function:

◆ TEST() [8/8]

TEST ( SetGetTest  ,
OneKeyAllCollisions   
)

Definition at line 234 of file GroupByHashTest.cpp.

References get_group_value(), groups_buffer_entry_count, and key_qw_count.

234  {
235  const int32_t groups_buffer_entry_count{10};
236  const int32_t key_qw_count{1};
237  const int32_t row_size_quad{key_qw_count + 1};
239  int64_t key_start = 31;
240  for (int32_t i = 0; i < groups_buffer_entry_count; ++i) {
241  int64_t key = key_start + groups_buffer_entry_count * i;
242  auto gv = get_group_value(gb,
243  groups_buffer_entry_count,
244  &key,
245  key_qw_count,
246  sizeof(int64_t),
247  row_size_quad);
248  ASSERT_NE(gv, nullptr);
249  *gv = key + 100;
250  }
251  for (int32_t i = 0; i < groups_buffer_entry_count; ++i) {
252  int64_t key = key_start + groups_buffer_entry_count * i;
253  auto gv = get_group_value(gb,
254  groups_buffer_entry_count,
255  &key,
256  key_qw_count,
257  sizeof(int64_t),
258  row_size_quad);
259  ASSERT_NE(gv, nullptr);
260  ASSERT_EQ(*gv, key + 100);
261  }
262  int64_t key = key_start + groups_buffer_entry_count * groups_buffer_entry_count;
263  auto gv = get_group_value(
264  gb, groups_buffer_entry_count, &key, key_qw_count, sizeof(int64_t), row_size_quad);
265  ASSERT_EQ(gv, nullptr);
266 }
const int64_t const uint32_t groups_buffer_entry_count
const int64_t const uint32_t const uint32_t key_qw_count
NEVER_INLINE DEVICE int64_t * get_group_value(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const uint32_t key_width, const uint32_t row_size_quad, const int64_t *init_vals)
+ Here is the call graph for this function: