forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultSetTestUtils.cpp
More file actions
72 lines (69 loc) · 2.42 KB
/
ResultSetTestUtils.cpp
File metadata and controls
72 lines (69 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright 2017 MapD Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ResultSetTestUtils.h"
#include "../QueryEngine/ResultSetBufferAccessors.h"
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 */) {
size_t target_slot = 0;
int64_t vv = 0;
for (const auto& target_info : target_infos) {
bool isNullable = !target_info.sql_type.get_notnull();
const bool float_argument_input = takes_float_argument(target_info);
if ((isNullable && target_info.skip_null_val && null_val) || empty) {
vv = null_val_bit_pattern(target_info.sql_type, float_argument_input);
} else {
vv = v;
}
switch (target_info.sql_type.get_type()) {
case kSMALLINT:
case kINT:
case kBIGINT:
value_slots[target_slot] = vv;
break;
case kFLOAT:
if (float_argument_input) {
float fi = vv;
int64_t fi_bin = *reinterpret_cast<const int32_t*>(may_alias_ptr(&fi));
value_slots[target_slot] = null_val ? vv : fi_bin;
break;
}
case kDOUBLE: {
double di = vv;
value_slots[target_slot] = null_val ? vv : *reinterpret_cast<const int64_t*>(may_alias_ptr(&di));
break;
}
case kTEXT:
value_slots[target_slot] = -(vv + 2);
break;
default:
CHECK(false);
}
if (target_info.agg_kind == kAVG) {
value_slots[target_slot + 1] = 1;
}
target_slot = advance_slot(target_slot, target_info, false);
}
}
size_t get_slot_count(const std::vector<TargetInfo>& target_infos) {
size_t count = 0;
for (const auto& target_info : target_infos) {
count = advance_slot(count, target_info, false);
}
return count;
}