forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfield.cpp
More file actions
187 lines (172 loc) · 6.44 KB
/
Copy pathfield.cpp
File metadata and controls
187 lines (172 loc) · 6.44 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.
// This file is copied from
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Field.cpp
// and modified by Doris
#include "vec/core/field.h"
#include "vec/core/accurate_comparison.h"
#include "vec/core/decimal_comparison.h"
#include "vec/data_types/data_type_decimal.h"
#include "vec/io/io_helper.h"
#include "vec/io/var_int.h"
namespace doris {
namespace vectorized {
class BufferReadable;
class BufferWritable;
} // namespace vectorized
} // namespace doris
namespace doris::vectorized {
void read_binary(Array& x, BufferReadable& buf) {
size_t size;
UInt8 type;
doris::vectorized::read_binary(type, buf);
doris::vectorized::read_binary(size, buf);
for (size_t index = 0; index < size; ++index) {
switch (type) {
case Field::Types::Null: {
x.push_back(doris::vectorized::Field());
break;
}
case Field::Types::UInt64: {
UInt64 value;
doris::vectorized::read_var_uint(value, buf);
x.push_back(value);
break;
}
case Field::Types::UInt128: {
UInt128 value;
doris::vectorized::read_binary(value, buf);
x.push_back(value);
break;
}
case Field::Types::Int64: {
Int64 value;
doris::vectorized::read_var_int(value, buf);
x.push_back(value);
break;
}
case Field::Types::Float64: {
Float64 value;
doris::vectorized::read_float_binary(value, buf);
x.push_back(value);
break;
}
case Field::Types::String: {
std::string value;
doris::vectorized::read_string_binary(value, buf);
x.push_back(Field(value));
break;
}
case Field::Types::JSONB: {
JsonbField value;
doris::vectorized::read_json_binary(value, buf);
x.push_back(value);
break;
}
}
}
}
void write_binary(const Array& x, BufferWritable& buf) {
UInt8 type = Field::Types::Null;
size_t size = x.size();
if (size) type = x.front().get_type();
doris::vectorized::write_binary(type, buf);
doris::vectorized::write_binary(size, buf);
for (Array::const_iterator it = x.begin(); it != x.end(); ++it) {
switch (type) {
case Field::Types::Null:
break;
case Field::Types::UInt64: {
doris::vectorized::write_var_uint(get<UInt64>(*it), buf);
break;
}
case Field::Types::UInt128: {
doris::vectorized::write_binary(get<UInt128>(*it), buf);
break;
}
case Field::Types::Int64: {
doris::vectorized::write_var_int(get<Int64>(*it), buf);
break;
}
case Field::Types::Float64: {
doris::vectorized::write_float_binary(get<Float64>(*it), buf);
break;
}
case Field::Types::String: {
doris::vectorized::write_string_binary(get<std::string>(*it), buf);
break;
}
case Field::Types::JSONB: {
doris::vectorized::write_json_binary(get<JsonbField>(*it), buf);
break;
}
}
};
}
template <>
Decimal128V3 DecimalField<Decimal128V3>::get_scale_multiplier() const {
return DataTypeDecimal<Decimal128V3>::get_scale_multiplier(scale);
}
template <typename T>
bool dec_equal(T x, T y, UInt32 x_scale, UInt32 y_scale) {
using Comparator = DecimalComparison<T, T, EqualsOp>;
return Comparator::compare(x, y, x_scale, y_scale);
}
template <typename T>
bool dec_less(T x, T y, UInt32 x_scale, UInt32 y_scale) {
using Comparator = DecimalComparison<T, T, LessOp>;
return Comparator::compare(x, y, x_scale, y_scale);
}
template <typename T>
bool dec_less_or_equal(T x, T y, UInt32 x_scale, UInt32 y_scale) {
using Comparator = DecimalComparison<T, T, LessOrEqualsOp>;
return Comparator::compare(x, y, x_scale, y_scale);
}
#define DECLARE_DECIMAL_COMPARISON(TYPE) \
template <> \
bool decimal_equal(TYPE x, TYPE y, UInt32 xs, UInt32 ys) { \
return dec_equal(x, y, xs, ys); \
} \
template <> \
bool decimal_less(TYPE x, TYPE y, UInt32 xs, UInt32 ys) { \
return dec_less(x, y, xs, ys); \
} \
template <> \
bool decimal_less_or_equal(TYPE x, TYPE y, UInt32 xs, UInt32 ys) { \
return dec_less_or_equal(x, y, xs, ys); \
} \
template <> \
TYPE DecimalField<TYPE>::get_scale_multiplier() const { \
return DataTypeDecimal<TYPE>::get_scale_multiplier(scale); \
}
DECLARE_DECIMAL_COMPARISON(Decimal32)
DECLARE_DECIMAL_COMPARISON(Decimal64)
DECLARE_DECIMAL_COMPARISON(Decimal128V2)
DECLARE_DECIMAL_COMPARISON(Decimal256)
template <>
bool decimal_equal(Decimal128V3 x, Decimal128V3 y, UInt32 xs, UInt32 ys) {
return dec_equal(x, y, xs, ys);
}
template <>
bool decimal_less(Decimal128V3 x, Decimal128V3 y, UInt32 xs, UInt32 ys) {
return dec_less(x, y, xs, ys);
}
template <>
bool decimal_less_or_equal(Decimal128V3 x, Decimal128V3 y, UInt32 xs, UInt32 ys) {
return dec_less_or_equal(x, y, xs, ys);
}
} // namespace doris::vectorized