OmniSciDB  04ee39c94c
ResultSetTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
24 #include "ResultSetTestUtils.h"
25 
26 #include "../QueryEngine/Descriptors/RowSetMemoryOwner.h"
27 #include "../QueryEngine/ResultSet.h"
28 #include "../QueryEngine/ResultSetReductionJIT.h"
29 #include "../QueryEngine/RuntimeFunctions.h"
30 #include "../StringDictionary/StringDictionary.h"
31 #include "TestHelpers.h"
32 
33 #include <gtest/gtest.h>
34 
35 #include <algorithm>
36 #include <queue>
37 #include <random>
38 
39 TEST(Construct, Allocate) {
40  std::vector<TargetInfo> target_infos;
41  QueryMemoryDescriptor query_mem_desc;
42  ResultSet result_set(target_infos,
44  query_mem_desc,
45  std::make_shared<RowSetMemoryOwner>(),
46  nullptr);
47  result_set.allocateStorage();
48 }
49 
50 namespace {
51 
52 using OneRow = std::vector<TargetValue>;
53 
54 /* This class allows to emulate and evaluate ResultSet and it's reduce function.
55  * It creates two ResultSet equivalents, populates them with randomly generated data,
56  * merges them into one, and provides access to the data contained in the merged set.
57  * Comparing these data with the ones received from the ResultSet code reduce procedure
58  * run on the same pair of the ResultSet equivalents, allows to evaluate the functionality
59  * of the ResultSet code.
60  */
62  public:
63  ResultSetEmulator(int8_t* buff1,
64  int8_t* buff2,
65  const std::vector<TargetInfo>& target_infos,
66  const QueryMemoryDescriptor& query_mem_desc,
67  NumberGenerator& gen1,
68  NumberGenerator& gen2,
69  const size_t perc1,
70  const size_t perc2,
71  const size_t flow,
72  const bool silent)
73  :
74 
75  rs1_buff(buff1)
76  , rs2_buff(buff2)
77  , rs_target_infos(target_infos)
78  , rs_query_mem_desc(query_mem_desc)
79  , rs1_gen(gen1)
80  , rs2_gen(gen2)
81  , rs1_perc(perc1)
82  , rs2_perc(perc2)
83  , rs_flow(flow)
84  , rs_entry_count(query_mem_desc.getEntryCount())
85  , rs_silent(silent) {
86  rs_entry_count =
87  query_mem_desc.getEntryCount(); // it's set to 10 in "small" query_mem_descriptor
88  rs1_groups.resize(rs_entry_count);
89  std::fill(rs1_groups.begin(), rs1_groups.end(), false);
90  rs2_groups.resize(rs_entry_count);
91  std::fill(rs2_groups.begin(), rs2_groups.end(), false);
92  rs1_values.resize(rs_entry_count);
93  std::fill(rs1_values.begin(), rs1_values.end(), 0);
94  rs2_values.resize(rs_entry_count);
95  std::fill(rs2_values.begin(), rs2_values.end(), 0);
96  rseReducedGroups.resize(rs_entry_count);
97  std::fill(rseReducedGroups.begin(), rseReducedGroups.end(), false);
98 
99  emulateResultSets();
100  }
102 
103  std::queue<std::vector<int64_t>> getReferenceTable() const { return rseReducedTable; }
104  std::vector<bool> getReferenceGroupMap() const { return rseReducedGroups; }
105  bool getReferenceGroupMapElement(size_t idx) {
106  CHECK_LE(idx, rseReducedGroups.size() - 1);
107  return rseReducedGroups[idx];
108  }
109  std::vector<int64_t> getReferenceRow(bool keep_row = false) {
110  std::vector<int64_t> rse_reduced_row(rseReducedTable.front());
111  rseReducedTable.pop();
112  if (keep_row) {
113  rseReducedTable.push(rse_reduced_row);
114  }
115  return rse_reduced_row;
116  }
117  int64_t rse_get_null_val() {
118  int64_t null_val = 0;
119  for (const auto& target_info : rs_target_infos) {
120  null_val = inline_int_null_val(target_info.sql_type);
121  break; // currently all of TargetInfo's columns used in tests have same type, so
122  // the they all share same null_val, and that's why the first column is used
123  // here.
124  }
125  return null_val;
126  }
127  void print_rse_generated_result_sets() const;
128  void print_merged_result_sets(const std::vector<OneRow>& result);
129 
130  private:
131  void emulateResultSets();
132  void createResultSet(size_t rs_perc, std::vector<bool>& rs_groups);
133  void mergeResultSets();
134  int8_t *rs1_buff, *rs2_buff;
135  const std::vector<TargetInfo> rs_target_infos;
138  size_t rs1_perc, rs2_perc, rs_flow;
140  bool rs_silent;
141  std::vector<bool> rs1_groups; // true if group is in ResultSet #1
142  std::vector<bool> rs2_groups; // true if group is in ResultSet #2
143  std::vector<bool>
144  rseReducedGroups; // true if group is in either ResultSet #1 or ResultSet #2
145  std::vector<int64_t> rs1_values; // generated values for ResultSet #1
146  std::vector<int64_t> rs2_values; // generated values for ResultSet #2
147  std::queue<std::vector<int64_t>>
148  rseReducedTable; // combined/reduced values of ResultSet #1 and ResultSet #2
149 
150  void rse_fill_storage_buffer_perfect_hash_colwise(int8_t* buff,
151  NumberGenerator& generator,
152  const std::vector<bool>& rs_groups,
153  std::vector<int64_t>& rs_values);
154  void rse_fill_storage_buffer_perfect_hash_rowwise(int8_t* buff,
155  NumberGenerator& generator,
156  const std::vector<bool>& rs_groups,
157  std::vector<int64_t>& rs_values);
158  void rse_fill_storage_buffer_baseline_colwise(int8_t* buff,
159  NumberGenerator& generator,
160  const std::vector<bool>& rs_groups,
161  std::vector<int64_t>& rs_values);
162  void rse_fill_storage_buffer_baseline_rowwise(int8_t* buff,
163  NumberGenerator& generator,
164  const std::vector<bool>& rs_groups,
165  std::vector<int64_t>& rs_values);
166  void rse_fill_storage_buffer(int8_t* buff,
167  NumberGenerator& generator,
168  const std::vector<bool>& rs_groups,
169  std::vector<int64_t>& rs_values);
170  void print_emulator_diag();
171  int64_t rseAggregateKMIN(size_t i);
172  int64_t rseAggregateKMAX(size_t i);
173  int64_t rseAggregateKAVG(size_t i);
174  int64_t rseAggregateKSUM(size_t i);
175  int64_t rseAggregateKCOUNT(size_t i);
176 };
177 
178 /* top level module to create and fill up ResultSets as well as to generate golden values
179  */
180 void ResultSetEmulator::emulateResultSets() {
181  /* generate topology of ResultSet #1 */
182  if (!rs_silent) {
183  printf("\nResultSetEmulator (ResultSet #1): ");
184  }
185 
186  createResultSet(rs1_perc, rs1_groups);
187  if (!rs_silent) {
188  printf("\n");
189  for (size_t i = 0; i < rs1_groups.size(); i++) {
190  if (rs1_groups[i]) {
191  printf("1");
192  } else {
193  printf("0");
194  }
195  }
196  }
197 
198  /* generate topology of ResultSet #2 */
199  if (!rs_silent) {
200  printf("\nResultSetEmulator (ResultSet #2): ");
201  }
202 
203  createResultSet(rs2_perc, rs2_groups);
204  if (!rs_silent) {
205  printf("\n");
206  for (size_t i = 0; i < rs2_groups.size(); i++) {
207  if (rs2_groups[i]) {
208  printf("1");
209  } else {
210  printf("0");
211  }
212  }
213  printf("\n");
214  }
215 
216  /* populate both ResultSet's buffers with real data */
217  // print_emulator_diag();
218  rse_fill_storage_buffer(rs1_buff, rs1_gen, rs1_groups, rs1_values);
219  // print_emulator_diag();
220  rse_fill_storage_buffer(rs2_buff, rs2_gen, rs2_groups, rs2_values);
221  // print_emulator_diag();
222 
223  /* merge/reduce data contained in both ResultSets and generate golden values */
224  mergeResultSets();
225 }
226 
227 /* generate ResultSet topology (create rs_groups and rs_groups_idx vectors) */
228 void ResultSetEmulator::createResultSet(size_t rs_perc, std::vector<bool>& rs_groups) {
229  std::vector<int> rs_groups_idx;
230  rs_groups_idx.resize(rs_entry_count);
231  std::iota(rs_groups_idx.begin(), rs_groups_idx.end(), 0);
232  std::random_device rs_rd;
233  std::mt19937 rs_rand_gen(rs_rd());
234  std::shuffle(rs_groups_idx.begin(), rs_groups_idx.end(), rs_rand_gen);
235 
236  for (size_t i = 0; i < (rs_entry_count * rs_perc / 100); i++) {
237  if (!rs_silent) {
238  printf(" %i", rs_groups_idx[i]);
239  }
240  rs_groups[rs_groups_idx[i]] = true;
241  }
242 }
243 
244 /* merge/reduce data contained in both ResultSets and generate golden values */
245 void ResultSetEmulator::mergeResultSets() {
246  std::vector<int64_t> rse_reduced_row;
247  rse_reduced_row.resize(rs_target_infos.size());
248 
249  for (size_t j = 0; j < rs_entry_count; j++) { // iterates through rows
250  if (rs1_groups[j] || rs2_groups[j]) {
251  rseReducedGroups[j] = true;
252  for (size_t i = 0; i < rs_target_infos.size(); i++) { // iterates through columns
253  switch (rs_target_infos[i].agg_kind) {
254  case kMIN: {
255  rse_reduced_row[i] = rseAggregateKMIN(j);
256  break;
257  }
258  case kMAX: {
259  rse_reduced_row[i] = rseAggregateKMAX(j);
260  break;
261  }
262  case kAVG: {
263  rse_reduced_row[i] = rseAggregateKAVG(j);
264  break;
265  }
266  case kSUM: {
267  rse_reduced_row[i] = rseAggregateKSUM(j);
268  break;
269  }
270  case kCOUNT: {
271  rse_reduced_row[i] = rseAggregateKCOUNT(j);
272  break;
273  }
274  default:
275  CHECK(false);
276  }
277  }
278  rseReducedTable.push(rse_reduced_row);
279  }
280  }
281 }
282 
283 void ResultSetEmulator::rse_fill_storage_buffer_perfect_hash_colwise(
284  int8_t* buff,
285  NumberGenerator& generator,
286  const std::vector<bool>& rs_groups,
287  std::vector<int64_t>& rs_values) {
288  const auto key_component_count = rs_query_mem_desc.getKeyCount();
289  CHECK(rs_query_mem_desc.didOutputColumnar());
290  // initialize the key buffer(s)
291  auto col_ptr = buff;
292  for (size_t key_idx = 0; key_idx < key_component_count; ++key_idx) {
293  auto key_entry_ptr = col_ptr;
294  const auto key_bytes = rs_query_mem_desc.groupColWidth(key_idx);
295  CHECK_EQ(8, key_bytes);
296  for (size_t i = 0; i < rs_entry_count; i++) {
297  const auto v = generator.getNextValue();
298  if (rs_groups[i]) {
299  // const auto v = generator.getNextValue();
300  write_key(v, key_entry_ptr, key_bytes);
301  } else {
302  write_key(EMPTY_KEY_64, key_entry_ptr, key_bytes);
303  }
304  key_entry_ptr += key_bytes;
305  }
306  col_ptr = advance_to_next_columnar_key_buff(col_ptr, rs_query_mem_desc, key_idx);
307  generator.reset();
308  }
309  // initialize the value buffer(s)
310  size_t slot_idx = 0;
311  for (const auto& target_info : rs_target_infos) {
312  auto col_entry_ptr = col_ptr;
313  const auto col_bytes = rs_query_mem_desc.getPaddedSlotWidthBytes(slot_idx);
314  for (size_t i = 0; i < rs_entry_count; i++) {
315  int8_t* ptr2{nullptr};
316  if (target_info.agg_kind == kAVG) {
317  ptr2 = col_entry_ptr + rs_query_mem_desc.getEntryCount() * col_bytes;
318  }
319  const auto v = generator.getNextValue();
320  if (rs_groups[i]) {
321  // const auto v = generator.getNextValue();
322  rs_values[i] = v;
323  if (rs_flow == 2) { // null_val test-cases
324  if (i >= rs_entry_count - 4) { // only the last four rows of RS #1 and RS #2
325  // exersized for null_val test
326  rs_values[i] = -1;
328  col_entry_ptr,
329  col_bytes,
330  ptr2,
331  rs_query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1),
332  v,
333  target_info,
334  false,
335  true);
336  } else {
338  col_entry_ptr,
339  col_bytes,
340  ptr2,
341  rs_query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1),
342  v,
343  target_info,
344  false,
345  false);
346  }
347  } else {
348  fill_one_entry_one_col(col_entry_ptr,
349  col_bytes,
350  ptr2,
351  rs_query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1),
352  v,
353  target_info,
354  false,
355  false);
356  }
357  } else {
358  if (rs_flow == 2) { // null_val test-cases
359  if (i >= rs_entry_count - 4) { // only the last four rows of RS #1 and RS #2
360  // exersized for null_val test
361  rs_values[i] = -1;
362  }
363  fill_one_entry_one_col(col_entry_ptr,
364  col_bytes,
365  ptr2,
366  rs_query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1),
367  rs_query_mem_desc.hasKeylessHash() ? 0 : 0xdeadbeef,
368  target_info,
369  true,
370  true);
371  } else {
372  fill_one_entry_one_col(col_entry_ptr,
373  col_bytes,
374  ptr2,
375  rs_query_mem_desc.getPaddedSlotWidthBytes(slot_idx + 1),
376  rs_query_mem_desc.hasKeylessHash() ? 0 : 0xdeadbeef,
377  target_info,
378  true,
379  false);
380  }
381  }
382  col_entry_ptr += col_bytes;
383  }
384  col_ptr = advance_to_next_columnar_target_buff(col_ptr, rs_query_mem_desc, slot_idx);
385  if (target_info.is_agg && target_info.agg_kind == kAVG) {
386  col_ptr =
387  advance_to_next_columnar_target_buff(col_ptr, rs_query_mem_desc, slot_idx + 1);
388  }
389  slot_idx = advance_slot(slot_idx, target_info, false);
390  generator.reset();
391  }
392 }
393 
394 void ResultSetEmulator::rse_fill_storage_buffer_perfect_hash_rowwise(
395  int8_t* buff,
396  NumberGenerator& generator,
397  const std::vector<bool>& rs_groups,
398  std::vector<int64_t>& rs_values) {
399  const auto key_component_count = rs_query_mem_desc.getKeyCount();
400  CHECK(!rs_query_mem_desc.didOutputColumnar());
401  auto key_buff = buff;
402  CHECK_EQ(rs_groups.size(), rs_query_mem_desc.getEntryCount());
403  for (size_t i = 0; i < rs_groups.size(); i++) {
404  const auto v = generator.getNextValue();
405  if (rs_groups[i]) {
406  // const auto v = generator.getNextValue();
407  rs_values[i] = v;
408  auto key_buff_i64 = reinterpret_cast<int64_t*>(key_buff);
409  for (size_t key_comp_idx = 0; key_comp_idx < key_component_count; ++key_comp_idx) {
410  *key_buff_i64++ = v;
411  }
412  auto entries_buff = reinterpret_cast<int8_t*>(key_buff_i64);
413  if (rs_flow == 2) { // null_vall test-cases
414  if (i >= rs_entry_count - 4) { // only the last four rows of RS #1 and RS #2
415  // exersized for null_val test
416  rs_values[i] = -1;
417  key_buff = fill_one_entry_no_collisions(
418  entries_buff, rs_query_mem_desc, v, rs_target_infos, false, true);
419  } else {
420  key_buff = fill_one_entry_no_collisions(
421  entries_buff, rs_query_mem_desc, v, rs_target_infos, false, false);
422  }
423  } else {
424  key_buff = fill_one_entry_no_collisions(
425  entries_buff, rs_query_mem_desc, v, rs_target_infos, false);
426  }
427  } else {
428  auto key_buff_i64 = reinterpret_cast<int64_t*>(key_buff);
429  for (size_t key_comp_idx = 0; key_comp_idx < key_component_count; ++key_comp_idx) {
430  *key_buff_i64++ = EMPTY_KEY_64;
431  }
432  auto entries_buff = reinterpret_cast<int8_t*>(key_buff_i64);
433  if (rs_flow == 2) { // null_val test-cases
434  if (i >= rs_entry_count - 4) { // only the last four rows of RS #1 and RS #2
435  // exersized for null_val test
436  rs_values[i] = -1;
437  }
438  key_buff = fill_one_entry_no_collisions(
439  entries_buff, rs_query_mem_desc, 0xdeadbeef, rs_target_infos, true, true);
440  } else {
441  key_buff = fill_one_entry_no_collisions(
442  entries_buff, rs_query_mem_desc, 0xdeadbeef, rs_target_infos, true);
443  }
444  }
445  }
446 }
447 
448 void ResultSetEmulator::rse_fill_storage_buffer_baseline_colwise(
449  int8_t* buff,
450  NumberGenerator& generator,
451  const std::vector<bool>& rs_groups,
452  std::vector<int64_t>& rs_values) {
453  CHECK(rs_query_mem_desc.didOutputColumnar());
454  const auto key_component_count = rs_query_mem_desc.getKeyCount();
455  const auto i64_buff = reinterpret_cast<int64_t*>(buff);
456  for (size_t i = 0; i < rs_entry_count; i++) {
457  for (size_t key_comp_idx = 0; key_comp_idx < key_component_count; ++key_comp_idx) {
458  i64_buff[key_offset_colwise(i, key_comp_idx, rs_entry_count)] = EMPTY_KEY_64;
459  }
460  size_t target_slot = 0;
461  int64_t init_val = 0;
462  for (const auto& target_info : rs_target_infos) {
463  if (target_info.agg_kind == kCOUNT) {
464  init_val = 0;
465  } else if (!target_info.sql_type.get_notnull() && target_info.skip_null_val &&
466  (rs_flow == 2)) { // null_val support
467  init_val = inline_int_null_val(target_info.sql_type);
468  } else {
469  init_val = 0xdeadbeef;
470  }
471  if (target_info.agg_kind != kAVG) {
472  i64_buff[slot_offset_colwise(
473  i, target_slot, key_component_count, rs_entry_count)] = init_val;
474  } else {
475  i64_buff[slot_offset_colwise(
476  i, target_slot, key_component_count, rs_entry_count)] = 0;
477  }
478  target_slot++;
479  }
480  }
481  for (size_t i = 0; i < rs_entry_count; i++) {
482  const auto v = generator.getNextValue();
483  if (rs_groups[i]) {
484  bool null_val = false;
485  if ((rs_flow == 2) &&
486  (i >= rs_entry_count - 4)) { // null_val test-cases: last four rows
487  rs_values[i] = -1;
488  null_val = true;
489  } else {
490  rs_values[i] = v;
491  }
492  std::vector<int64_t> key(key_component_count, v);
493  auto value_slots =
494  get_group_value_columnar(i64_buff, rs_entry_count, &key[0], key.size());
495  CHECK(value_slots);
496  for (const auto& target_info : rs_target_infos) {
498  value_slots, v, target_info, rs_entry_count, false, null_val);
499  value_slots += rs_entry_count;
500  if (target_info.agg_kind == kAVG) {
501  value_slots += rs_entry_count;
502  }
503  }
504  }
505  }
506 }
507 
508 void ResultSetEmulator::rse_fill_storage_buffer_baseline_rowwise(
509  int8_t* buff,
510  NumberGenerator& generator,
511  const std::vector<bool>& rs_groups,
512  std::vector<int64_t>& rs_values) {
513  CHECK(!rs_query_mem_desc.didOutputColumnar());
514  CHECK_EQ(rs_groups.size(), rs_query_mem_desc.getEntryCount());
515  const auto key_component_count = rs_query_mem_desc.getKeyCount();
516  const auto i64_buff = reinterpret_cast<int64_t*>(buff);
517  const auto target_slot_count = get_slot_count(rs_target_infos);
518  for (size_t i = 0; i < rs_entry_count; i++) {
519  const auto first_key_comp_offset =
520  key_offset_rowwise(i, key_component_count, target_slot_count);
521  for (size_t key_comp_idx = 0; key_comp_idx < key_component_count; ++key_comp_idx) {
522  i64_buff[first_key_comp_offset + key_comp_idx] = EMPTY_KEY_64;
523  }
524  size_t target_slot = 0;
525  int64_t init_val = 0;
526  for (const auto& target_info : rs_target_infos) {
527  if (target_info.agg_kind == kCOUNT) {
528  init_val = 0;
529  } else if (!target_info.sql_type.get_notnull() && target_info.skip_null_val &&
530  (rs_flow == 2)) { // null_val support
531  init_val = inline_int_null_val(target_info.sql_type);
532  } else {
533  init_val = 0xdeadbeef;
534  }
535  i64_buff[slot_offset_rowwise(
536  i, target_slot, key_component_count, target_slot_count)] = init_val;
537  target_slot++;
538  if (target_info.agg_kind == kAVG) {
539  i64_buff[slot_offset_rowwise(
540  i, target_slot, key_component_count, target_slot_count)] = 0;
541  target_slot++;
542  }
543  }
544  }
545 
546  for (size_t i = 0; i < rs_entry_count; i++) {
547  const auto v = generator.getNextValue();
548  if (rs_groups[i]) {
549  std::vector<int64_t> key(key_component_count, v);
550  auto value_slots = get_group_value(i64_buff,
551  rs_entry_count,
552  &key[0],
553  key.size(),
554  sizeof(int64_t),
555  key_component_count + target_slot_count,
556  nullptr);
557  CHECK(value_slots);
558  if ((rs_flow == 2) &&
559  (i >= rs_entry_count - 4)) { // null_val test-cases: last four rows
560  rs_values[i] = -1;
561  fill_one_entry_baseline(value_slots, v, rs_target_infos, false, true);
562  } else {
563  rs_values[i] = v;
564  fill_one_entry_baseline(value_slots, v, rs_target_infos, false, false);
565  }
566  }
567  }
568 }
569 
570 void ResultSetEmulator::rse_fill_storage_buffer(int8_t* buff,
571  NumberGenerator& generator,
572  const std::vector<bool>& rs_groups,
573  std::vector<int64_t>& rs_values) {
574  switch (rs_query_mem_desc.getQueryDescriptionType()) {
576  if (rs_query_mem_desc.didOutputColumnar()) {
577  rse_fill_storage_buffer_perfect_hash_colwise(
578  buff, generator, rs_groups, rs_values);
579  } else {
580  rse_fill_storage_buffer_perfect_hash_rowwise(
581  buff, generator, rs_groups, rs_values);
582  }
583  break;
584  }
586  if (rs_query_mem_desc.didOutputColumnar()) {
587  rse_fill_storage_buffer_baseline_colwise(buff, generator, rs_groups, rs_values);
588  } else {
589  rse_fill_storage_buffer_baseline_rowwise(buff, generator, rs_groups, rs_values);
590  }
591  break;
592  }
593  default:
594  CHECK(false);
595  }
596  CHECK(buff);
597 }
598 
599 #ifdef __clang__
600 #pragma clang diagnostic push
601 #pragma clang diagnostic ignored "-Wunused-function"
602 #else
603 #pragma GCC diagnostic push
604 #pragma GCC diagnostic ignored "-Wunused-function"
605 #endif
606 
607 void ResultSetEmulator::print_emulator_diag() {
608  if (!rs_silent) {
609  for (size_t j = 0; j < rs_entry_count; j++) {
610  int g1 = 0, g2 = 0;
611  if (rs1_groups[j]) {
612  g1 = 1;
613  }
614  if (rs2_groups[j]) {
615  g2 = 1;
616  }
617  printf("\nGroup #%i (%i,%i): Buf1=%lld Buf2=%lld",
618  (int)j,
619  g1,
620  g2,
621  static_cast<long long>(rs1_values[j]),
622  static_cast<long long>(rs2_values[j]));
623  }
624  }
625 }
626 
627 #ifdef __clang__
628 #pragma clang diagnostic pop
629 #else
630 #pragma GCC diagnostic pop
631 #endif
632 
633 void ResultSetEmulator::print_rse_generated_result_sets() const {
634  printf("\nResultSet #1 Final Groups: ");
635  for (size_t i = 0; i < rs1_groups.size(); i++) {
636  if (rs1_groups[i]) {
637  printf("1");
638  } else {
639  printf("0");
640  }
641  }
642 
643  printf("\nResultSet #2 Final Groups: ");
644  for (size_t i = 0; i < rs2_groups.size(); i++) {
645  if (rs2_groups[i]) {
646  printf("1");
647  } else {
648  printf("0");
649  }
650  }
651  printf("\n");
652 }
653 
654 void ResultSetEmulator::print_merged_result_sets(const std::vector<OneRow>& result) {
655  printf("\n ****** KMIN_DATA_FROM_RS_MERGE_CODE ****** %i", (int)result.size());
656  size_t j = 0;
657  for (const auto& row : result) {
658  const auto ival_0 = v<int64_t>(row[0]); // kMIN
659  const auto ival_1 = v<int64_t>(row[1]); // kMAX
660  const auto ival_2 = v<int64_t>(row[2]); // kSUM
661  const auto ival_3 = v<int64_t>(row[3]); // kCOUNT
662  const auto ival_4 = v<double>(row[4]); // kAVG
663  printf("\n Group #%i KMIN/KMAX/KSUM/KCOUNT from RS_MergeCode: %lld %lld %lld %lld %f",
664  (int)j,
665  static_cast<long long>(ival_0),
666  static_cast<long long>(ival_1),
667  static_cast<long long>(ival_2),
668  static_cast<long long>(ival_3),
669  ival_4);
670  j++;
671  }
672 
673  size_t active_group_count = 0;
674  for (size_t j = 0; j < rseReducedGroups.size(); j++) {
675  if (rseReducedGroups[j]) {
676  active_group_count++;
677  }
678  }
679  printf("\n\n ****** KMIN_DATA_FROM_MERGE_BUFFER_CODE ****** Total: %i, Active: %i",
680  (int)rs_entry_count,
681  (int)active_group_count);
682  size_t num_groups = getReferenceTable().size();
683  for (size_t i = 0; i < num_groups; i++) {
684  std::vector<int64_t> ref_row = getReferenceRow(true);
685  int64_t ref_val_0 = ref_row[0]; // kMIN
686  int64_t ref_val_1 = ref_row[1]; // kMAX
687  int64_t ref_val_2 = ref_row[2]; // kSUM
688  int64_t ref_val_3 = ref_row[3]; // kCOUNT
689  int64_t ref_val_4 = ref_row[4]; // kAVG
690  printf(
691  "\n Group #%i KMIN/KMAX/KSUM/KCOUNT from ReducedBuffer: %lld %lld %lld %lld %f",
692  static_cast<int>(i),
693  static_cast<long long>(ref_val_0),
694  static_cast<long long>(ref_val_1),
695  static_cast<long long>(ref_val_2),
696  static_cast<long long>(ref_val_3),
697  static_cast<double>(ref_val_4));
698  }
699  printf("\n");
700 }
701 
702 int64_t ResultSetEmulator::rseAggregateKMIN(size_t i) {
703  int64_t result = rse_get_null_val();
704 
705  if (rs1_groups[i] && rs2_groups[i]) {
706  if ((rs1_values[i] == -1) && (rs2_values[i] == -1)) {
707  return result;
708  } else {
709  if ((rs1_values[i] != -1) && (rs2_values[i] != -1)) {
710  result = std::min(rs1_values[i], rs2_values[i]);
711  } else {
712  result = std::max(rs1_values[i], rs2_values[i]);
713  }
714  }
715  } else {
716  if (rs1_groups[i]) {
717  if (rs1_values[i] != -1) {
718  result = rs1_values[i];
719  }
720  } else {
721  if (rs2_groups[i]) {
722  if (rs2_values[i] != -1) {
723  result = rs2_values[i];
724  }
725  }
726  }
727  }
728 
729  return result;
730 }
731 
732 int64_t ResultSetEmulator::rseAggregateKMAX(size_t i) {
733  int64_t result = rse_get_null_val();
734 
735  if (rs1_groups[i] && rs2_groups[i]) {
736  if ((rs1_values[i] == -1) && (rs2_values[i] == -1)) {
737  return result;
738  } else {
739  result = std::max(rs1_values[i], rs2_values[i]);
740  }
741  } else {
742  if (rs1_groups[i]) {
743  if (rs1_values[i] != -1) {
744  result = rs1_values[i];
745  }
746  } else {
747  if (rs2_groups[i]) {
748  if (rs2_values[i] != -1) {
749  result = rs2_values[i];
750  }
751  }
752  }
753  }
754 
755  return result;
756 }
757 
758 int64_t ResultSetEmulator::rseAggregateKAVG(size_t i) {
759  int64_t result = 0;
760  int n1 = 1,
761  n2 = 1; // for test purposes count of elements in each group is 1 (see proc
762  // "fill_one_entry_no_collisions")
763 
764  if (rs1_groups[i] && rs2_groups[i]) {
765  if ((rs1_values[i] == -1) && (rs2_values[i] == -1)) {
766  // return rse_get_null_val();
767  return result;
768  }
769  int n = 0;
770  if (rs1_values[i] != -1) {
771  result += rs1_values[i] / n1;
772  n++;
773  }
774  if (rs2_values[i] != -1) {
775  result += rs2_values[i] / n2;
776  n++;
777  }
778  if (n > 1) {
779  result /= n;
780  }
781  } else {
782  // result = rse_get_null_val();
783  if (rs1_groups[i]) {
784  if (rs1_values[i] != -1) {
785  result = rs1_values[i] / n1;
786  }
787  } else {
788  if (rs2_groups[i]) {
789  if (rs2_values[i] != -1) {
790  result = rs2_values[i] / n2;
791  }
792  }
793  }
794  }
795 
796  return result;
797 }
798 
799 int64_t ResultSetEmulator::rseAggregateKSUM(size_t i) {
800  int64_t result = 0;
801 
802  if (rs1_groups[i] && rs2_groups[i]) {
803  if ((rs1_values[i] == -1) && (rs2_values[i] == -1)) {
804  return rse_get_null_val();
805  }
806  if (rs1_values[i] != -1) {
807  result += rs1_values[i];
808  }
809  if (rs2_values[i] != -1) {
810  result += rs2_values[i];
811  }
812  } else {
813  result = rse_get_null_val();
814  if (rs1_groups[i]) {
815  if (rs1_values[i] != -1) {
816  result = rs1_values[i];
817  }
818  } else {
819  if (rs2_groups[i]) {
820  if (rs2_values[i] != -1) {
821  result = rs2_values[i];
822  }
823  }
824  }
825  }
826 
827  return result;
828 }
829 
830 int64_t ResultSetEmulator::rseAggregateKCOUNT(size_t i) {
831  int64_t result = 0;
832 
833  if (rs1_groups[i] && rs2_groups[i]) {
834  if ((rs1_values[i] == -1) && (rs2_values[i] == -1)) {
835  return 0;
836  }
837  if (rs1_values[i] != -1) {
838  result += rs1_values[i];
839  }
840  if (rs2_values[i] != -1) {
841  result += rs2_values[i];
842  }
843  } else {
844  if (rs1_groups[i]) {
845  if (rs1_values[i] != -1) {
846  result = rs1_values[i];
847  }
848  } else {
849  if (rs2_groups[i]) {
850  if (rs2_values[i] != -1) {
851  result = rs2_values[i];
852  }
853  }
854  }
855  }
856 
857  return result;
858 }
859 
860 bool approx_eq(const double v, const double target, const double eps = 0.01) {
861  return target - eps < v && v < target + eps;
862 }
863 
864 std::shared_ptr<StringDictionary> g_sd =
865  std::make_shared<StringDictionary>("", false, true);
866 
867 void test_iterate(const std::vector<TargetInfo>& target_infos,
868  const QueryMemoryDescriptor& query_mem_desc) {
869  SQLTypeInfo double_ti(kDOUBLE, false);
870  auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
871  StringDictionaryProxy* sdp =
872  row_set_mem_owner->addStringDict(g_sd, 1, g_sd->storageEntryCount());
873  ResultSet result_set(
874  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
875  for (size_t i = 0; i < query_mem_desc.getEntryCount(); ++i) {
876  sdp->getOrAddTransient(std::to_string(i));
877  }
878  const auto storage = result_set.allocateStorage();
879  EvenNumberGenerator generator;
881  storage->getUnderlyingBuffer(), target_infos, query_mem_desc, generator, 2);
882  int64_t ref_val{0};
883  while (true) {
884  const auto row = result_set.getNextRow(true, false);
885  if (row.empty()) {
886  break;
887  }
888  CHECK_EQ(target_infos.size(), row.size());
889  for (size_t i = 0; i < target_infos.size(); ++i) {
890  const auto& target_info = target_infos[i];
891  const auto& ti = target_info.agg_kind == kAVG ? double_ti : target_info.sql_type;
892  switch (ti.get_type()) {
893  case kTINYINT:
894  case kSMALLINT:
895  case kINT:
896  case kBIGINT: {
897  const auto ival = v<int64_t>(row[i]);
898  ASSERT_EQ(ref_val, ival);
899  break;
900  }
901  case kDOUBLE: {
902  const auto dval = v<double>(row[i]);
903  ASSERT_TRUE(approx_eq(static_cast<double>(ref_val), dval));
904  break;
905  }
906  case kTEXT: {
907  const auto sval = v<NullableString>(row[i]);
908  ASSERT_EQ(std::to_string(ref_val), boost::get<std::string>(sval));
909  break;
910  }
911  default:
912  CHECK(false);
913  }
914  }
915  ref_val += 2;
916  }
917 }
918 
919 std::vector<TargetInfo> generate_test_target_infos() {
920  std::vector<TargetInfo> target_infos;
921  SQLTypeInfo int_ti(kINT, false);
922  SQLTypeInfo double_ti(kDOUBLE, false);
923  SQLTypeInfo null_ti(kNULLT, false);
924  target_infos.push_back(TargetInfo{false, kMIN, int_ti, null_ti, true, false});
925  target_infos.push_back(TargetInfo{true, kAVG, int_ti, int_ti, true, false});
926  target_infos.push_back(TargetInfo{true, kSUM, int_ti, int_ti, true, false});
927  target_infos.push_back(TargetInfo{false, kMIN, double_ti, null_ti, true, false});
928  {
929  SQLTypeInfo dict_string_ti(kTEXT, false);
930  dict_string_ti.set_compression(kENCODING_DICT);
931  dict_string_ti.set_comp_param(1);
932  target_infos.push_back(TargetInfo{false, kMIN, dict_string_ti, null_ti, true, false});
933  }
934  return target_infos;
935 }
936 
937 std::vector<TargetInfo> generate_random_groups_target_infos() {
938  std::vector<TargetInfo> target_infos;
939  SQLTypeInfo int_ti(kINT, true);
940  SQLTypeInfo double_ti(kDOUBLE, true);
941  // SQLTypeInfo null_ti(kNULLT, false);
942  target_infos.push_back(TargetInfo{true, kMIN, int_ti, int_ti, true, false});
943  target_infos.push_back(TargetInfo{true, kMAX, int_ti, int_ti, true, false});
944  target_infos.push_back(TargetInfo{true, kSUM, int_ti, int_ti, true, false});
945  target_infos.push_back(TargetInfo{true, kCOUNT, int_ti, int_ti, true, false});
946  target_infos.push_back(TargetInfo{true, kAVG, int_ti, double_ti, true, false});
947  return target_infos;
948 }
949 
951  std::vector<TargetInfo> target_infos;
952  SQLTypeInfo int_ti(kINT, false);
953  // SQLTypeInfo null_ti(kNULLT, false);
954  SQLTypeInfo double_ti(kDOUBLE, false);
955  target_infos.push_back(TargetInfo{true, kMIN, int_ti, int_ti, true, false});
956  target_infos.push_back(TargetInfo{true, kMAX, int_ti, int_ti, true, false});
957  target_infos.push_back(TargetInfo{true, kSUM, int_ti, int_ti, true, false});
958  target_infos.push_back(TargetInfo{true, kCOUNT, int_ti, int_ti, true, false});
959  target_infos.push_back(TargetInfo{true, kAVG, int_ti, double_ti, true, false});
960  return target_infos;
961 }
962 
963 std::vector<OneRow> get_rows_sorted_by_col(ResultSet& rs, const size_t col_idx) {
964  std::list<Analyzer::OrderEntry> order_entries;
965  order_entries.emplace_back(1, false, false);
966  rs.sort(order_entries, 0);
967  std::vector<OneRow> result;
968 
969  while (true) {
970  const auto row = rs.getNextRow(false, false);
971  if (row.empty()) {
972  break;
973  }
974  result.push_back(row);
975  }
976  return result;
977 }
978 
979 void test_reduce(const std::vector<TargetInfo>& target_infos,
980  const QueryMemoryDescriptor& query_mem_desc,
981  NumberGenerator& generator1,
982  NumberGenerator& generator2,
983  const int step) {
984  SQLTypeInfo double_ti(kDOUBLE, false);
985  const ResultSetStorage* storage1{nullptr};
986  const ResultSetStorage* storage2{nullptr};
987  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
988  row_set_mem_owner->addStringDict(g_sd, 1, g_sd->storageEntryCount());
989  const auto rs1 = std::make_unique<ResultSet>(
990  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
991  storage1 = rs1->allocateStorage();
993  storage1->getUnderlyingBuffer(), target_infos, query_mem_desc, generator1, step);
994  const auto rs2 = std::make_unique<ResultSet>(
995  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
996  storage2 = rs2->allocateStorage();
998  storage2->getUnderlyingBuffer(), target_infos, query_mem_desc, generator2, step);
999  ResultSetManager rs_manager;
1000  std::vector<ResultSet*> storage_set{rs1.get(), rs2.get()};
1001  auto result_rs = rs_manager.reduce(storage_set);
1002  int64_t ref_val{0};
1003  std::list<Analyzer::OrderEntry> order_entries;
1004  order_entries.emplace_back(1, false, false);
1005  result_rs->sort(order_entries, 0);
1006  while (true) {
1007  const auto row = result_rs->getNextRow(false, false);
1008  if (row.empty()) {
1009  break;
1010  }
1011  CHECK_EQ(target_infos.size(), row.size());
1012  for (size_t i = 0; i < target_infos.size(); ++i) {
1013  const auto& target_info = target_infos[i];
1014  const auto& ti = target_info.agg_kind == kAVG ? double_ti : target_info.sql_type;
1015  switch (ti.get_type()) {
1016  case kTINYINT:
1017  case kSMALLINT:
1018  case kINT:
1019  case kBIGINT: {
1020  const auto ival = v<int64_t>(row[i]);
1021  ASSERT_EQ((target_info.agg_kind == kSUM || target_info.agg_kind == kCOUNT)
1022  ? step * ref_val
1023  : ref_val,
1024  ival);
1025  break;
1026  }
1027  case kDOUBLE: {
1028  const auto dval = v<double>(row[i]);
1029  ASSERT_TRUE(approx_eq(static_cast<double>((target_info.agg_kind == kSUM ||
1030  target_info.agg_kind == kCOUNT)
1031  ? step * ref_val
1032  : ref_val),
1033  dval));
1034  break;
1035  }
1036  case kTEXT:
1037  break;
1038  default:
1039  CHECK(false);
1040  }
1041  }
1042  ref_val += step;
1043  }
1044 }
1045 
1046 void test_reduce_random_groups(const std::vector<TargetInfo>& target_infos,
1047  const QueryMemoryDescriptor& query_mem_desc,
1048  NumberGenerator& generator1,
1049  NumberGenerator& generator2,
1050  const int prct1,
1051  const int prct2,
1052  bool silent,
1053  const int flow = 0) {
1054  SQLTypeInfo double_ti(kDOUBLE, false);
1055  const ResultSetStorage* storage1{nullptr};
1056  const ResultSetStorage* storage2{nullptr};
1057  std::unique_ptr<ResultSet> rs1;
1058  std::unique_ptr<ResultSet> rs2;
1059  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
1060  switch (query_mem_desc.getQueryDescriptionType()) {
1062  rs1.reset(new ResultSet(target_infos,
1064  query_mem_desc,
1065  row_set_mem_owner,
1066  nullptr));
1067  storage1 = rs1->allocateStorage();
1068  rs2.reset(new ResultSet(target_infos,
1070  query_mem_desc,
1071  row_set_mem_owner,
1072  nullptr));
1073  storage2 = rs2->allocateStorage();
1074  break;
1075  }
1077  rs1.reset(new ResultSet(target_infos,
1079  query_mem_desc,
1080  row_set_mem_owner,
1081  nullptr));
1082  storage1 = rs1->allocateStorage();
1083  rs2.reset(new ResultSet(target_infos,
1085  query_mem_desc,
1086  row_set_mem_owner,
1087  nullptr));
1088  storage2 = rs2->allocateStorage();
1089  break;
1090  }
1091  default:
1092  CHECK(false);
1093  }
1094 
1095  ResultSetEmulator* rse = new ResultSetEmulator(storage1->getUnderlyingBuffer(),
1096  storage2->getUnderlyingBuffer(),
1097  target_infos,
1098  query_mem_desc,
1099  generator1,
1100  generator2,
1101  prct1,
1102  prct2,
1103  flow,
1104  silent);
1105  if (!silent) {
1107  }
1108 
1109  ResultSetManager rs_manager;
1110  std::vector<ResultSet*> storage_set{rs1.get(), rs2.get()};
1111  auto result_rs = rs_manager.reduce(storage_set);
1112  std::queue<std::vector<int64_t>> ref_table = rse->getReferenceTable();
1113  std::vector<bool> ref_group_map = rse->getReferenceGroupMap();
1114  const auto result = get_rows_sorted_by_col(*result_rs, 0);
1115  CHECK(!result.empty());
1116 
1117  if (!silent) {
1119  }
1120 
1121  size_t row_idx = 0;
1122  int64_t ref_val = 0;
1123  for (const auto& row : result) {
1124  CHECK_EQ(target_infos.size(), row.size());
1125  while (true) {
1126  if (row_idx >= rse->getReferenceGroupMap().size()) {
1127  LOG(FATAL) << "Number of groups in reduced result set is more than expected";
1128  }
1129  if (rse->getReferenceGroupMapElement(row_idx)) {
1130  break;
1131  } else {
1132  row_idx++;
1133  continue;
1134  }
1135  }
1136  std::vector<int64_t> ref_row = rse->getReferenceRow();
1137  for (size_t i = 0; i < target_infos.size(); ++i) {
1138  ref_val = ref_row[i];
1139  const auto& target_info = target_infos[i];
1140  const auto& ti = target_info.agg_kind == kAVG ? double_ti : target_info.sql_type;
1141  std::string p_tag("");
1142  if (flow == 2) { // null_val test-cases
1143  p_tag += "kNULLT_";
1144  }
1145  switch (ti.get_type()) {
1146  case kSMALLINT:
1147  case kINT:
1148  case kBIGINT: {
1149  const auto ival = v<int64_t>(row[i]);
1150  switch (target_info.agg_kind) {
1151  case kMIN: {
1152  if (!silent) {
1153  p_tag += "KMIN";
1154  printf("\n%s row_idx = %i, ref_val = %lld, ival = %lld",
1155  p_tag.c_str(),
1156  static_cast<int>(row_idx),
1157  static_cast<long long>(ref_val),
1158  static_cast<long long>(ival));
1159  if (ref_val != ival) {
1160  printf("%21s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1161  } else {
1162  printf("%21s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1163  }
1164  } else {
1165  ASSERT_EQ(ref_val, ival);
1166  }
1167  break;
1168  }
1169  case kMAX: {
1170  if (!silent) {
1171  p_tag += "KMAX";
1172  printf("\n%s row_idx = %i, ref_val = %lld, ival = %lld",
1173  p_tag.c_str(),
1174  static_cast<int>(row_idx),
1175  static_cast<long long>(ref_val),
1176  static_cast<long long>(ival));
1177  if (ref_val != ival) {
1178  printf("%21s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1179  } else {
1180  printf("%21s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1181  }
1182  } else {
1183  ASSERT_EQ(ref_val, ival);
1184  }
1185  break;
1186  }
1187  case kAVG: {
1188  if (!silent) {
1189  p_tag += "KAVG";
1190  printf("\n%s row_idx = %i, ref_val = %lld, ival = %lld",
1191  p_tag.c_str(),
1192  static_cast<int>(row_idx),
1193  static_cast<long long>(ref_val),
1194  static_cast<long long>(ival));
1195  if (ref_val != ival) {
1196  printf("%21s%s%s", "", p_tag.c_str(), " TEST FAILED1!\n");
1197  } else {
1198  printf("%21s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1199  }
1200  } else {
1201  ASSERT_EQ(ref_val, ival);
1202  }
1203  break;
1204  }
1205  case kSUM:
1206  case kCOUNT: {
1207  if (!silent) {
1208  p_tag += "KSUM";
1209  printf("\n%s row_idx = %i, ref_val = %lld, ival = %lld",
1210  p_tag.c_str(),
1211  static_cast<int>(row_idx),
1212  static_cast<long long>(ref_val),
1213  static_cast<long long>(ival));
1214  if (ref_val != ival) {
1215  printf("%21s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1216  } else {
1217  printf("%21s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1218  }
1219  } else {
1220  ASSERT_EQ(ref_val, ival);
1221  }
1222  break;
1223  }
1224  default:
1225  CHECK(false);
1226  }
1227  break;
1228  }
1229  case kDOUBLE: {
1230  const auto dval = v<double>(row[i]);
1231  switch (target_info.agg_kind) {
1232  case kMIN: {
1233  if (!silent) {
1234  p_tag += "KMIN_D";
1235  printf("\nKMIN_D row_idx = %i, ref_val = %f, dval = %f",
1236  static_cast<int>(row_idx),
1237  static_cast<double>(ref_val),
1238  dval);
1239  if (!approx_eq(static_cast<double>(ref_val), dval)) {
1240  printf("%5s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1241  } else {
1242  printf("%5s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1243  }
1244  } else {
1245  ASSERT_TRUE(approx_eq(static_cast<double>(ref_val), dval));
1246  }
1247  break;
1248  }
1249  case kMAX: {
1250  if (!silent) {
1251  p_tag += "KMAX_D";
1252  printf("\n%s row_idx = %i, ref_val = %f, dval = %f",
1253  p_tag.c_str(),
1254  static_cast<int>(row_idx),
1255  static_cast<double>(ref_val),
1256  dval);
1257  if (!approx_eq(static_cast<double>(ref_val), dval)) {
1258  printf("%5s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1259  } else {
1260  printf("%5s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1261  }
1262  } else {
1263  ASSERT_TRUE(approx_eq(static_cast<double>(ref_val), dval));
1264  }
1265  break;
1266  }
1267  case kAVG: {
1268  if (!silent) {
1269  p_tag += "KAVG_D";
1270  printf("\n%s row_idx = %i, ref_val = %f, dval = %f",
1271  p_tag.c_str(),
1272  static_cast<int>(row_idx),
1273  static_cast<double>(ref_val),
1274  dval);
1275  if (!approx_eq(static_cast<double>(ref_val), dval)) {
1276  printf("%5s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1277  } else {
1278  printf("%5s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1279  }
1280  } else {
1281  ASSERT_TRUE(approx_eq(static_cast<double>(ref_val), dval));
1282  }
1283  break;
1284  }
1285  case kSUM:
1286  case kCOUNT: {
1287  if (!silent) {
1288  p_tag += "KSUM_D";
1289  printf("\n%s row_idx = %i, ref_val = %f, dval = %f",
1290  p_tag.c_str(),
1291  (int)row_idx,
1292  (double)ref_val,
1293  dval);
1294  if (!approx_eq(static_cast<double>(ref_val), dval)) {
1295  printf("%5s%s%s", "", p_tag.c_str(), " TEST FAILED!\n");
1296  } else {
1297  printf("%5s%s%s", "", p_tag.c_str(), " TEST PASSED!\n");
1298  }
1299  } else {
1300  ASSERT_TRUE(approx_eq(static_cast<double>(ref_val), dval));
1301  }
1302  break;
1303  }
1304  default:
1305  CHECK(false);
1306  }
1307  break;
1308  }
1309  default:
1310  CHECK(false);
1311  }
1312  }
1313  row_idx++;
1314  }
1315 
1316  delete rse;
1317 }
1318 } // namespace
1319 
1320 TEST(Iterate, PerfectHashOneCol) {
1321  const auto target_infos = generate_test_target_infos();
1322  const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1323  test_iterate(target_infos, query_mem_desc);
1324 }
1325 
1326 TEST(Iterate, PerfectHashOneCol32) {
1327  const auto target_infos = generate_test_target_infos();
1328  const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1329  test_iterate(target_infos, query_mem_desc);
1330 }
1331 
1332 TEST(Iterate, PerfectHashOneColColumnar) {
1333  const auto target_infos = generate_test_target_infos();
1334  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1335  query_mem_desc.setOutputColumnar(true);
1336  test_iterate(target_infos, query_mem_desc);
1337 }
1338 
1339 TEST(Iterate, PerfectHashOneColColumnar32) {
1340  const auto target_infos = generate_test_target_infos();
1341  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1342  query_mem_desc.setOutputColumnar(true);
1343  test_iterate(target_infos, query_mem_desc);
1344 }
1345 
1346 TEST(Iterate, PerfectHashOneColColumnar16) {
1347  std::vector<int8_t> group_column_widths{8};
1348  const int8_t suggested_agg_width = 2;
1349  const auto target_infos = generate_custom_agg_target_infos(
1350  group_column_widths,
1351  {kMAX, kMIN, kCOUNT, kSUM, kAVG},
1353  {kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT});
1354  auto query_mem_desc = perfect_hash_one_col_desc(
1355  target_infos, suggested_agg_width, 0, 99, group_column_widths);
1356  query_mem_desc.setOutputColumnar(true);
1357  test_iterate(target_infos, query_mem_desc);
1358 }
1359 
1360 TEST(Iterate, PerfectHashOneColColumnar8) {
1361  std::vector<int8_t> group_column_widths{8};
1362  const int8_t suggested_agg_width = 1;
1363  const auto target_infos = generate_custom_agg_target_infos(
1364  group_column_widths,
1365  {kMAX, kMIN, kCOUNT, kSUM, kAVG},
1367  {kTINYINT, kTINYINT, kTINYINT, kTINYINT, kTINYINT});
1368  auto query_mem_desc = perfect_hash_one_col_desc(
1369  target_infos, suggested_agg_width, 0, 99, group_column_widths);
1370  query_mem_desc.setOutputColumnar(true);
1371  test_iterate(target_infos, query_mem_desc);
1372 }
1373 
1374 TEST(Iterate, PerfectHashOneColKeyless) {
1375  const auto target_infos = generate_test_target_infos();
1376  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1377  query_mem_desc.setHasKeylessHash(true);
1378  query_mem_desc.setTargetIdxForKey(2);
1379  test_iterate(target_infos, query_mem_desc);
1380 }
1381 
1382 TEST(Iterate, PerfectHashOneColKeyless32) {
1383  const auto target_infos = generate_test_target_infos();
1384  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1385  query_mem_desc.setHasKeylessHash(true);
1386  query_mem_desc.setTargetIdxForKey(2);
1387  test_iterate(target_infos, query_mem_desc);
1388 }
1389 
1390 TEST(Iterate, PerfectHashOneColColumnarKeyless) {
1391  const auto target_infos = generate_test_target_infos();
1392  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1393  query_mem_desc.setOutputColumnar(true);
1394  query_mem_desc.setHasKeylessHash(true);
1395  query_mem_desc.setTargetIdxForKey(2);
1396  test_iterate(target_infos, query_mem_desc);
1397 }
1398 
1399 TEST(Iterate, PerfectHashOneColColumnarKeyless32) {
1400  const auto target_infos = generate_test_target_infos();
1401  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1402  query_mem_desc.setOutputColumnar(true);
1403  query_mem_desc.setHasKeylessHash(true);
1404  query_mem_desc.setTargetIdxForKey(2);
1405  test_iterate(target_infos, query_mem_desc);
1406 }
1407 
1408 TEST(Iterate, PerfectHashOneColColumnarKeyless16) {
1409  std::vector<int8_t> group_column_widths{8};
1410  const int8_t suggested_agg_width = 2;
1411  const auto target_infos = generate_custom_agg_target_infos(
1412  group_column_widths,
1413  {kAVG, kSUM, kMIN, kCOUNT, kMAX},
1414  {kDOUBLE, kINT, kSMALLINT, kINT, kSMALLINT},
1415  {kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT});
1416  auto query_mem_desc =
1417  perfect_hash_one_col_desc(target_infos, suggested_agg_width, 0, 99);
1418  query_mem_desc.setOutputColumnar(true);
1419  query_mem_desc.setHasKeylessHash(true);
1420  query_mem_desc.setTargetIdxForKey(2);
1421  test_iterate(target_infos, query_mem_desc);
1422 }
1423 
1424 TEST(Iterate, PerfectHashOneColColumnarKeyless8) {
1425  std::vector<int8_t> group_column_widths{8};
1426  const int8_t suggested_agg_width = 1;
1427  const auto target_infos = generate_custom_agg_target_infos(
1428  group_column_widths,
1429  {kAVG, kSUM, kMIN, kCOUNT, kMAX},
1430  {kDOUBLE, kINT, kTINYINT, kINT, kTINYINT},
1431  {kTINYINT, kTINYINT, kTINYINT, kTINYINT, kTINYINT});
1432  auto query_mem_desc =
1433  perfect_hash_one_col_desc(target_infos, suggested_agg_width, 0, 99);
1434  query_mem_desc.setOutputColumnar(true);
1435  query_mem_desc.setHasKeylessHash(true);
1436  query_mem_desc.setTargetIdxForKey(2);
1437  test_iterate(target_infos, query_mem_desc);
1438 }
1439 
1440 TEST(Iterate, PerfectHashTwoCol) {
1441  const auto target_infos = generate_test_target_infos();
1442  const auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1443  test_iterate(target_infos, query_mem_desc);
1444 }
1445 
1446 TEST(Iterate, PerfectHashTwoCol32) {
1447  const auto target_infos = generate_test_target_infos();
1448  const auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1449  test_iterate(target_infos, query_mem_desc);
1450 }
1451 
1452 TEST(Iterate, PerfectHashTwoColColumnar) {
1453  const auto target_infos = generate_test_target_infos();
1454  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1455  query_mem_desc.setOutputColumnar(true);
1456  test_iterate(target_infos, query_mem_desc);
1457 }
1458 
1459 TEST(Iterate, PerfectHashTwoColColumnar32) {
1460  const auto target_infos = generate_test_target_infos();
1461  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1462  query_mem_desc.setOutputColumnar(true);
1463  test_iterate(target_infos, query_mem_desc);
1464 }
1465 
1466 TEST(Iterate, PerfectHashTwoColKeyless) {
1467  const auto target_infos = generate_test_target_infos();
1468  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1469  query_mem_desc.setHasKeylessHash(true);
1470  query_mem_desc.setTargetIdxForKey(2);
1471  test_iterate(target_infos, query_mem_desc);
1472 }
1473 
1474 TEST(Iterate, PerfectHashTwoColKeyless32) {
1475  const auto target_infos = generate_test_target_infos();
1476  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1477  query_mem_desc.setHasKeylessHash(true);
1478  query_mem_desc.setTargetIdxForKey(2);
1479  test_iterate(target_infos, query_mem_desc);
1480 }
1481 
1482 TEST(Iterate, PerfectHashTwoColColumnarKeyless) {
1483  const auto target_infos = generate_test_target_infos();
1484  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1485  query_mem_desc.setOutputColumnar(true);
1486  query_mem_desc.setHasKeylessHash(true);
1487  query_mem_desc.setTargetIdxForKey(2);
1488  test_iterate(target_infos, query_mem_desc);
1489 }
1490 
1491 TEST(Iterate, PerfectHashTwoColColumnarKeyless32) {
1492  const auto target_infos = generate_test_target_infos();
1493  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1494  query_mem_desc.setOutputColumnar(true);
1495  query_mem_desc.setHasKeylessHash(true);
1496  query_mem_desc.setTargetIdxForKey(2);
1497  test_iterate(target_infos, query_mem_desc);
1498 }
1499 
1500 TEST(Iterate, BaselineHash) {
1501  const auto target_infos = generate_test_target_infos();
1502  const auto query_mem_desc = baseline_hash_two_col_desc(target_infos, 8);
1503  test_iterate(target_infos, query_mem_desc);
1504 }
1505 
1506 TEST(Iterate, BaselineHashColumnar) {
1507  const auto target_infos = generate_test_target_infos();
1508  auto query_mem_desc = baseline_hash_two_col_desc(target_infos, 8);
1509  query_mem_desc.setOutputColumnar(true);
1510  test_iterate(target_infos, query_mem_desc);
1511 }
1512 
1513 TEST(Reduce, PerfectHashOneCol) {
1514  const auto target_infos = generate_test_target_infos();
1515  const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1516  EvenNumberGenerator generator1;
1517  EvenNumberGenerator generator2;
1518  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1519 }
1520 
1521 TEST(Reduce, PerfectHashOneCol32) {
1522  const auto target_infos = generate_test_target_infos();
1523  const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1524  EvenNumberGenerator generator1;
1525  EvenNumberGenerator generator2;
1526  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1527 }
1528 
1529 TEST(Reduce, PerfectHashOneColColumnar) {
1530  const auto target_infos = generate_test_target_infos();
1531  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1532  query_mem_desc.setOutputColumnar(true);
1533  EvenNumberGenerator generator1;
1534  EvenNumberGenerator generator2;
1535  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1536 }
1537 
1538 TEST(Reduce, PerfectHashOneColColumnar32) {
1539  const auto target_infos = generate_test_target_infos();
1540  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1541  query_mem_desc.setOutputColumnar(true);
1542  EvenNumberGenerator generator1;
1543  EvenNumberGenerator generator2;
1544  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1545 }
1546 
1547 TEST(Reduce, PerfectHashOneColColumnar16) {
1548  std::vector<int8_t> group_column_widths{8};
1549  const int8_t suggested_agg_width = 2;
1550  const auto target_infos = generate_custom_agg_target_infos(
1551  group_column_widths,
1552  {kMAX, kMIN, kCOUNT, kSUM, kAVG},
1554  {kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT});
1555  auto query_mem_desc = perfect_hash_one_col_desc(
1556  target_infos, suggested_agg_width, 0, 99, group_column_widths);
1557  query_mem_desc.setOutputColumnar(true);
1558  EvenNumberGenerator generator1;
1559  EvenNumberGenerator generator2;
1560  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1561 }
1562 
1563 TEST(Reduce, PerfectHashOneColColumnar8) {
1564  std::vector<int8_t> group_column_widths{8};
1565  const int8_t suggested_agg_width = 1;
1566  const auto target_infos = generate_custom_agg_target_infos(
1567  group_column_widths,
1568  {kMAX, kMIN, kCOUNT, kSUM, kAVG},
1570  {kTINYINT, kTINYINT, kTINYINT, kTINYINT, kTINYINT});
1571  auto query_mem_desc = perfect_hash_one_col_desc(
1572  target_infos, suggested_agg_width, 0, 99, group_column_widths);
1573  query_mem_desc.setOutputColumnar(true);
1574  EvenNumberGenerator generator1;
1575  EvenNumberGenerator generator2;
1576  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1577 }
1578 
1579 TEST(Reduce, PerfectHashOneColKeyless) {
1580  const auto target_infos = generate_test_target_infos();
1581  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1582  query_mem_desc.setHasKeylessHash(true);
1583  query_mem_desc.setTargetIdxForKey(2);
1584  EvenNumberGenerator generator1;
1585  EvenNumberGenerator generator2;
1586  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1587 }
1588 
1589 TEST(Reduce, PerfectHashOneColKeyless32) {
1590  const auto target_infos = generate_test_target_infos();
1591  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1592  query_mem_desc.setHasKeylessHash(true);
1593  query_mem_desc.setTargetIdxForKey(2);
1594  EvenNumberGenerator generator1;
1595  EvenNumberGenerator generator2;
1596  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1597 }
1598 
1599 TEST(Reduce, PerfectHashOneColColumnarKeyless) {
1600  const auto target_infos = generate_test_target_infos();
1601  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
1602  query_mem_desc.setOutputColumnar(true);
1603  query_mem_desc.setHasKeylessHash(true);
1604  query_mem_desc.setTargetIdxForKey(2);
1605  EvenNumberGenerator generator1;
1606  EvenNumberGenerator generator2;
1607  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1608 }
1609 
1610 TEST(Reduce, PerfectHashOneColColumnarKeyless32) {
1611  const auto target_infos = generate_test_target_infos();
1612  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 4, 0, 99);
1613  query_mem_desc.setOutputColumnar(true);
1614  query_mem_desc.setHasKeylessHash(true);
1615  query_mem_desc.setTargetIdxForKey(2);
1616  EvenNumberGenerator generator1;
1617  EvenNumberGenerator generator2;
1618  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1619 }
1620 
1621 TEST(Reduce, PerfectHashOneColColumnarKeyless16) {
1622  std::vector<int8_t> group_column_widths{8};
1623  const int8_t suggested_agg_width = 2;
1624  const auto target_infos = generate_custom_agg_target_infos(
1625  group_column_widths,
1626  {kAVG, kSUM, kMIN, kCOUNT, kMAX},
1627  {kDOUBLE, kINT, kSMALLINT, kINT, kSMALLINT},
1628  {kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT, kSMALLINT});
1629  auto query_mem_desc =
1630  perfect_hash_one_col_desc(target_infos, suggested_agg_width, 0, 99);
1631  query_mem_desc.setOutputColumnar(true);
1632  query_mem_desc.setHasKeylessHash(true);
1633  query_mem_desc.setTargetIdxForKey(2);
1634  EvenNumberGenerator generator1;
1635  EvenNumberGenerator generator2;
1636  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1637 }
1638 
1639 TEST(Reduce, PerfectHashOneColColumnarKeyless8) {
1640  std::vector<int8_t> group_column_widths{8};
1641  const int8_t suggested_agg_width = 1;
1642  const auto target_infos = generate_custom_agg_target_infos(
1643  group_column_widths,
1644  {kAVG, kSUM, kMIN, kCOUNT, kMAX},
1645  {kDOUBLE, kINT, kTINYINT, kINT, kTINYINT},
1646  {kTINYINT, kTINYINT, kTINYINT, kTINYINT, kTINYINT});
1647  auto query_mem_desc =
1648  perfect_hash_one_col_desc(target_infos, suggested_agg_width, 0, 99);
1649  query_mem_desc.setOutputColumnar(true);
1650  query_mem_desc.setHasKeylessHash(true);
1651  query_mem_desc.setTargetIdxForKey(2);
1652  EvenNumberGenerator generator1;
1653  EvenNumberGenerator generator2;
1654  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1655 }
1656 
1657 TEST(Reduce, PerfectHashTwoCol) {
1658  const auto target_infos = generate_test_target_infos();
1659  const auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1660  EvenNumberGenerator generator1;
1661  EvenNumberGenerator generator2;
1662  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1663 }
1664 
1665 TEST(Reduce, PerfectHashTwoCol32) {
1666  const auto target_infos = generate_test_target_infos();
1667  const auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1668  EvenNumberGenerator generator1;
1669  EvenNumberGenerator generator2;
1670  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1671 }
1672 
1673 TEST(Reduce, PerfectHashTwoColColumnar) {
1674  const auto target_infos = generate_test_target_infos();
1675  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1676  query_mem_desc.setOutputColumnar(true);
1677  EvenNumberGenerator generator1;
1678  EvenNumberGenerator generator2;
1679  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1680 }
1681 
1682 TEST(Reduce, PerfectHashTwoColColumnar32) {
1683  const auto target_infos = generate_test_target_infos();
1684  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1685  query_mem_desc.setOutputColumnar(true);
1686  EvenNumberGenerator generator1;
1687  EvenNumberGenerator generator2;
1688  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1689 }
1690 
1691 TEST(Reduce, PerfectHashTwoColKeyless) {
1692  const auto target_infos = generate_test_target_infos();
1693  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1694  query_mem_desc.setHasKeylessHash(true);
1695  query_mem_desc.setTargetIdxForKey(2);
1696  EvenNumberGenerator generator1;
1697  EvenNumberGenerator generator2;
1698  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1699 }
1700 
1701 TEST(Reduce, PerfectHashTwoColKeyless32) {
1702  const auto target_infos = generate_test_target_infos();
1703  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1704  query_mem_desc.setHasKeylessHash(true);
1705  query_mem_desc.setTargetIdxForKey(2);
1706  EvenNumberGenerator generator1;
1707  EvenNumberGenerator generator2;
1708  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1709 }
1710 
1711 TEST(Reduce, PerfectHashTwoColColumnarKeyless) {
1712  const auto target_infos = generate_test_target_infos();
1713  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 8);
1714  query_mem_desc.setOutputColumnar(true);
1715  query_mem_desc.setHasKeylessHash(true);
1716  query_mem_desc.setTargetIdxForKey(2);
1717  EvenNumberGenerator generator1;
1718  EvenNumberGenerator generator2;
1719  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1720 }
1721 
1722 TEST(Reduce, PerfectHashTwoColColumnarKeyless32) {
1723  const auto target_infos = generate_test_target_infos();
1724  auto query_mem_desc = perfect_hash_two_col_desc(target_infos, 4);
1725  query_mem_desc.setOutputColumnar(true);
1726  query_mem_desc.setHasKeylessHash(true);
1727  query_mem_desc.setTargetIdxForKey(2);
1728  EvenNumberGenerator generator1;
1729  EvenNumberGenerator generator2;
1730  test_reduce(target_infos, query_mem_desc, generator1, generator2, 2);
1731 }
1732 
1733 TEST(Reduce, BaselineHash) {
1734  const auto target_infos = generate_test_target_infos();
1735  const auto query_mem_desc = baseline_hash_two_col_desc(target_infos, 8);
1736  EvenNumberGenerator generator1;
1737  ReverseOddOrEvenNumberGenerator generator2(2 * query_mem_desc.getEntryCount() - 1);
1738  test_reduce(target_infos, query_mem_desc, generator1, generator2, 1);
1739 }
1740 
1741 TEST(Reduce, BaselineHashColumnar) {
1742  const auto target_infos = generate_test_target_infos();
1743  auto query_mem_desc = baseline_hash_two_col_desc(target_infos, 8);
1744  query_mem_desc.setOutputColumnar(true);
1745  EvenNumberGenerator generator1;
1746  ReverseOddOrEvenNumberGenerator generator2(2 * query_mem_desc.getEntryCount() - 1);
1747  test_reduce(target_infos, query_mem_desc, generator1, generator2, 1);
1748 }
1749 
1750 TEST(MoreReduce, MissingValues) {
1751  std::vector<TargetInfo> target_infos;
1752  SQLTypeInfo bigint_ti(kBIGINT, false);
1753  SQLTypeInfo null_ti(kNULLT, false);
1754  target_infos.push_back(TargetInfo{false, kMIN, bigint_ti, null_ti, true, false});
1755  target_infos.push_back(TargetInfo{true, kCOUNT, bigint_ti, null_ti, true, false});
1756  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 7, 9);
1757  query_mem_desc.setHasKeylessHash(false);
1758  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
1759  const auto rs1 = std::make_unique<ResultSet>(
1760  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1761  const auto storage1 = rs1->allocateStorage();
1762  const auto rs2 = std::make_unique<ResultSet>(
1763  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1764  const auto storage2 = rs2->allocateStorage();
1765  {
1766  auto buff1 = reinterpret_cast<int64_t*>(storage1->getUnderlyingBuffer());
1767  buff1[0 * 3] = 7;
1768  buff1[1 * 3] = EMPTY_KEY_64;
1769  buff1[2 * 3] = EMPTY_KEY_64;
1770  buff1[0 * 3 + 1] = 7;
1771  buff1[1 * 3 + 1] = 0;
1772  buff1[2 * 3 + 1] = 0;
1773  buff1[0 * 3 + 2] = 15;
1774  buff1[1 * 3 + 2] = 0;
1775  buff1[2 * 3 + 2] = 0;
1776  }
1777  {
1778  auto buff2 = reinterpret_cast<int64_t*>(storage2->getUnderlyingBuffer());
1779  buff2[0 * 3] = EMPTY_KEY_64;
1780  buff2[1 * 3] = EMPTY_KEY_64;
1781  buff2[2 * 3] = 9;
1782  buff2[0 * 3 + 1] = 0;
1783  buff2[1 * 3 + 1] = 0;
1784  buff2[2 * 3 + 1] = 9;
1785  buff2[0 * 3 + 2] = 0;
1786  buff2[1 * 3 + 2] = 0;
1787  buff2[2 * 3 + 2] = 5;
1788  }
1789 #ifdef WITH_REDUCTION_JIT
1790  ResultSetReductionJIT reduction_jit(
1791  rs1->getQueryMemDesc(), rs1->getTargetInfos(), rs1->getTargetInitVals());
1792  const auto reduction_code = reduction_jit.codegen();
1793 #else
1794  ReductionCode reduction_code{};
1795 #endif // WITH_REDUCTION_JIT
1796  storage1->reduce(*storage2, {}, reduction_code);
1797  {
1798  const auto row = rs1->getNextRow(false, false);
1799  CHECK_EQ(size_t(2), row.size());
1800  ASSERT_EQ(7, v<int64_t>(row[0]));
1801  ASSERT_EQ(15, v<int64_t>(row[1]));
1802  }
1803  {
1804  const auto row = rs1->getNextRow(false, false);
1805  CHECK_EQ(size_t(2), row.size());
1806  ASSERT_EQ(9, v<int64_t>(row[0]));
1807  ASSERT_EQ(5, v<int64_t>(row[1]));
1808  }
1809  {
1810  const auto row = rs1->getNextRow(false, false);
1811  ASSERT_EQ(size_t(0), row.size());
1812  }
1813 }
1814 
1815 TEST(MoreReduce, MissingValuesKeyless) {
1816  std::vector<TargetInfo> target_infos;
1817  SQLTypeInfo bigint_ti(kBIGINT, false);
1818  SQLTypeInfo null_ti(kNULLT, false);
1819  target_infos.push_back(TargetInfo{false, kMIN, bigint_ti, null_ti, true, false});
1820  target_infos.push_back(TargetInfo{true, kCOUNT, bigint_ti, null_ti, true, false});
1821  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 7, 9);
1822  query_mem_desc.setHasKeylessHash(true);
1823  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
1824  const auto rs1 = std::make_unique<ResultSet>(
1825  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1826  const auto storage1 = rs1->allocateStorage();
1827  const auto rs2 = std::make_unique<ResultSet>(
1828  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1829  const auto storage2 = rs2->allocateStorage();
1830  {
1831  auto buff1 = reinterpret_cast<int64_t*>(storage1->getUnderlyingBuffer());
1832  buff1[0 * 2] = 7;
1833  buff1[1 * 2] = 0;
1834  buff1[2 * 2] = 0;
1835  buff1[0 * 2 + 1] = 15;
1836  buff1[1 * 2 + 1] = 0;
1837  buff1[2 * 2 + 1] = 0;
1838  }
1839  {
1840  auto buff2 = reinterpret_cast<int64_t*>(storage2->getUnderlyingBuffer());
1841  buff2[0 * 2] = 0;
1842  buff2[1 * 2] = 0;
1843  buff2[2 * 2] = 9;
1844  buff2[0 * 2 + 1] = 0;
1845  buff2[1 * 2 + 1] = 0;
1846  buff2[2 * 2 + 1] = 5;
1847  }
1848 #ifdef WITH_REDUCTION_JIT
1849  ResultSetReductionJIT reduction_jit(
1850  rs1->getQueryMemDesc(), rs1->getTargetInfos(), rs1->getTargetInitVals());
1851  const auto reduction_code = reduction_jit.codegen();
1852 #else
1853  ReductionCode reduction_code{};
1854 #endif // WITH_REDUCTION_JIT
1855  storage1->reduce(*storage2, {}, reduction_code);
1856  {
1857  const auto row = rs1->getNextRow(false, false);
1858  CHECK_EQ(size_t(2), row.size());
1859  ASSERT_EQ(7, v<int64_t>(row[0]));
1860  ASSERT_EQ(15, v<int64_t>(row[1]));
1861  }
1862  {
1863  const auto row = rs1->getNextRow(false, false);
1864  CHECK_EQ(size_t(2), row.size());
1865  ASSERT_EQ(9, v<int64_t>(row[0]));
1866  ASSERT_EQ(5, v<int64_t>(row[1]));
1867  }
1868  {
1869  const auto row = rs1->getNextRow(false, false);
1870  ASSERT_EQ(size_t(0), row.size());
1871  }
1872 }
1873 
1874 TEST(MoreReduce, OffsetRewrite) {
1875  std::vector<TargetInfo> target_infos;
1876  SQLTypeInfo bigint_ti(kBIGINT, false);
1877  SQLTypeInfo real_str_ti(kTEXT, true, kENCODING_NONE);
1878  SQLTypeInfo null_ti(kNULLT, false);
1879 
1880  target_infos.push_back(TargetInfo{false, kMIN, bigint_ti, null_ti, true, false});
1881  target_infos.push_back(TargetInfo{true, kSAMPLE, real_str_ti, null_ti, true, false});
1882  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 7, 9);
1883  query_mem_desc.setHasKeylessHash(false);
1884  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
1885  const auto rs1 = std::make_unique<ResultSet>(
1886  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1887  const auto storage1 = rs1->allocateStorage();
1888  const auto rs2 = std::make_unique<ResultSet>(
1889  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1890  const auto storage2 = rs2->allocateStorage();
1891  std::vector<std::string> serialized_varlen_buffer{"foo", "bar", "hello"};
1892 
1893  {
1894  auto buff1 = reinterpret_cast<int64_t*>(storage1->getUnderlyingBuffer());
1895  buff1[0 * 4] = 7;
1896  buff1[1 * 4] = 8;
1897  buff1[2 * 4] = 9;
1898  buff1[0 * 4 + 1] = 7;
1899  buff1[1 * 4 + 1] = 8;
1900  buff1[2 * 4 + 1] = 9;
1901  buff1[0 * 4 + 2] = 0;
1902  buff1[1 * 4 + 2] = 0;
1903  buff1[2 * 4 + 2] = 1;
1904  buff1[0 * 4 + 3] = 0;
1905  buff1[1 * 4 + 3] = 0;
1906  buff1[2 * 4 + 3] = 0;
1907  }
1908  {
1909  auto buff2 = reinterpret_cast<int64_t*>(storage2->getUnderlyingBuffer());
1910  buff2[0 * 4] = 7;
1911  buff2[1 * 4] = 8;
1912  buff2[2 * 4] = 9;
1913  buff2[0 * 4 + 1] = 7;
1914  buff2[1 * 4 + 1] = 8;
1915  buff2[2 * 4 + 1] = 9;
1916  buff2[0 * 4 + 2] = 0;
1917  buff2[1 * 4 + 2] = 2;
1918  buff2[2 * 4 + 2] = 1;
1919  buff2[0 * 4 + 3] = 0;
1920  buff2[1 * 4 + 3] = 0;
1921  buff2[2 * 4 + 3] = 0;
1922  }
1923 
1924  storage1->rewriteAggregateBufferOffsets(serialized_varlen_buffer);
1925 #ifdef WITH_REDUCTION_JIT
1926  ResultSetReductionJIT reduction_jit(
1927  rs1->getQueryMemDesc(), rs1->getTargetInfos(), rs1->getTargetInitVals());
1928  const auto reduction_code = reduction_jit.codegen();
1929 #else
1930  ReductionCode reduction_code{};
1931 #endif // WITH_REDUCTION_JIT
1932  storage1->reduce(*storage2, serialized_varlen_buffer, reduction_code);
1933  rs1->setSeparateVarlenStorageValid(true);
1934  {
1935  const auto row = rs1->getNextRow(false, false);
1936  CHECK_EQ(size_t(2), row.size());
1937  ASSERT_EQ(7, v<int64_t>(row[0]));
1938  ASSERT_EQ("foo", boost::get<std::string>(v<NullableString>(row[1])));
1939  }
1940  {
1941  const auto row = rs1->getNextRow(false, false);
1942  CHECK_EQ(size_t(2), row.size());
1943  ASSERT_EQ(8, v<int64_t>(row[0]));
1944  ASSERT_EQ("hello", boost::get<std::string>(v<NullableString>(row[1])));
1945  }
1946  {
1947  const auto row = rs1->getNextRow(false, false);
1948  CHECK_EQ(size_t(2), row.size());
1949  ASSERT_EQ(9, v<int64_t>(row[0]));
1950  ASSERT_EQ("bar", boost::get<std::string>(v<NullableString>(row[1])));
1951  }
1952  {
1953  const auto row = rs1->getNextRow(false, false);
1954  ASSERT_EQ(size_t(0), row.size());
1955  }
1956 }
1957 
1958 namespace {
1959 
1960 template <typename T>
1961 std::string arr_to_byte_string(const std::vector<T>& in) {
1962  auto data_ptr = reinterpret_cast<const char*>(in.data());
1963  return std::string(data_ptr, data_ptr + in.size() * sizeof(T));
1964 }
1965 
1966 } // namespace
1967 
1968 TEST(MoreReduce, OffsetRewriteGeo) {
1969  std::vector<TargetInfo> target_infos;
1970  SQLTypeInfo int_ti(kINT, false);
1971  SQLTypeInfo multipoly_ti(kMULTIPOLYGON, false);
1972  SQLTypeInfo null_ti(kNULLT, false);
1973 
1974  target_infos.push_back(TargetInfo{true, kSAMPLE, multipoly_ti, null_ti, true, false});
1975  target_infos.push_back(TargetInfo{true, kSUM, int_ti, int_ti, true, false});
1976 
1977  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 7, 9);
1978  query_mem_desc.setHasKeylessHash(false);
1979  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
1980  const auto rs1 = std::make_unique<ResultSet>(
1981  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1982  const auto storage1 = rs1->allocateStorage();
1983  const auto rs2 = std::make_unique<ResultSet>(
1984  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
1985  const auto storage2 = rs2->allocateStorage();
1986  std::vector<std::string> serialized_varlen_buffer{
1987  arr_to_byte_string(std::vector<double>{1, 1, 2, 2, 3, 3, 4, 4}),
1988  arr_to_byte_string(std::vector<int32_t>{4}),
1989  arr_to_byte_string(std::vector<int32_t>{1}),
1990  arr_to_byte_string(std::vector<double>{1, 1, 2, 2, 3, 3, 4, 4, 5, 5}),
1991  arr_to_byte_string(std::vector<int32_t>{5}),
1992  arr_to_byte_string(std::vector<int32_t>{1})};
1993 
1994  {
1995  auto buff1 = reinterpret_cast<int64_t*>(storage1->getUnderlyingBuffer());
1996  buff1[0 * 8] = 7; // key
1997  buff1[1 * 8] = 8;
1998  buff1[2 * 8] = 9;
1999  buff1[0 * 8 + 1] = 0; // coords
2000  buff1[1 * 8 + 1] = 3;
2001  buff1[2 * 8 + 1] = 0;
2002  buff1[0 * 8 + 3] = 1; // ring sizes
2003  buff1[1 * 8 + 3] = 4;
2004  buff1[2 * 8 + 3] = 1;
2005  buff1[0 * 8 + 5] = 2; // poly rings
2006  buff1[1 * 8 + 5] = 5;
2007  buff1[2 * 8 + 5] = 2;
2008  buff1[0 * 8 + 7] = 1; // int argument to sum
2009  buff1[1 * 8 + 7] = 2;
2010  buff1[2 * 8 + 7] = 3;
2011  }
2012  {
2013  auto buff2 = reinterpret_cast<int64_t*>(storage2->getUnderlyingBuffer());
2014  buff2[0 * 8] = 7; // key
2015  buff2[1 * 8] = 8;
2016  buff2[2 * 8] = 9;
2017  buff2[0 * 8 + 1] = 0; // coords
2018  buff2[1 * 8 + 1] = 3;
2019  buff2[2 * 8 + 1] = 0;
2020  buff2[0 * 8 + 3] = 1; // ring sizes
2021  buff2[1 * 8 + 3] = 4;
2022  buff2[2 * 8 + 3] = 1;
2023  buff2[0 * 8 + 5] = 2; // poly rings
2024  buff2[1 * 8 + 5] = 5;
2025  buff2[2 * 8 + 5] = 2;
2026  buff2[0 * 8 + 7] = 4; // int argument to sum
2027  buff2[1 * 8 + 7] = 5;
2028  buff2[2 * 8 + 7] = 6;
2029  }
2030 
2031  storage1->rewriteAggregateBufferOffsets(serialized_varlen_buffer);
2032 #ifdef WITH_REDUCTION_JIT
2033  ResultSetReductionJIT reduction_jit(
2034  rs1->getQueryMemDesc(), rs1->getTargetInfos(), rs1->getTargetInitVals());
2035  const auto reduction_code = reduction_jit.codegen();
2036 #else
2037  ReductionCode reduction_code{};
2038 #endif // WITH_REDUCTION_JIT
2039  storage1->reduce(*storage2, serialized_varlen_buffer, reduction_code);
2040  rs1->setGeoReturnType(ResultSet::GeoReturnType::WktString);
2041  rs1->setSeparateVarlenStorageValid(true);
2042  {
2043  const auto row = rs1->getNextRow(false, false);
2044  CHECK_EQ(size_t(2), row.size());
2045  ASSERT_EQ("MULTIPOLYGON (((1 1,2 2,3 3,4 4,1 1)))",
2046  boost::get<std::string>(v<NullableString>(row[0])));
2047  ASSERT_EQ(5, v<int64_t>(row[1]));
2048  }
2049  {
2050  const auto row = rs1->getNextRow(false, false);
2051  CHECK_EQ(size_t(2), row.size());
2052  ASSERT_EQ("MULTIPOLYGON (((1 1,2 2,3 3,4 4,5 5,1 1)))",
2053  boost::get<std::string>(v<NullableString>(row[0])));
2054  ASSERT_EQ(7, v<int64_t>(row[1]));
2055  }
2056  {
2057  const auto row = rs1->getNextRow(false, false);
2058  CHECK_EQ(size_t(2), row.size());
2059  ASSERT_EQ("MULTIPOLYGON (((1 1,2 2,3 3,4 4,1 1)))",
2060  boost::get<std::string>(v<NullableString>(row[0])));
2061  ASSERT_EQ(9, v<int64_t>(row[1]));
2062  }
2063  {
2064  const auto row = rs1->getNextRow(false, false);
2065  ASSERT_EQ(size_t(0), row.size());
2066  }
2067 }
2068 
2069 TEST(MoreReduce, OffsetRewriteGeoKeyless) {
2070  std::vector<TargetInfo> target_infos;
2071  SQLTypeInfo int_ti(kINT, false);
2072  SQLTypeInfo multipoly_ti(kMULTIPOLYGON, false);
2073  SQLTypeInfo null_ti(kNULLT, false);
2074 
2075  target_infos.push_back(TargetInfo{false, kCOUNT, int_ti, null_ti, true, false});
2076  target_infos.push_back(TargetInfo{true, kSAMPLE, multipoly_ti, null_ti, true, false});
2077  target_infos.push_back(TargetInfo{true, kSUM, int_ti, int_ti, true, false});
2078 
2079  auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 7, 9);
2080  query_mem_desc.setHasKeylessHash(true);
2081  query_mem_desc.setTargetIdxForKey(0);
2082  const auto row_set_mem_owner = std::make_shared<RowSetMemoryOwner>();
2083  const auto rs1 = std::make_unique<ResultSet>(
2084  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
2085  const auto storage1 = rs1->allocateStorage();
2086  const auto rs2 = std::make_unique<ResultSet>(
2087  target_infos, ExecutorDeviceType::CPU, query_mem_desc, row_set_mem_owner, nullptr);
2088  const auto storage2 = rs2->allocateStorage();
2089  std::vector<std::string> serialized_varlen_buffer{
2090  arr_to_byte_string(std::vector<double>{1, 1, 2, 2, 3, 3, 4, 4}),
2091  arr_to_byte_string(std::vector<int32_t>{4}),
2092  arr_to_byte_string(std::vector<int32_t>{1}),
2093  arr_to_byte_string(std::vector<double>{1, 1, 2, 2, 3, 3, 4, 4, 5, 5}),
2094  arr_to_byte_string(std::vector<int32_t>{5}),
2095  arr_to_byte_string(std::vector<int32_t>{1})};
2096 
2097  {
2098  auto buff1 = reinterpret_cast<int64_t*>(storage1->getUnderlyingBuffer());
2099  buff1[0 * 8] = 7; // key
2100  buff1[1 * 8] = 8;
2101  buff1[2 * 8] = 9;
2102  buff1[0 * 8 + 1] = 0; // coords
2103  buff1[1 * 8 + 1] = 3;
2104  buff1[2 * 8 + 1] = 0;
2105  buff1[0 * 8 + 3] = 1; // ring sizes
2106  buff1[1 * 8 + 3] = 4;
2107  buff1[2 * 8 + 3] = 1;
2108  buff1[0 * 8 + 5] = 2; // poly rings
2109  buff1[1 * 8 + 5] = 5;
2110  buff1[2 * 8 + 5] = 2;
2111  buff1[0 * 8 + 7] = 1; // int argument to sum
2112  buff1[1 * 8 + 7] = 2;
2113  buff1[2 * 8 + 7] = 3;
2114  }
2115  {
2116  auto buff2 = reinterpret_cast<int64_t*>(storage2->getUnderlyingBuffer());
2117  buff2[0 * 8] = 7; // key
2118  buff2[1 * 8] = 8;
2119  buff2[2 * 8] = 9;
2120  buff2[0 * 8 + 1] = 0; // coords
2121  buff2[1 * 8 + 1] = 3;
2122  buff2[2 * 8 + 1] = 0;
2123  buff2[0 * 8 + 3] = 1; // ring sizes
2124  buff2[1 * 8 + 3] = 4;
2125  buff2[2 * 8 + 3] = 1;
2126  buff2[0 * 8 + 5] = 2; // poly rings
2127  buff2[1 * 8 + 5] = 5;
2128  buff2[2 * 8 + 5] = 2;
2129  buff2[0 * 8 + 7] = 4; // int argument to sum
2130  buff2[1 * 8 + 7] = 5;
2131  buff2[2 * 8 + 7] = 6;
2132  }
2133 
2134  storage1->rewriteAggregateBufferOffsets(serialized_varlen_buffer);
2135 #ifdef WITH_REDUCTION_JIT
2136  ResultSetReductionJIT reduction_jit(
2137  rs1->getQueryMemDesc(), rs1->getTargetInfos(), rs1->getTargetInitVals());
2138  const auto reduction_code = reduction_jit.codegen();
2139 #else
2140  ReductionCode reduction_code{};
2141 #endif // WITH_REDUCTION_JIT
2142  storage1->reduce(*storage2, serialized_varlen_buffer, reduction_code);
2143  rs1->setGeoReturnType(ResultSet::GeoReturnType::WktString);
2144  rs1->setSeparateVarlenStorageValid(true);
2145  {
2146  const auto row = rs1->getNextRow(false, false);
2147  CHECK_EQ(size_t(3), row.size());
2148  ASSERT_EQ(7, v<int64_t>(row[0]));
2149  ASSERT_EQ("MULTIPOLYGON (((1 1,2 2,3 3,4 4,1 1)))",
2150  boost::get<std::string>(v<NullableString>(row[1])));
2151  ASSERT_EQ(5, v<int64_t>(row[2]));
2152  }
2153  {
2154  const auto row = rs1->getNextRow(false, false);
2155  CHECK_EQ(size_t(3), row.size());
2156  ASSERT_EQ(8, v<int64_t>(row[0]));
2157  ASSERT_EQ("MULTIPOLYGON (((1 1,2 2,3 3,4 4,5 5,1 1)))",
2158  boost::get<std::string>(v<NullableString>(row[1])));
2159  ASSERT_EQ(7, v<int64_t>(row[2]));
2160  }
2161  {
2162  const auto row = rs1->getNextRow(false, false);
2163  CHECK_EQ(size_t(3), row.size());
2164  ASSERT_EQ(9, v<int64_t>(row[0]));
2165  ASSERT_EQ("MULTIPOLYGON (((1 1,2 2,3 3,4 4,1 1)))",
2166  boost::get<std::string>(v<NullableString>(row[1])));
2167  ASSERT_EQ(9, v<int64_t>(row[2]));
2168  }
2169  {
2170  const auto row = rs1->getNextRow(false, false);
2171  ASSERT_EQ(size_t(0), row.size());
2172  }
2173 }
2174 
2175 /* FLOW #1: Perfect_Hash_Row_Based testcases */
2176 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_2525) {
2177  const auto target_infos = generate_random_groups_target_infos();
2178  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2179  // const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
2180  EvenNumberGenerator gen1;
2181  EvenNumberGenerator gen2;
2182  const int prct1 = 25, prct2 = 25;
2183  bool silent = false; // true/false - don't/do print diagnostic messages
2184  silent = true;
2186  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2187 }
2188 
2189 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_2575) {
2190  const auto target_infos = generate_random_groups_target_infos();
2191  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2192  // const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
2193  EvenNumberGenerator gen1;
2194  EvenNumberGenerator gen2;
2195  const int prct1 = 25, prct2 = 75;
2196  bool silent = false; // true/false - don't/do print diagnostic messages
2197  silent = true;
2199  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2200 }
2201 
2202 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_5050) {
2203  const auto target_infos = generate_random_groups_target_infos();
2204  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2205  // const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
2206  EvenNumberGenerator gen1;
2207  EvenNumberGenerator gen2;
2208  const int prct1 = 50, prct2 = 50;
2209  bool silent = false; // true/false - don't/do print diagnostic messages
2210  silent = true;
2212  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2213 }
2214 
2215 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_7525) {
2216  const auto target_infos = generate_random_groups_target_infos();
2217  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2218  // const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
2219  EvenNumberGenerator gen1;
2220  EvenNumberGenerator gen2;
2221  const int prct1 = 75, prct2 = 25;
2222  bool silent = false; // true/false - don't/do print diagnostic messages
2223  silent = true;
2225  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2226 }
2227 
2228 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_25100) {
2229  const auto target_infos = generate_random_groups_target_infos();
2230  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2231  // const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
2232  EvenNumberGenerator gen1;
2233  EvenNumberGenerator gen2;
2234  const int prct1 = 25, prct2 = 100;
2235  bool silent = false; // true/false - don't/do print diagnostic messages
2236  silent = true;
2238  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2239 }
2240 
2241 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_10025) {
2242  const auto target_infos = generate_random_groups_target_infos();
2243  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2244  // const auto query_mem_desc = perfect_hash_one_col_desc(target_infos, 8, 0, 99);
2245  EvenNumberGenerator gen1;
2246  EvenNumberGenerator gen2;
2247  const int prct1 = 100, prct2 = 25;
2248  bool silent = false; // true/false - don't/do print diagnostic messages
2249  silent = true;
2251  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2252 }
2253 
2254 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_9505) {
2255  const auto target_infos = generate_random_groups_target_infos();
2256  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2257  EvenNumberGenerator gen1;
2258  EvenNumberGenerator gen2;
2259  const int prct1 = 95, prct2 = 5;
2260  bool silent = false; // true/false - don't/do print diagnostic messages
2261  silent = true;
2263  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2264 }
2265 
2266 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_100100) {
2267  const auto target_infos = generate_random_groups_target_infos();
2268  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2269  EvenNumberGenerator gen1;
2270  EvenNumberGenerator gen2;
2271  const int prct1 = 100, prct2 = 100;
2272  bool silent = false; // true/false - don't/do print diagnostic messages
2273  silent = true;
2275  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2276 }
2277 
2278 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_2500) {
2279  const auto target_infos = generate_random_groups_target_infos();
2280  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2281  EvenNumberGenerator gen1;
2282  EvenNumberGenerator gen2;
2283  const int prct1 = 25, prct2 = 0;
2284  bool silent = false; // true/false - don't/do print diagnostic messages
2285  silent = true;
2287  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2288 }
2289 
2290 TEST(ReduceRandomGroups, PerfectHashOneCol_Small_0075) {
2291  const auto target_infos = generate_random_groups_target_infos();
2292  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2293  EvenNumberGenerator gen1;
2294  EvenNumberGenerator gen2;
2295  const int prct1 = 0, prct2 = 75;
2296  bool silent = false; // true/false - don't/do print diagnostic messages
2297  silent = true;
2299  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2300 }
2301 
2302 /* FLOW #2: Non_Perfect_Hash_Row_Based testcases */
2303 TEST(ReduceRandomGroups, BaselineHash_Large_5050) {
2304  const auto target_infos = generate_random_groups_target_infos();
2305  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2306  EvenNumberGenerator gen1;
2307  EvenNumberGenerator gen2;
2308  const int prct1 = 50, prct2 = 50;
2309  bool silent = false; // true/false - don't/do print diagnostic messages
2310  silent = true;
2312  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2313 }
2314 
2315 TEST(ReduceRandomGroups, BaselineHash_Large_7525) {
2316  const auto target_infos = generate_random_groups_target_infos();
2317  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2318  EvenNumberGenerator gen1;
2319  EvenNumberGenerator gen2;
2320  const int prct1 = 75, prct2 = 25;
2321  bool silent = false; // true/false - don't/do print diagnostic messages
2322  silent = true;
2324  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2325 }
2326 
2327 TEST(ReduceRandomGroups, BaselineHash_Large_2575) {
2328  const auto target_infos = generate_random_groups_target_infos();
2329  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2330  EvenNumberGenerator gen1;
2331  EvenNumberGenerator gen2;
2332  const int prct1 = 25, prct2 = 75;
2333  bool silent = false; // true/false - don't/do print diagnostic messages
2334  silent = true;
2336  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2337 }
2338 
2339 TEST(ReduceRandomGroups, BaselineHash_Large_1020) {
2340  const auto target_infos = generate_random_groups_target_infos();
2341  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2342  EvenNumberGenerator gen1;
2343  EvenNumberGenerator gen2;
2344  const int prct1 = 10, prct2 = 20;
2345  bool silent = false; // true/false - don't/do print diagnostic messages
2346  silent = true;
2348  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2349 }
2350 
2351 TEST(ReduceRandomGroups, BaselineHash_Large_100100) {
2352  const auto target_infos = generate_random_groups_target_infos();
2353  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2354  EvenNumberGenerator gen1;
2355  EvenNumberGenerator gen2;
2356  const int prct1 = 100, prct2 = 100;
2357  bool silent = false; // true/false - don't/do print diagnostic messages
2358  silent = true;
2360  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2361 }
2362 
2363 TEST(ReduceRandomGroups, BaselineHash_Large_2500) {
2364  const auto target_infos = generate_random_groups_target_infos();
2365  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2366  EvenNumberGenerator gen1;
2367  EvenNumberGenerator gen2;
2368  const int prct1 = 25, prct2 = 0;
2369  bool silent = false; // true/false - don't/do print diagnostic messages
2370  silent = true;
2372  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2373 }
2374 
2375 TEST(ReduceRandomGroups, BaselineHash_Large_0075) {
2376  const auto target_infos = generate_random_groups_target_infos();
2377  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2378  EvenNumberGenerator gen1;
2379  EvenNumberGenerator gen2;
2380  const int prct1 = 0, prct2 = 75;
2381  bool silent = false; // true/false - don't/do print diagnostic messages
2382  silent = true;
2384  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2385 }
2386 
2387 /* FLOW #3: Perfect_Hash_Column_Based testcases */
2388 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_Small_5050) {
2389  const auto target_infos = generate_random_groups_target_infos();
2390  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2391  query_mem_desc.setOutputColumnar(true);
2392  EvenNumberGenerator gen1;
2393  EvenNumberGenerator gen2;
2394  const int prct1 = 50, prct2 = 50;
2395  bool silent = false; // true/false - don't/do print diagnostic messages
2396  silent = true;
2398  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2399 }
2400 
2401 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_Small_25100) {
2402  const auto target_infos = generate_random_groups_target_infos();
2403  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2404  query_mem_desc.setOutputColumnar(true);
2405  EvenNumberGenerator gen1;
2406  EvenNumberGenerator gen2;
2407  const int prct1 = 25, prct2 = 100;
2408  bool silent = false; // true/false - don't/do print diagnostic messages
2409  silent = true;
2411  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2412 }
2413 
2414 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_Small_10025) {
2415  const auto target_infos = generate_random_groups_target_infos();
2416  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2417  query_mem_desc.setOutputColumnar(true);
2418  EvenNumberGenerator gen1;
2419  EvenNumberGenerator gen2;
2420  const int prct1 = 100, prct2 = 25;
2421  bool silent = false; // true/false - don't/do print diagnostic messages
2422  silent = true;
2424  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2425 }
2426 
2427 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_Small_100100) {
2428  const auto target_infos = generate_random_groups_target_infos();
2429  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2430  query_mem_desc.setOutputColumnar(true);
2431  EvenNumberGenerator gen1;
2432  EvenNumberGenerator gen2;
2433  const int prct1 = 100, prct2 = 100;
2434  bool silent = false; // true/false - don't/do print diagnostic messages
2435  silent = true;
2437  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2438 }
2439 
2440 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_Small_2500) {
2441  const auto target_infos = generate_random_groups_target_infos();
2442  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2443  query_mem_desc.setOutputColumnar(true);
2444  EvenNumberGenerator gen1;
2445  EvenNumberGenerator gen2;
2446  const int prct1 = 25, prct2 = 0;
2447  bool silent = false; // true/false - don't/do print diagnostic messages
2448  silent = true;
2450  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2451 }
2452 
2453 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_Small_0075) {
2454  const auto target_infos = generate_random_groups_target_infos();
2455  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2456  query_mem_desc.setOutputColumnar(true);
2457  EvenNumberGenerator gen1;
2458  EvenNumberGenerator gen2;
2459  const int prct1 = 0, prct2 = 75;
2460  bool silent = false; // true/false - don't/do print diagnostic messages
2461  silent = true;
2463  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2464 }
2465 
2466 /* FLOW #4: Non_Perfect_Hash_Column_Based testcases */
2467 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_5050) {
2468  const auto target_infos = generate_random_groups_target_infos();
2469  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2470  query_mem_desc.setOutputColumnar(true);
2471  EvenNumberGenerator gen1;
2472  EvenNumberGenerator gen2;
2473  const int prct1 = 50, prct2 = 50;
2474  bool silent = false; // true/false - don't/do print diagnostic messages
2475  silent = true;
2477  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2478 }
2479 
2480 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_25100) {
2481  const auto target_infos = generate_random_groups_target_infos();
2482  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2483  query_mem_desc.setOutputColumnar(true);
2484  EvenNumberGenerator gen1;
2485  EvenNumberGenerator gen2;
2486  const int prct1 = 25, prct2 = 100;
2487  bool silent = false; // true/false - don't/do print diagnostic messages
2488  silent = true;
2490  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2491 }
2492 
2493 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_10025) {
2494  const auto target_infos = generate_random_groups_target_infos();
2495  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2496  query_mem_desc.setOutputColumnar(true);
2497  EvenNumberGenerator gen1;
2498  EvenNumberGenerator gen2;
2499  const int prct1 = 100, prct2 = 25;
2500  bool silent = false; // true/false - don't/do print diagnostic messages
2501  silent = true;
2503  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2504 }
2505 
2506 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_100100) {
2507  const auto target_infos = generate_random_groups_target_infos();
2508  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2509  query_mem_desc.setOutputColumnar(true);
2510  EvenNumberGenerator gen1;
2511  EvenNumberGenerator gen2;
2512  const int prct1 = 100, prct2 = 100;
2513  bool silent = false; // true/false - don't/do print diagnostic messages
2514  silent = true;
2516  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2517 }
2518 
2519 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_2500) {
2520  const auto target_infos = generate_random_groups_target_infos();
2521  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2522  query_mem_desc.setOutputColumnar(true);
2523  EvenNumberGenerator gen1;
2524  EvenNumberGenerator gen2;
2525  const int prct1 = 25, prct2 = 0;
2526  bool silent = false; // true/false - don't/do print diagnostic messages
2527  silent = true;
2529  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2530 }
2531 
2532 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_0075) {
2533  const auto target_infos = generate_random_groups_target_infos();
2534  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2535  query_mem_desc.setOutputColumnar(true);
2536  EvenNumberGenerator gen1;
2537  EvenNumberGenerator gen2;
2538  const int prct1 = 0, prct2 = 75;
2539  bool silent = false; // true/false - don't/do print diagnostic messages
2540  silent = true;
2542  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent);
2543 }
2544 
2545 /* FLOW #5: Perfect_Hash_Row_Based_NullVal testcases */
2546 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_2525) {
2547  const auto target_infos = generate_random_groups_nullable_target_infos();
2548  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2549  EvenNumberGenerator gen1;
2550  EvenNumberGenerator gen2;
2551  const int prct1 = 25, prct2 = 25;
2552  ASSERT_LE(prct1, 100);
2553  ASSERT_LE(prct2, 100);
2554  bool silent = false; // true/false - don't/do print diagnostic messages
2555  silent = true;
2557  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2558 }
2559 
2560 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_2575) {
2561  const auto target_infos = generate_random_groups_nullable_target_infos();
2562  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2563  EvenNumberGenerator gen1;
2564  EvenNumberGenerator gen2;
2565  const int prct1 = 25, prct2 = 75;
2566  ASSERT_LE(prct1, 100);
2567  ASSERT_LE(prct2, 100);
2568  bool silent = false; // true/false - don't/do print diagnostic messages
2569  silent = true;
2571  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2572 }
2573 
2574 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_5050) {
2575  const auto target_infos = generate_random_groups_nullable_target_infos();
2576  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2577  EvenNumberGenerator gen1;
2578  EvenNumberGenerator gen2;
2579  const int prct1 = 50, prct2 = 50;
2580  ASSERT_LE(prct1, 100);
2581  ASSERT_LE(prct2, 100);
2582  bool silent = false; // true/false - don't/do print diagnostic messages
2583  silent = true;
2585  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2586 }
2587 
2588 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_7525) {
2589  const auto target_infos = generate_random_groups_nullable_target_infos();
2590  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2591  EvenNumberGenerator gen1;
2592  EvenNumberGenerator gen2;
2593  const int prct1 = 75, prct2 = 25;
2594  ASSERT_LE(prct1, 100);
2595  ASSERT_LE(prct2, 100);
2596  bool silent = false; // true/false - don't/do print diagnostic messages
2597  silent = true;
2599  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2600 }
2601 
2602 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_25100) {
2603  const auto target_infos = generate_random_groups_nullable_target_infos();
2604  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2605  EvenNumberGenerator gen1;
2606  EvenNumberGenerator gen2;
2607  const int prct1 = 25, prct2 = 100;
2608  ASSERT_LE(prct1, 100);
2609  ASSERT_LE(prct2, 100);
2610  bool silent = false; // true/false - don't/do print diagnostic messages
2611  silent = true;
2613  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2614 }
2615 
2616 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_10025) {
2617  const auto target_infos = generate_random_groups_nullable_target_infos();
2618  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2619  EvenNumberGenerator gen1;
2620  EvenNumberGenerator gen2;
2621  const int prct1 = 100, prct2 = 25;
2622  ASSERT_LE(prct1, 100);
2623  ASSERT_LE(prct2, 100);
2624  bool silent = false; // true/false - don't/do print diagnostic messages
2625  silent = true;
2627  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2628 }
2629 
2630 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_100100) {
2631  const auto target_infos = generate_random_groups_nullable_target_infos();
2632  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2633  EvenNumberGenerator gen1;
2634  EvenNumberGenerator gen2;
2635  const int prct1 = 100, prct2 = 100;
2636  ASSERT_LE(prct1, 100);
2637  ASSERT_LE(prct2, 100);
2638  bool silent = false; // true/false - don't/do print diagnostic messages
2639  silent = true;
2641  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2642 }
2643 
2644 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_2500) {
2645  const auto target_infos = generate_random_groups_nullable_target_infos();
2646  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2647  EvenNumberGenerator gen1;
2648  EvenNumberGenerator gen2;
2649  const int prct1 = 25, prct2 = 0;
2650  ASSERT_LE(prct1, 100);
2651  ASSERT_LE(prct2, 100);
2652  bool silent = false; // true/false - don't/do print diagnostic messages
2653  silent = true;
2655  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2656 }
2657 
2658 TEST(ReduceRandomGroups, PerfectHashOneCol_NullVal_0075) {
2659  const auto target_infos = generate_random_groups_nullable_target_infos();
2660  const auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2661  EvenNumberGenerator gen1;
2662  EvenNumberGenerator gen2;
2663  const int prct1 = 0, prct2 = 75;
2664  ASSERT_LE(prct1, 100);
2665  ASSERT_LE(prct2, 100);
2666  bool silent = false; // true/false - don't/do print diagnostic messages
2667  silent = true;
2669  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2670 }
2671 
2672 /* FLOW #6: Perfect_Hash_Column_Based_NullVal testcases */
2673 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_NullVal_5050) {
2674  const auto target_infos = generate_random_groups_nullable_target_infos();
2675  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2676  query_mem_desc.setOutputColumnar(true);
2677  EvenNumberGenerator gen1;
2678  EvenNumberGenerator gen2;
2679  const int prct1 = 50, prct2 = 50;
2680  bool silent = false; // true/false - don't/do print diagnostic messages
2681  silent = true;
2683  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2684 }
2685 
2686 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_NullVal_25100) {
2687  const auto target_infos = generate_random_groups_nullable_target_infos();
2688  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2689  query_mem_desc.setOutputColumnar(true);
2690  EvenNumberGenerator gen1;
2691  EvenNumberGenerator gen2;
2692  const int prct1 = 25, prct2 = 100;
2693  bool silent = false; // true/false - don't/do print diagnostic messages
2694  silent = true;
2696  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2697 }
2698 
2699 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_NullVal_10025) {
2700  const auto target_infos = generate_random_groups_nullable_target_infos();
2701  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2702  query_mem_desc.setOutputColumnar(true);
2703  EvenNumberGenerator gen1;
2704  EvenNumberGenerator gen2;
2705  const int prct1 = 100, prct2 = 25;
2706  bool silent = false; // true/false - don't/do print diagnostic messages
2707  silent = true;
2709  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2710 }
2711 
2712 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_NullVal_100100) {
2713  const auto target_infos = generate_random_groups_nullable_target_infos();
2714  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2715  query_mem_desc.setOutputColumnar(true);
2716  EvenNumberGenerator gen1;
2717  EvenNumberGenerator gen2;
2718  const int prct1 = 100, prct2 = 100;
2719  bool silent = false; // true/false - don't/do print diagnostic messages
2720  silent = true;
2722  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2723 }
2724 
2725 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_NullVal_2500) {
2726  const auto target_infos = generate_random_groups_nullable_target_infos();
2727  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2728  query_mem_desc.setOutputColumnar(true);
2729  EvenNumberGenerator gen1;
2730  EvenNumberGenerator gen2;
2731  const int prct1 = 25, prct2 = 0;
2732  bool silent = false; // true/false - don't/do print diagnostic messages
2733  silent = true;
2735  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2736 }
2737 
2738 TEST(ReduceRandomGroups, PerfectHashOneColColumnar_NullVal_0075) {
2739  const auto target_infos = generate_random_groups_nullable_target_infos();
2740  auto query_mem_desc = perfect_hash_one_col_desc_small(target_infos, 8);
2741  query_mem_desc.setOutputColumnar(true);
2742  EvenNumberGenerator gen1;
2743  EvenNumberGenerator gen2;
2744  const int prct1 = 0, prct2 = 75;
2745  bool silent = false; // true/false - don't/do print diagnostic messages
2746  silent = true;
2748  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2749 }
2750 
2751 /* FLOW #7: Non_Perfect_Hash_Row_Based_NullVal testcases */
2752 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_5050) {
2753  const auto target_infos = generate_random_groups_nullable_target_infos();
2754  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2755  EvenNumberGenerator gen1;
2756  EvenNumberGenerator gen2;
2757  const int prct1 = 50, prct2 = 50;
2758  bool silent = false; // true/false - don't/do print diagnostic messages
2759  silent = true;
2761  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2762 }
2763 
2764 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_7525) {
2765  const auto target_infos = generate_random_groups_nullable_target_infos();
2766  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2767  EvenNumberGenerator gen1;
2768  EvenNumberGenerator gen2;
2769  const int prct1 = 75, prct2 = 25;
2770  bool silent = false; // true/false - don't/do print diagnostic messages
2771  silent = true;
2773  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2774 }
2775 
2776 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_2575) {
2777  const auto target_infos = generate_random_groups_nullable_target_infos();
2778  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2779  EvenNumberGenerator gen1;
2780  EvenNumberGenerator gen2;
2781  const int prct1 = 25, prct2 = 75;
2782  bool silent = false; // true/false - don't/do print diagnostic messages
2783  silent = true;
2785  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2786 }
2787 
2788 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_1020) {
2789  const auto target_infos = generate_random_groups_nullable_target_infos();
2790  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2791  EvenNumberGenerator gen1;
2792  EvenNumberGenerator gen2;
2793  const int prct1 = 10, prct2 = 20;
2794  bool silent = false; // true/false - don't/do print diagnostic messages
2795  silent = true;
2797  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2798 }
2799 
2800 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_100100) {
2801  const auto target_infos = generate_random_groups_nullable_target_infos();
2802  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2803  EvenNumberGenerator gen1;
2804  EvenNumberGenerator gen2;
2805  const int prct1 = 100, prct2 = 100;
2806  bool silent = false; // true/false - don't/do print diagnostic messages
2807  silent = true;
2809  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2810 }
2811 
2812 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_2500) {
2813  const auto target_infos = generate_random_groups_nullable_target_infos();
2814  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2815  EvenNumberGenerator gen1;
2816  EvenNumberGenerator gen2;
2817  const int prct1 = 25, prct2 = 0;
2818  bool silent = false; // true/false - don't/do print diagnostic messages
2819  silent = true;
2821  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2822 }
2823 
2824 TEST(ReduceRandomGroups, BaselineHash_Large_NullVal_0075) {
2825  const auto target_infos = generate_random_groups_nullable_target_infos();
2826  const auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2827  EvenNumberGenerator gen1;
2828  EvenNumberGenerator gen2;
2829  const int prct1 = 0, prct2 = 75;
2830  bool silent = false; // true/false - don't/do print diagnostic messages
2831  silent = true;
2833  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2834 }
2835 
2836 /* FLOW #8: Non_Perfect_Hash_Column_Based_NullVal testcases */
2837 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_NullVal_5050) {
2838  const auto target_infos = generate_random_groups_nullable_target_infos();
2839  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2840  query_mem_desc.setOutputColumnar(true);
2841  EvenNumberGenerator gen1;
2842  EvenNumberGenerator gen2;
2843  const int prct1 = 50, prct2 = 50;
2844  bool silent = false; // true/false - don't/do print diagnostic messages
2845  silent = true;
2847  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2848 }
2849 
2850 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_NullVal_25100) {
2851  const auto target_infos = generate_random_groups_nullable_target_infos();
2852  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2853  query_mem_desc.setOutputColumnar(true);
2854  EvenNumberGenerator gen1;
2855  EvenNumberGenerator gen2;
2856  const int prct1 = 25, prct2 = 100;
2857  bool silent = false; // true/false - don't/do print diagnostic messages
2858  silent = true;
2860  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2861 }
2862 
2863 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_NullVal_10025) {
2864  const auto target_infos = generate_random_groups_nullable_target_infos();
2865  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2866  query_mem_desc.setOutputColumnar(true);
2867  EvenNumberGenerator gen1;
2868  EvenNumberGenerator gen2;
2869  const int prct1 = 100, prct2 = 25;
2870  bool silent = false; // true/false - don't/do print diagnostic messages
2871  silent = true;
2873  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2874 }
2875 
2876 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_NullVal_100100) {
2877  const auto target_infos = generate_random_groups_nullable_target_infos();
2878  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2879  query_mem_desc.setOutputColumnar(true);
2880  EvenNumberGenerator gen1;
2881  EvenNumberGenerator gen2;
2882  const int prct1 = 100, prct2 = 100;
2883  bool silent = false; // true/false - don't/do print diagnostic messages
2884  silent = true;
2886  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2887 }
2888 
2889 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_NullVal_2500) {
2890  const auto target_infos = generate_random_groups_nullable_target_infos();
2891  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2892  query_mem_desc.setOutputColumnar(true);
2893  EvenNumberGenerator gen1;
2894  EvenNumberGenerator gen2;
2895  const int prct1 = 25, prct2 = 0;
2896  bool silent = false; // true/false - don't/do print diagnostic messages
2897  silent = true;
2899  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2900 }
2901 
2902 TEST(ReduceRandomGroups, BaselineHashColumnar_Large_NullVal_0075) {
2903  const auto target_infos = generate_random_groups_nullable_target_infos();
2904  auto query_mem_desc = baseline_hash_two_col_desc_large(target_infos, 8);
2905  query_mem_desc.setOutputColumnar(true);
2906  EvenNumberGenerator gen1;
2907  EvenNumberGenerator gen2;
2908  const int prct1 = 0, prct2 = 75;
2909  bool silent = false; // true/false - don't/do print diagnostic messages
2910  silent = true;
2912  target_infos, query_mem_desc, gen1, gen2, prct1, prct2, silent, 2);
2913 }
2914 
2915 int main(int argc, char** argv) {
2917  testing::InitGoogleTest(&argc, argv);
2918 
2919  int err{0};
2920  try {
2921  err = RUN_ALL_TESTS();
2922  } catch (const std::exception& e) {
2923  LOG(ERROR) << e.what();
2924  }
2926  return err;
2927 }
void print_merged_result_sets(const std::vector< OneRow > &result)
size_t slot_offset_rowwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t slot_count)
#define CHECK_EQ(x, y)
Definition: Logger.h:195
NEVER_INLINE DEVICE int64_t * get_group_value_columnar(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_qw_count)
#define EMPTY_KEY_64
QueryMemoryDescriptor perfect_hash_one_col_desc_small(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
size_t slot_offset_colwise(const size_t entry_idx, const size_t slot_idx, const size_t key_count, const size_t entry_count)
void fill_one_entry_one_col(int8_t *ptr1, const int8_t compact_sz1, int8_t *ptr2, const int8_t compact_sz2, int64_t v, const TargetInfo &target_info, const bool empty_entry, const bool null_val)
T advance_to_next_columnar_target_buff(T target_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t target_slot_idx)
#define LOG(tag)
Definition: Logger.h:182
int8_t * advance_to_next_columnar_key_buff(int8_t *key_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t key_idx)
void test_reduce_random_groups(const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator1, NumberGenerator &generator2, const int prct1, const int prct2, bool silent, const int flow=0)
QueryMemoryDescriptor baseline_hash_two_col_desc_large(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
std::vector< OneRow > get_rows_sorted_by_col(ResultSet &rs, const size_t col_idx)
void set_compression(EncodingType c)
Definition: sqltypes.h:423
ReductionCode codegen() const
std::string to_string(char const *&&v)
size_t get_slot_count(const std::vector< TargetInfo > &target_infos)
Definition: sqldefs.h:71
QueryMemoryDescriptor perfect_hash_one_col_desc(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes, const size_t min_val, const size_t max_val, std::vector< int8_t > group_column_widths)
std::string arr_to_byte_string(const std::vector< T > &in)
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
T v(const TargetValue &r)
std::shared_ptr< StringDictionary > g_sd
Definition: sqldefs.h:71
bool approx_eq(const double v, const double target, const double eps=0.01)
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)
virtual void reset()=0
void test_iterate(const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc)
std::vector< TargetInfo > generate_random_groups_target_infos()
size_t key_offset_colwise(const size_t entry_idx, const size_t key_idx, const size_t entry_count)
int8_t * fill_one_entry_no_collisions(int8_t *buff, const QueryMemoryDescriptor &query_mem_desc, const int64_t v, const std::vector< TargetInfo > &target_infos, const bool empty, const bool null_val)
Definition: sqltypes.h:54
#define CHECK_LE(x, y)
Definition: Logger.h:198
std::vector< TargetInfo > generate_random_groups_nullable_target_infos()
Definition: sqldefs.h:71
std::vector< TargetInfo > generate_test_target_infos()
size_t key_offset_rowwise(const size_t entry_idx, const size_t key_count, const size_t slot_count)
std::vector< TargetValue > OneRow
void set_comp_param(int p)
Definition: sqltypes.h:424
QueryMemoryDescriptor perfect_hash_two_col_desc(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
std::queue< std::vector< int64_t > > getReferenceTable() const
TEST(Construct, Allocate)
#define CHECK(condition)
Definition: Logger.h:187
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
void fill_one_entry_baseline(int64_t *value_slots, const int64_t v, const std::vector< TargetInfo > &target_infos, const bool empty, const bool null_val)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:47
virtual int64_t getNextValue()=0
int main(int argc, char **argv)
std::queue< std::vector< int64_t > > rseReducedTable
QueryDescriptionType getQueryDescriptionType() const
Definition: sqldefs.h:71
ResultSetEmulator(int8_t *buff1, int8_t *buff2, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &gen1, NumberGenerator &gen2, const size_t perc1, const size_t perc2, const size_t flow, const bool silent)
Definition: sqldefs.h:71
std::vector< int64_t > getReferenceRow(bool keep_row=false)
void test_reduce(const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator1, NumberGenerator &generator2, const int step)
ResultSet * reduce(std::vector< ResultSet *> &)
std::vector< TargetInfo > generate_custom_agg_target_infos(std::vector< int8_t > group_columns, std::vector< SQLAgg > sql_aggs, std::vector< SQLTypes > agg_types, std::vector< SQLTypes > arg_types)
void write_key(const int64_t k, int8_t *ptr, const int8_t key_bytes)
QueryMemoryDescriptor baseline_hash_two_col_desc(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
void fill_storage_buffer(int8_t *buff, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator, const size_t step)