OmniSciDB  04ee39c94c
ResultSetTestUtils.h
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 
17 #ifndef RESULTSETTESTUTILS_H
18 #define RESULTSETTESTUTILS_H
19 
20 #include "../QueryEngine/ResultSet.h"
21 #include "../QueryEngine/RuntimeFunctions.h"
22 #include "../QueryEngine/TargetValue.h"
23 #include "../Shared/TargetInfo.h"
24 #include "../Shared/sqldefs.h"
25 
26 #include <cstdint>
27 #include <cstdlib>
28 #include <unordered_map>
29 #include <vector>
30 
32  public:
33  virtual int64_t getNextValue() = 0;
34 
35  virtual void reset() = 0;
36 };
37 
39  public:
40  EvenNumberGenerator() : crt_(0) {}
41 
42  int64_t getNextValue() override {
43  const auto crt = crt_;
44  crt_ += 2;
45  return crt;
46  }
47 
48  void reset() override { crt_ = 0; }
49 
50  private:
51  int64_t crt_;
52 };
53 
55  public:
56  ReverseOddOrEvenNumberGenerator(const int64_t init) : crt_(init), init_(init) {}
57 
58  int64_t getNextValue() override {
59  const auto crt = crt_;
60  crt_ -= 2;
61  return crt;
62  }
63 
64  void reset() override { crt_ = init_; }
65 
66  private:
67  int64_t crt_;
68  int64_t init_;
69 };
70 
71 int8_t* advance_to_next_columnar_key_buff(int8_t* key_ptr,
72  const QueryMemoryDescriptor& query_mem_desc,
73  const size_t key_idx);
74 
75 int64_t get_empty_key_sentinel(int8_t key_bytes);
76 
77 void write_key(const int64_t k, int8_t* ptr, const int8_t key_bytes);
78 
79 void write_int(int8_t* slot_ptr, const int64_t v, const size_t slot_bytes);
80 
81 void write_fp(int8_t* slot_ptr, const int64_t v, const size_t slot_bytes);
82 
83 int8_t* fill_one_entry_no_collisions(int8_t* buff,
84  const QueryMemoryDescriptor& query_mem_desc,
85  const int64_t v,
86  const std::vector<TargetInfo>& target_infos,
87  const bool empty,
88  const bool null_val = false);
89 
90 void fill_one_entry_one_col(int8_t* ptr1,
91  const int8_t compact_sz1,
92  int8_t* ptr2,
93  const int8_t compact_sz2,
94  int64_t v,
95  const TargetInfo& target_info,
96  const bool empty_entry,
97  const bool null_val = false);
98 
99 void fill_one_entry_one_col(int64_t* value_slot,
100  const int64_t v,
101  const TargetInfo& target_info,
102  const size_t entry_count,
103  const bool empty_entry = false,
104  const bool null_val = false);
105 
106 void fill_one_entry_baseline(int64_t* value_slots,
107  const int64_t v,
108  const std::vector<TargetInfo>& target_infos,
109  const bool empty = false,
110  const bool null_val = false);
111 
113  const std::vector<TargetInfo>& target_infos,
114  const QueryMemoryDescriptor& query_mem_desc,
115  NumberGenerator& generator,
116  const size_t step = 2);
117 
119  const std::vector<TargetInfo>& target_infos,
120  const QueryMemoryDescriptor& query_mem_desc,
121  NumberGenerator& generator,
122  const size_t step = 2);
123 
124 void fill_storage_buffer_baseline_colwise(int8_t* buff,
125  const std::vector<TargetInfo>& target_infos,
126  const QueryMemoryDescriptor& query_mem_desc,
127  NumberGenerator& generator,
128  const size_t step);
129 
130 void fill_storage_buffer_baseline_rowwise(int8_t* buff,
131  const std::vector<TargetInfo>& target_infos,
132  const QueryMemoryDescriptor& query_mem_desc,
133  NumberGenerator& generator,
134  const size_t step);
135 
136 void fill_storage_buffer(int8_t* buff,
137  const std::vector<TargetInfo>& target_infos,
138  const QueryMemoryDescriptor& query_mem_desc,
139  NumberGenerator& generator,
140  const size_t step);
141 
143  const std::vector<TargetInfo>& target_infos,
144  const int8_t num_bytes);
145 
147  const std::vector<TargetInfo>& target_infos,
148  const int8_t num_bytes,
149  const size_t min_val,
150  const size_t max_val,
151  std::vector<int8_t> group_column_widths = {8});
152 
154  const std::vector<TargetInfo>& target_infos,
155  const int8_t num_bytes);
156 
158  const std::vector<TargetInfo>& target_infos,
159  const int8_t num_bytes);
160 
162  const std::vector<TargetInfo>& target_infos,
163  const int8_t num_bytes);
164 
165 size_t get_slot_count(const std::vector<TargetInfo>& target_infos);
166 
167 std::unordered_map<size_t, size_t> get_slot_to_target_mapping(
168  const std::vector<TargetInfo>& target_infos);
169 
170 std::vector<TargetInfo> generate_custom_agg_target_infos(std::vector<int8_t> key_columns,
171  std::vector<SQLAgg> sql_aggs,
172  std::vector<SQLTypes> agg_types,
173  std::vector<SQLTypes> arg_types);
174 
175 template <class T>
176 inline T v(const TargetValue& r) {
177  auto scalar_r = boost::get<ScalarTargetValue>(&r);
178  CHECK(scalar_r);
179  auto p = boost::get<T>(scalar_r);
180  CHECK(p);
181  return *p;
182 }
183 
184 template <class T>
185 const T* vptr(const TargetValue& r) {
186  auto scalar_r = boost::get<ScalarTargetValue>(&r);
187  CHECK(scalar_r);
188  return boost::get<T>(scalar_r);
189 }
190 
191 #endif // RESULTSETTESTUTILS_H
std::unordered_map< size_t, size_t > get_slot_to_target_mapping(const std::vector< TargetInfo > &target_infos)
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=false)
std::vector< TargetInfo > generate_custom_agg_target_infos(std::vector< int8_t > key_columns, std::vector< SQLAgg > sql_aggs, std::vector< SQLTypes > agg_types, std::vector< SQLTypes > arg_types)
int64_t get_empty_key_sentinel(int8_t key_bytes)
void fill_one_entry_baseline(int64_t *value_slots, const int64_t v, const std::vector< TargetInfo > &target_infos, const bool empty=false, const bool null_val=false)
QueryMemoryDescriptor baseline_hash_two_col_desc(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
void fill_storage_buffer_perfect_hash_rowwise(int8_t *buff, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator, const size_t step=2)
void fill_storage_buffer(int8_t *buff, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator, const size_t step)
void write_int(int8_t *slot_ptr, const int64_t v, const size_t slot_bytes)
size_t get_slot_count(const std::vector< TargetInfo > &target_infos)
T v(const TargetValue &r)
void init(LogOptions const &log_opts)
Definition: Logger.cpp:260
void fill_storage_buffer_baseline_rowwise(int8_t *buff, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator, const size_t step)
void reset() override
void write_fp(int8_t *slot_ptr, const int64_t v, const size_t slot_bytes)
QueryMemoryDescriptor perfect_hash_one_col_desc_small(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
virtual void reset()=0
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={8})
int8_t * advance_to_next_columnar_key_buff(int8_t *key_ptr, const QueryMemoryDescriptor &query_mem_desc, const size_t key_idx)
void fill_storage_buffer_perfect_hash_colwise(int8_t *buff, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator, const size_t step=2)
void write_key(const int64_t k, int8_t *ptr, const int8_t key_bytes)
QueryMemoryDescriptor perfect_hash_two_col_desc(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
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=false)
#define CHECK(condition)
Definition: Logger.h:187
void fill_storage_buffer_baseline_colwise(int8_t *buff, const std::vector< TargetInfo > &target_infos, const QueryMemoryDescriptor &query_mem_desc, NumberGenerator &generator, const size_t step)
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
virtual int64_t getNextValue()=0
QueryMemoryDescriptor baseline_hash_two_col_desc_large(const std::vector< TargetInfo > &target_infos, const int8_t num_bytes)
const T * vptr(const TargetValue &r)
ReverseOddOrEvenNumberGenerator(const int64_t init)
int64_t getNextValue() override