YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/bfpg/bfunc_convert.h
Line
Count
Source (jump to first uncovered line)
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//
15
// This module defines of C++ functions to support "cast" operators. Note that for "cast" operators,
16
// all arguments must of exact types. Type resolution will raise error if an argument type is
17
// only compatible / convertible but not equal.
18
//   Example: cast(int64 to string) will accept only int64 and string but not int32 and string.
19
//
20
// The conversion routines can be use for either or both of two different purposes.
21
// - Converting the value from one type to another.
22
// - Converting the value from one data representation to another.
23
//
24
// Once written, this function should not be changed to avoid compatibility issues. That is,
25
// server might runs one version while client use a different version of this function.
26
//
27
// See the header of file "/util/bfpg/bfpg.h" for overall info.
28
//--------------------------------------------------------------------------------------------------
29
30
#ifndef YB_BFPG_BFUNC_CONVERT_H_
31
#define YB_BFPG_BFUNC_CONVERT_H_
32
33
#include <iostream>
34
#include <string>
35
36
#include "yb/gutil/casts.h"
37
38
#include "yb/util/date_time.h"
39
#include "yb/util/logging.h"
40
#include "yb/util/net/inetaddress.h"
41
#include "yb/util/status_fwd.h"
42
#include "yb/util/stol_utils.h"
43
44
namespace yb {
45
namespace bfpg {
46
47
//--------------------------------------------------------------------------------------------------
48
// The following functions are for numeric conversions.
49
50
// Conversion for int8.
51
template<typename PTypePtr, typename RTypePtr>
52
Status ConvertI8ToI8(PTypePtr source, RTypePtr target) {
53
  if (source->IsNull()) {
54
    target->SetNull();
55
  } else {
56
    target->set_int8_value(source->int8_value());
57
  }
58
  return Status::OK();
59
}
60
61
template<typename PTypePtr, typename RTypePtr>
62
0
Status ConvertI8ToI16(PTypePtr source, RTypePtr target) {
63
0
  if (source->IsNull()) {
64
0
    target->SetNull();
65
0
  } else {
66
0
    target->set_int16_value(source->int8_value());
67
0
  }
68
0
  return Status::OK();
69
0
}
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI16INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI16INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI16IPNS_7QLValueES3_EENS_6StatusET_T0_
70
71
template<typename PTypePtr, typename RTypePtr>
72
0
Status ConvertI8ToI32(PTypePtr source, RTypePtr target) {
73
0
  if (source->IsNull()) {
74
0
    target->SetNull();
75
0
  } else {
76
0
    target->set_int32_value(source->int8_value());
77
0
  }
78
0
  return Status::OK();
79
0
}
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI32INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI32INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI32IPNS_7QLValueES3_EENS_6StatusET_T0_
80
81
template<typename PTypePtr, typename RTypePtr>
82
0
Status ConvertI8ToI64(PTypePtr source, RTypePtr target) {
83
0
  if (source->IsNull()) {
84
0
    target->SetNull();
85
0
  } else {
86
0
    target->set_int64_value(source->int8_value());
87
0
  }
88
0
  return Status::OK();
89
0
}
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI64INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI64INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI8ToI64IPNS_7QLValueES3_EENS_6StatusET_T0_
90
91
template<typename PTypePtr, typename RTypePtr>
92
0
Status ConvertI8ToFloat(PTypePtr source, RTypePtr target) {
93
0
  if (source->IsNull()) {
94
0
    target->SetNull();
95
0
  } else {
96
0
    target->set_float_value(source->int8_value());
97
0
  }
98
0
  return Status::OK();
99
0
}
Unexecuted instantiation: _ZN2yb4bfpg16ConvertI8ToFloatINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg16ConvertI8ToFloatINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg16ConvertI8ToFloatIPNS_7QLValueES3_EENS_6StatusET_T0_
100
101
template<typename PTypePtr, typename RTypePtr>
102
0
Status ConvertI8ToDouble(PTypePtr source, RTypePtr target) {
103
0
  if (source->IsNull()) {
104
0
    target->SetNull();
105
0
  } else {
106
0
    target->set_double_value(source->int8_value());
107
0
  }
108
0
  return Status::OK();
109
0
}
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI8ToDoubleINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI8ToDoubleINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI8ToDoubleIPNS_7QLValueES3_EENS_6StatusET_T0_
110
111
// Conversion from int16 to others.
112
template<typename PTypePtr, typename RTypePtr>
113
0
Status ConvertI16ToI8(PTypePtr source, RTypePtr target) {
114
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
115
0
  if (source->IsNull()) {
116
0
    target->SetNull();
117
0
  } else {
118
0
    target->set_int8_value(source->int16_value());
119
0
  }
120
0
  return Status::OK();
121
0
}
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI16ToI8INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI16ToI8INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI16ToI8IPNS_7QLValueES3_EENS_6StatusET_T0_
122
123
template<typename PTypePtr, typename RTypePtr>
124
Status ConvertI16ToI16(PTypePtr source, RTypePtr target) {
125
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
126
  if (source->IsNull()) {
127
    target->SetNull();
128
  } else {
129
    target->set_int16_value(source->int16_value());
130
  }
131
  return Status::OK();
132
}
133
134
template<typename PTypePtr, typename RTypePtr>
135
0
Status ConvertI16ToI32(PTypePtr source, RTypePtr target) {
136
0
  if (source->IsNull()) {
137
0
    target->SetNull();
138
0
  } else {
139
0
    target->set_int32_value(source->int16_value());
140
0
  }
141
0
  return Status::OK();
142
0
}
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI16ToI32INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI16ToI32INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI16ToI32IPNS_7QLValueES3_EENS_6StatusET_T0_
143
144
template<typename PTypePtr, typename RTypePtr>
145
0
Status ConvertI16ToI64(PTypePtr source, RTypePtr target) {
146
0
  if (source->IsNull()) {
147
0
    target->SetNull();
148
0
  } else {
149
0
    target->set_int64_value(source->int16_value());
150
0
  }
151
0
  return Status::OK();
152
0
}
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI16ToI64INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI16ToI64INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI16ToI64IPNS_7QLValueES3_EENS_6StatusET_T0_
153
154
template<typename PTypePtr, typename RTypePtr>
155
0
Status ConvertI16ToFloat(PTypePtr source, RTypePtr target) {
156
0
  if (source->IsNull()) {
157
0
    target->SetNull();
158
0
  } else {
159
0
    target->set_float_value(source->int16_value());
160
0
  }
161
0
  return Status::OK();
162
0
}
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI16ToFloatINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI16ToFloatINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI16ToFloatIPNS_7QLValueES3_EENS_6StatusET_T0_
163
164
template<typename PTypePtr, typename RTypePtr>
165
1
Status ConvertI16ToDouble(PTypePtr source, RTypePtr target) {
166
1
  if (source->IsNull()) {
167
0
    target->SetNull();
168
1
  } else {
169
1
    target->set_double_value(source->int16_value());
170
1
  }
171
1
  return Status::OK();
172
1
}
_ZN2yb4bfpg18ConvertI16ToDoubleINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Line
Count
Source
165
1
Status ConvertI16ToDouble(PTypePtr source, RTypePtr target) {
166
1
  if (source->IsNull()) {
167
0
    target->SetNull();
168
1
  } else {
169
1
    target->set_double_value(source->int16_value());
170
1
  }
171
1
  return Status::OK();
172
1
}
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI16ToDoubleINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI16ToDoubleIPNS_7QLValueES3_EENS_6StatusET_T0_
173
174
// Conversion from int32 to others.
175
template<typename PTypePtr, typename RTypePtr>
176
0
Status ConvertI32ToI8(PTypePtr source, RTypePtr target) {
177
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
178
0
  if (source->IsNull()) {
179
0
    target->SetNull();
180
0
  } else {
181
0
    target->set_int8_value(source->int32_value());
182
0
  }
183
0
  return Status::OK();
184
0
}
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI32ToI8INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI32ToI8INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI32ToI8IPNS_7QLValueES3_EENS_6StatusET_T0_
185
186
template<typename PTypePtr, typename RTypePtr>
187
0
Status ConvertI32ToI16(PTypePtr source, RTypePtr target) {
188
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
189
0
  if (source->IsNull()) {
190
0
    target->SetNull();
191
0
  } else {
192
0
    target->set_int16_value(source->int32_value());
193
0
  }
194
0
  return Status::OK();
195
0
}
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI32ToI16INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI32ToI16INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI32ToI16IPNS_7QLValueES3_EENS_6StatusET_T0_
196
197
template<typename PTypePtr, typename RTypePtr>
198
Status ConvertI32ToI32(PTypePtr source, RTypePtr target) {
199
  if (source->IsNull()) {
200
    target->SetNull();
201
  } else {
202
    target->set_int32_value(source->int32_value());
203
  }
204
  return Status::OK();
205
}
206
207
template<typename PTypePtr, typename RTypePtr>
208
0
Status ConvertI32ToI64(PTypePtr source, RTypePtr target) {
209
0
  if (source->IsNull()) {
210
0
    target->SetNull();
211
0
  } else {
212
0
    target->set_int64_value(source->int32_value());
213
0
  }
214
0
  return Status::OK();
215
0
}
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI32ToI64INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI32ToI64INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI32ToI64IPNS_7QLValueES3_EENS_6StatusET_T0_
216
217
template<typename PTypePtr, typename RTypePtr>
218
0
Status ConvertI32ToFloat(PTypePtr source, RTypePtr target) {
219
0
  if (source->IsNull()) {
220
0
    target->SetNull();
221
0
  } else {
222
0
    target->set_float_value(source->int32_value());
223
0
  }
224
0
  return Status::OK();
225
0
}
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI32ToFloatINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI32ToFloatINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI32ToFloatIPNS_7QLValueES3_EENS_6StatusET_T0_
226
227
template<typename PTypePtr, typename RTypePtr>
228
0
Status ConvertI32ToDouble(PTypePtr source, RTypePtr target) {
229
0
  if (source->IsNull()) {
230
0
    target->SetNull();
231
0
  } else {
232
0
    target->set_double_value(source->int32_value());
233
0
  }
234
0
  return Status::OK();
235
0
}
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI32ToDoubleINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI32ToDoubleINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI32ToDoubleIPNS_7QLValueES3_EENS_6StatusET_T0_
236
237
// Conversion from int64 to others.
238
template<typename PTypePtr, typename RTypePtr>
239
0
Status ConvertI64ToI8(PTypePtr source, RTypePtr target) {
240
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
241
0
  if (source->IsNull()) {
242
0
    target->SetNull();
243
0
  } else {
244
0
    target->set_int8_value(source->int64_value());
245
0
  }
246
0
  return Status::OK();
247
0
}
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI64ToI8INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI64ToI8INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg14ConvertI64ToI8IPNS_7QLValueES3_EENS_6StatusET_T0_
248
249
template<typename PTypePtr, typename RTypePtr>
250
1
Status ConvertI64ToI16(PTypePtr source, RTypePtr target) {
251
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
252
1
  if (source->IsNull()) {
253
0
    target->SetNull();
254
1
  } else {
255
1
    target->set_int16_value(source->int64_value());
256
1
  }
257
1
  return Status::OK();
258
1
}
_ZN2yb4bfpg15ConvertI64ToI16INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Line
Count
Source
250
1
Status ConvertI64ToI16(PTypePtr source, RTypePtr target) {
251
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
252
1
  if (source->IsNull()) {
253
0
    target->SetNull();
254
1
  } else {
255
1
    target->set_int16_value(source->int64_value());
256
1
  }
257
1
  return Status::OK();
258
1
}
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI64ToI16INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI64ToI16IPNS_7QLValueES3_EENS_6StatusET_T0_
259
260
template<typename PTypePtr, typename RTypePtr>
261
0
Status ConvertI64ToI32(PTypePtr source, RTypePtr target) {
262
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
263
0
  if (source->IsNull()) {
264
0
    target->SetNull();
265
0
  } else {
266
0
    target->set_int32_value(static_cast<int32_t>(source->int64_value()));
267
0
  }
268
0
  return Status::OK();
269
0
}
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI64ToI32INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI64ToI32INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg15ConvertI64ToI32IPNS_7QLValueES3_EENS_6StatusET_T0_
270
271
template<typename PTypePtr, typename RTypePtr>
272
Status ConvertI64ToI64(PTypePtr source, RTypePtr target) {
273
  // TODO(neil) Overflow? When we truely support expressions, these loose-ends must be fixed.
274
  if (source->IsNull()) {
275
    target->SetNull();
276
  } else {
277
    target->set_int64_value(source->int64_value());
278
  }
279
  return Status::OK();
280
}
281
282
template<typename PTypePtr, typename RTypePtr>
283
0
Status ConvertI64ToFloat(PTypePtr source, RTypePtr target) {
284
0
  if (source->IsNull()) {
285
0
    target->SetNull();
286
0
  } else {
287
0
    target->set_float_value(source->int64_value());
288
0
  }
289
0
  return Status::OK();
290
0
}
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI64ToFloatINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI64ToFloatINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertI64ToFloatIPNS_7QLValueES3_EENS_6StatusET_T0_
291
292
template<typename PTypePtr, typename RTypePtr>
293
1
Status ConvertI64ToDouble(PTypePtr source, RTypePtr target) {
294
1
  if (source->IsNull()) {
295
0
    target->SetNull();
296
1
  } else {
297
1
    target->set_double_value(source->int64_value());
298
1
  }
299
1
  return Status::OK();
300
1
}
_ZN2yb4bfpg18ConvertI64ToDoubleINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Line
Count
Source
293
1
Status ConvertI64ToDouble(PTypePtr source, RTypePtr target) {
294
1
  if (source->IsNull()) {
295
0
    target->SetNull();
296
1
  } else {
297
1
    target->set_double_value(source->int64_value());
298
1
  }
299
1
  return Status::OK();
300
1
}
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI64ToDoubleINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertI64ToDoubleIPNS_7QLValueES3_EENS_6StatusET_T0_
301
302
// Conversion from float to others.
303
template<typename PTypePtr, typename RTypePtr>
304
Status ConvertFloatToFloat(PTypePtr source, RTypePtr target) {
305
  if (source->IsNull()) {
306
    target->SetNull();
307
  } else {
308
    target->set_float_value(source->float_value());
309
  }
310
  return Status::OK();
311
}
312
313
template<typename PTypePtr, typename RTypePtr>
314
0
Status ConvertFloatToDouble(PTypePtr source, RTypePtr target) {
315
0
  if (source->IsNull()) {
316
0
    target->SetNull();
317
0
  } else {
318
0
    target->set_double_value(source->float_value());
319
0
  }
320
0
  return Status::OK();
321
0
}
Unexecuted instantiation: _ZN2yb4bfpg20ConvertFloatToDoubleINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg20ConvertFloatToDoubleINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg20ConvertFloatToDoubleIPNS_7QLValueES3_EENS_6StatusET_T0_
322
323
// Conversion from double to others.
324
template<typename PTypePtr, typename RTypePtr>
325
1
Status ConvertDoubleToFloat(PTypePtr source, RTypePtr target) {
326
1
  if (source->IsNull()) {
327
0
    target->SetNull();
328
1
  } else {
329
1
    target->set_float_value(source->double_value());
330
1
  }
331
1
  return Status::OK();
332
1
}
_ZN2yb4bfpg20ConvertDoubleToFloatINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Line
Count
Source
325
1
Status ConvertDoubleToFloat(PTypePtr source, RTypePtr target) {
326
1
  if (source->IsNull()) {
327
0
    target->SetNull();
328
1
  } else {
329
1
    target->set_float_value(source->double_value());
330
1
  }
331
1
  return Status::OK();
332
1
}
Unexecuted instantiation: _ZN2yb4bfpg20ConvertDoubleToFloatINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg20ConvertDoubleToFloatIPNS_7QLValueES3_EENS_6StatusET_T0_
333
334
template<typename PTypePtr, typename RTypePtr>
335
Status ConvertDoubleToDouble(PTypePtr source, RTypePtr target) {
336
  if (source->IsNull()) {
337
    target->SetNull();
338
  } else {
339
    target->set_double_value(source->double_value());
340
  }
341
  return Status::OK();
342
}
343
344
//--------------------------------------------------------------------------------------------------
345
// The following functions are for timestamp conversion.
346
template<typename PTypePtr, typename RTypePtr>
347
Status ConvertTimestampToI64(PTypePtr source, RTypePtr target) {
348
  if (source->IsNull()) {
349
    target->SetNull();
350
  } else {
351
    target->set_int64_value(source->timestamp_value().ToInt64());
352
  }
353
  return Status::OK();
354
}
355
356
template<typename PTypePtr, typename RTypePtr>
357
Status ConvertI64ToTimestamp(PTypePtr source, RTypePtr target) {
358
  if (source->IsNull()) {
359
    target->SetNull();
360
  } else {
361
    target->set_timestamp_value(DateTime::TimestampFromInt(source->int64_value()).ToInt64());
362
  }
363
  return Status::OK();
364
}
365
366
template<typename PTypePtr, typename RTypePtr>
367
Status ConvertTimestampToString(PTypePtr source, RTypePtr target) {
368
  if (source->IsNull()) {
369
    target->SetNull();
370
  } else {
371
    target->set_string_value(source->timestamp_value().ToString());
372
  }
373
  return Status::OK();
374
}
375
376
template<typename PTypePtr, typename RTypePtr>
377
Status ConvertStringToTimestamp(PTypePtr source, RTypePtr target) {
378
  if (source->IsNull()) {
379
    target->SetNull();
380
  } else {
381
    Timestamp ts;
382
    RETURN_NOT_OK(DateTime::TimestampFromString(source->string_value(), &ts));
383
    target->set_timestamp_value(ts.ToInt64());
384
  }
385
  return Status::OK();
386
}
387
388
//--------------------------------------------------------------------------------------------------
389
// The following functions are for string conversion.
390
template<typename PTypePtr, typename RTypePtr>
391
Status ConvertStringToString(PTypePtr source, RTypePtr target) {
392
  if (source->IsNull()) {
393
    target->SetNull();
394
  } else {
395
    target->set_string_value(source->string_value());
396
  }
397
  return Status::OK();
398
}
399
400
template<typename PTypePtr, typename RTypePtr>
401
Status ConvertStringToInet(PTypePtr source, RTypePtr target) {
402
  if (source->IsNull()) {
403
    target->SetNull();
404
  } else {
405
    target->set_inetaddress_value(InetAddress(
406
        VERIFY_RESULT(HostToAddress(source->string_value()))));
407
  }
408
  return Status::OK();
409
}
410
411
//--------------------------------------------------------------------------------------------------
412
// The following functions are for boolean conversion.
413
template<typename PTypePtr, typename RTypePtr>
414
Status ConvertBoolToBool(PTypePtr source, RTypePtr target) {
415
  if (source->IsNull()) {
416
    target->SetNull();
417
  } else {
418
    target->set_bool_value(source->bool_value());
419
  }
420
  return Status::OK();
421
}
422
423
//--------------------------------------------------------------------------------------------------
424
// The following functions are for conversions to blob / binary from other datatypes.
425
426
template<typename PTypePtr, typename RTypePtr>
427
Status ConvertStringToBlob(PTypePtr source, RTypePtr target) {
428
  return STATUS(RuntimeError, "Not yet implemented");
429
}
430
431
template<typename PTypePtr, typename RTypePtr>
432
Status ConvertBoolToBlob(PTypePtr source, RTypePtr target) {
433
  return STATUS(RuntimeError, "Not yet implemented");
434
}
435
436
template<typename PTypePtr, typename RTypePtr>
437
Status ConvertInt8ToBlob(PTypePtr source, RTypePtr target) {
438
  return STATUS(RuntimeError, "Not yet implemented");
439
}
440
441
template<typename PTypePtr, typename RTypePtr>
442
Status ConvertInt16ToBlob(PTypePtr source, RTypePtr target) {
443
  return STATUS(RuntimeError, "Not yet implemented");
444
}
445
446
template<typename PTypePtr, typename RTypePtr>
447
Status ConvertInt32ToBlob(PTypePtr source, RTypePtr target) {
448
  return STATUS(RuntimeError, "Not yet implemented");
449
}
450
451
template<typename PTypePtr, typename RTypePtr>
452
Status ConvertInt64ToBlob(PTypePtr source, RTypePtr target) {
453
  return STATUS(RuntimeError, "Not yet implemented");
454
}
455
456
template<typename PTypePtr, typename RTypePtr>
457
Status ConvertVarintToBlob(PTypePtr source, RTypePtr target) {
458
  return STATUS(RuntimeError, "Not yet implemented");
459
}
460
461
template<typename PTypePtr, typename RTypePtr>
462
Status ConvertFloatToBlob(PTypePtr source, RTypePtr target) {
463
  return STATUS(RuntimeError, "Not yet implemented");
464
}
465
466
template<typename PTypePtr, typename RTypePtr>
467
Status ConvertDoubleToBlob(PTypePtr source, RTypePtr target) {
468
  return STATUS(RuntimeError, "Not yet implemented");
469
}
470
471
template<typename PTypePtr, typename RTypePtr>
472
Status ConvertDecimalToBlob(PTypePtr source, RTypePtr target) {
473
  return STATUS(RuntimeError, "Not yet implemented");
474
}
475
476
template<typename PTypePtr, typename RTypePtr>
477
Status ConvertDateToBlob(PTypePtr source, RTypePtr target) {
478
  return STATUS(RuntimeError, "Not yet implemented");
479
}
480
481
template<typename PTypePtr, typename RTypePtr>
482
Status ConvertTimeToBlob(PTypePtr source, RTypePtr target) {
483
  return STATUS(RuntimeError, "Not yet implemented");
484
}
485
486
template<typename PTypePtr, typename RTypePtr>
487
Status ConvertTimestampToBlob(PTypePtr source, RTypePtr target) {
488
  return STATUS(RuntimeError, "Not yet implemented");
489
}
490
491
template<typename PTypePtr, typename RTypePtr>
492
Status ConvertUuidToBlob(PTypePtr source, RTypePtr target) {
493
  return STATUS(RuntimeError, "Not yet implemented");
494
}
495
496
template<typename PTypePtr, typename RTypePtr>
497
Status ConvertTimeuuidToBlob(PTypePtr source, RTypePtr target) {
498
  return STATUS(RuntimeError, "Not yet implemented");
499
}
500
501
template<typename PTypePtr, typename RTypePtr>
502
Status ConvertInetToBlob(PTypePtr source, RTypePtr target) {
503
  return STATUS(RuntimeError, "Not yet implemented");
504
}
505
506
template<typename PTypePtr, typename RTypePtr>
507
Status ConvertListToBlob(PTypePtr source, RTypePtr target) {
508
  return STATUS(RuntimeError, "Not yet implemented");
509
}
510
511
template<typename PTypePtr, typename RTypePtr>
512
Status ConvertMapToBlob(PTypePtr source, RTypePtr target) {
513
  return STATUS(RuntimeError, "Not yet implemented");
514
}
515
516
template<typename PTypePtr, typename RTypePtr>
517
Status ConvertSetToBlob(PTypePtr source, RTypePtr target) {
518
  return STATUS(RuntimeError, "Not yet implemented");
519
}
520
521
template<typename PTypePtr, typename RTypePtr>
522
Status ConvertTupleToBlob(PTypePtr source, RTypePtr target) {
523
  return STATUS(RuntimeError, "Not yet implemented");
524
}
525
526
// The following functions are for conversions from blob / binary to other datatypes.
527
528
template<typename PTypePtr, typename RTypePtr>
529
Status ConvertBlobToString(PTypePtr source, RTypePtr target) {
530
  return STATUS(RuntimeError, "Not yet implemented");
531
}
532
533
template<typename PTypePtr, typename RTypePtr>
534
Status ConvertBlobToBool(PTypePtr source, RTypePtr target) {
535
  return STATUS(RuntimeError, "Not yet implemented");
536
}
537
538
template<typename PTypePtr, typename RTypePtr>
539
Status ConvertBlobToInt8(PTypePtr source, RTypePtr target) {
540
  return STATUS(RuntimeError, "Not yet implemented");
541
}
542
543
template<typename PTypePtr, typename RTypePtr>
544
Status ConvertBlobToInt16(PTypePtr source, RTypePtr target) {
545
  return STATUS(RuntimeError, "Not yet implemented");
546
}
547
548
template<typename PTypePtr, typename RTypePtr>
549
Status ConvertBlobToInt32(PTypePtr source, RTypePtr target) {
550
  return STATUS(RuntimeError, "Not yet implemented");
551
}
552
553
template<typename PTypePtr, typename RTypePtr>
554
Status ConvertBlobToInt64(PTypePtr source, RTypePtr target) {
555
  return STATUS(RuntimeError, "Not yet implemented");
556
}
557
558
template<typename PTypePtr, typename RTypePtr>
559
Status ConvertBlobToVarint(PTypePtr source, RTypePtr target) {
560
  return STATUS(RuntimeError, "Not yet implemented");
561
}
562
563
template<typename PTypePtr, typename RTypePtr>
564
Status ConvertBlobToFloat(PTypePtr source, RTypePtr target) {
565
  return STATUS(RuntimeError, "Not yet implemented");
566
}
567
568
template<typename PTypePtr, typename RTypePtr>
569
Status ConvertBlobToDouble(PTypePtr source, RTypePtr target) {
570
  return STATUS(RuntimeError, "Not yet implemented");
571
}
572
573
template<typename PTypePtr, typename RTypePtr>
574
Status ConvertBlobToDecimal(PTypePtr source, RTypePtr target) {
575
  return STATUS(RuntimeError, "Not yet implemented");
576
}
577
578
template<typename PTypePtr, typename RTypePtr>
579
Status ConvertBlobToDate(PTypePtr source, RTypePtr target) {
580
  return STATUS(RuntimeError, "Not yet implemented");
581
}
582
583
template<typename PTypePtr, typename RTypePtr>
584
Status ConvertBlobToTime(PTypePtr source, RTypePtr target) {
585
  return STATUS(RuntimeError, "Not yet implemented");
586
}
587
588
template<typename PTypePtr, typename RTypePtr>
589
Status ConvertBlobToTimestamp(PTypePtr source, RTypePtr target) {
590
  return STATUS(RuntimeError, "Not yet implemented");
591
}
592
593
template<typename PTypePtr, typename RTypePtr>
594
Status ConvertBlobToUuid(PTypePtr source, RTypePtr target) {
595
  return STATUS(RuntimeError, "Not yet implemented");
596
}
597
598
template<typename PTypePtr, typename RTypePtr>
599
Status ConvertBlobToTimeuuid(PTypePtr source, RTypePtr target) {
600
  return STATUS(RuntimeError, "Not yet implemented");
601
}
602
603
template<typename PTypePtr, typename RTypePtr>
604
Status ConvertBlobToInet(PTypePtr source, RTypePtr target) {
605
  return STATUS(RuntimeError, "Not yet implemented");
606
}
607
608
template<typename PTypePtr, typename RTypePtr>
609
Status ConvertBlobToList(PTypePtr source, RTypePtr target) {
610
  return STATUS(RuntimeError, "Not yet implemented");
611
}
612
613
template<typename PTypePtr, typename RTypePtr>
614
Status ConvertBlobToMap(PTypePtr source, RTypePtr target) {
615
  return STATUS(RuntimeError, "Not yet implemented");
616
}
617
618
template<typename PTypePtr, typename RTypePtr>
619
Status ConvertBlobToSet(PTypePtr source, RTypePtr target) {
620
  return STATUS(RuntimeError, "Not yet implemented");
621
}
622
623
template<typename PTypePtr, typename RTypePtr>
624
Status ConvertBlobToTuple(PTypePtr source, RTypePtr target) {
625
  return STATUS(RuntimeError, "Not yet implemented");
626
}
627
628
//--------------------------------------------------------------------------------------------------
629
// The following functions are for conversions between date-time datatypes.
630
template<typename PTypePtr, typename RTypePtr>
631
Status ConvertTimeuuidToDate(PTypePtr source, RTypePtr target) {
632
  return STATUS(RuntimeError, "Not yet implemented");
633
}
634
635
template<typename PTypePtr, typename RTypePtr>
636
0
Status ConvertTimestampToDate(PTypePtr source, RTypePtr target) {
637
0
  return STATUS(RuntimeError, "Not yet implemented");
638
0
}
Unexecuted instantiation: _ZN2yb4bfpg22ConvertTimestampToDateINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg22ConvertTimestampToDateINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg22ConvertTimestampToDateIPNS_7QLValueES3_EENS_6StatusET_T0_
639
640
template<typename PTypePtr, typename RTypePtr>
641
Status ConvertTimeuuidToTime(PTypePtr source, RTypePtr target) {
642
  return STATUS(RuntimeError, "Not yet implemented");
643
}
644
645
template<typename PTypePtr, typename RTypePtr>
646
0
Status ConvertTimestampToTime(PTypePtr source, RTypePtr target) {
647
0
  return STATUS(RuntimeError, "Not yet implemented");
648
0
}
Unexecuted instantiation: _ZN2yb4bfpg22ConvertTimestampToTimeINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg22ConvertTimestampToTimeINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg22ConvertTimestampToTimeIPNS_7QLValueES3_EENS_6StatusET_T0_
649
650
template<typename PTypePtr, typename RTypePtr>
651
0
Status ConvertDateToTimestamp(PTypePtr source, RTypePtr target) {
652
0
  return STATUS(RuntimeError, "Not yet implemented");
653
0
}
Unexecuted instantiation: _ZN2yb4bfpg22ConvertDateToTimestampINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg22ConvertDateToTimestampINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg22ConvertDateToTimestampIPNS_7QLValueES3_EENS_6StatusET_T0_
654
655
template<typename PTypePtr, typename RTypePtr>
656
Status ConvertTimeuuidToTimestamp(PTypePtr source, RTypePtr target) {
657
  return STATUS(RuntimeError, "Not yet implemented");
658
}
659
660
template<typename PTypePtr, typename RTypePtr>
661
0
Status ConvertDateToUnixTimestamp(PTypePtr source, RTypePtr target) {
662
0
  return STATUS(RuntimeError, "Not yet implemented");
663
0
}
Unexecuted instantiation: _ZN2yb4bfpg26ConvertDateToUnixTimestampINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg26ConvertDateToUnixTimestampINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg26ConvertDateToUnixTimestampIPNS_7QLValueES3_EENS_6StatusET_T0_
664
665
template<typename PTypePtr, typename RTypePtr>
666
0
Status ConvertTimestampToUnixTimestamp(PTypePtr source, RTypePtr target) {
667
0
  return STATUS(RuntimeError, "Not yet implemented");
668
0
}
Unexecuted instantiation: _ZN2yb4bfpg31ConvertTimestampToUnixTimestampINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg31ConvertTimestampToUnixTimestampINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg31ConvertTimestampToUnixTimestampIPNS_7QLValueES3_EENS_6StatusET_T0_
669
670
template<typename PTypePtr, typename RTypePtr>
671
Status ConvertTimeuuidToUnixTimestamp(PTypePtr source, RTypePtr target) {
672
  return STATUS(RuntimeError, "Not yet implemented");
673
}
674
675
template<typename PTypePtr, typename RTypePtr>
676
Status ConvertToMaxTimeuuid(PTypePtr source, RTypePtr target) {
677
  return STATUS(RuntimeError, "Not yet implemented");
678
}
679
680
template<typename PTypePtr, typename RTypePtr>
681
Status ConvertToMinTimeuuid(PTypePtr source, RTypePtr target) {
682
  return STATUS(RuntimeError, "Not yet implemented");
683
}
684
685
//--------------------------------------------------------------------------------------------------
686
// The following functions are for conversions from VarInt to the other numeric types.
687
688
template<typename PTypePtr, typename RTypePtr>
689
0
Status ConvertVarintToI8(PTypePtr source, RTypePtr target) {
690
0
  if (source->IsNull()) {
691
0
    target->SetNull();
692
0
  } else {
693
0
    int64_t val = VERIFY_RESULT(source->varint_value().ToInt64());
694
0
    if (val < INT8_MIN || val > INT8_MAX) {
695
0
      return STATUS(InvalidArgument, "VarInt cannot be converted to int8 due to overflow");
696
0
    }
697
0
    target->set_int8_value(val);
698
0
  }
699
0
  return Status::OK();
700
0
}
Unexecuted instantiation: _ZN2yb4bfpg17ConvertVarintToI8INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertVarintToI8INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg17ConvertVarintToI8IPNS_7QLValueES3_EENS_6StatusET_T0_
701
702
template<typename PTypePtr, typename RTypePtr>
703
0
Status ConvertVarintToI16(PTypePtr source, RTypePtr target) {
704
0
  if (source->IsNull()) {
705
0
    target->SetNull();
706
0
  } else {
707
0
    int64_t val = VERIFY_RESULT(source->varint_value().ToInt64());
708
0
    if (val < INT16_MIN || val > INT16_MAX) {
709
0
      return STATUS(InvalidArgument, "VarInt cannot be converted to int16 due to overflow");
710
0
    }
711
0
    target->set_int16_value(val);
712
0
  }
713
0
  return Status::OK();
714
0
}
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI16INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI16INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI16IPNS_7QLValueES3_EENS_6StatusET_T0_
715
716
template<typename PTypePtr, typename RTypePtr>
717
0
Status ConvertVarintToI32(PTypePtr source, RTypePtr target) {
718
0
  if (source->IsNull()) {
719
0
    target->SetNull();
720
0
  } else {
721
0
    int64_t val = VERIFY_RESULT(source->varint_value().ToInt64());
722
0
    if (val < INT32_MIN || val > INT32_MAX) {
723
0
      return STATUS(InvalidArgument, "VarInt cannot be converted to int32 due to overflow");
724
0
    }
725
0
    target->set_int32_value(static_cast<int32_t>(val));
726
0
  }
727
0
  return Status::OK();
728
0
}
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI32INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI32INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI32IPNS_7QLValueES3_EENS_6StatusET_T0_
729
730
template<typename PTypePtr, typename RTypePtr>
731
0
Status ConvertVarintToI64(PTypePtr source, RTypePtr target) {
732
0
  if (source->IsNull()) {
733
0
    target->SetNull();
734
0
  } else {
735
0
    int64_t val = VERIFY_RESULT(source->varint_value().ToInt64());
736
0
    target->set_int64_value(val);
737
0
  }
738
0
  return Status::OK();
739
0
}
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI64INSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI64INSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg18ConvertVarintToI64IPNS_7QLValueES3_EENS_6StatusET_T0_
740
741
template<typename PTypePtr, typename RTypePtr>
742
0
Status ConvertVarintToFloat(PTypePtr source, RTypePtr target) {
743
0
  if (source->IsNull()) {
744
0
    target->SetNull();
745
0
  } else {
746
    // This may lose precision, it should return the closest float value to the input number.
747
0
    target->set_float_value(static_cast<float>(VERIFY_RESULT(CheckedStold(
748
0
        source->varint_value().ToString()))));
749
0
  }
750
0
  return Status::OK();
751
0
}
Unexecuted instantiation: _ZN2yb4bfpg20ConvertVarintToFloatINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg20ConvertVarintToFloatINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg20ConvertVarintToFloatIPNS_7QLValueES3_EENS_6StatusET_T0_
752
753
template<typename PTypePtr, typename RTypePtr>
754
0
Status ConvertVarintToDouble(PTypePtr source, RTypePtr target) {
755
0
  if (source->IsNull()) {
756
0
    target->SetNull();
757
0
  } else {
758
    // This may lose precision, it should return the closest double value to the input number.
759
0
    target->set_double_value(VERIFY_RESULT(CheckedStold(
760
0
        source->varint_value().ToString())));
761
0
  }
762
0
  return Status::OK();
763
0
}
Unexecuted instantiation: _ZN2yb4bfpg21ConvertVarintToDoubleINSt3__110shared_ptrINS0_11BFTestValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg21ConvertVarintToDoubleINSt3__110shared_ptrINS_7QLValueEEES5_EENS_6StatusET_T0_
Unexecuted instantiation: _ZN2yb4bfpg21ConvertVarintToDoubleIPNS_7QLValueES3_EENS_6StatusET_T0_
764
765
} // namespace bfpg
766
} // namespace yb
767
768
#endif  // YB_BFPG_BFUNC_CONVERT_H_