YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/bfql/bfunc_standard.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 standard C++ functions that are used to support QL builtin functions.
16
// Each of these functions have one or more entries in builtin library directory. Note that C++
17
// functions don't have to be defined here as long as they are linked to this lib.
18
//
19
// Once written, this function should not be changed to avoid compatibility issues. That is,
20
// server might runs one version while client use a different version of this function.
21
//
22
// See the header of file "/util/bfql/bfql.h" for more general info.
23
//--------------------------------------------------------------------------------------------------
24
25
#ifndef YB_BFQL_BFUNC_STANDARD_H_
26
#define YB_BFQL_BFUNC_STANDARD_H_
27
28
#include <fcntl.h>
29
#include <stdint.h>
30
#include <uuid/uuid.h>
31
32
#include <cstring>
33
#include <iostream>
34
#include <locale>
35
#include <string>
36
#include <unordered_set>
37
38
#include "yb/common/jsonb.h"
39
#include "yb/common/ql_protocol.pb.h"
40
#include "yb/common/ql_type.h"
41
42
#include "yb/util/status_fwd.h"
43
#include "yb/util/date_time.h"
44
#include "yb/util/fault_injection.h"
45
#include "yb/util/logging.h"
46
#include "yb/util/status_log.h"
47
#include "yb/util/string_util.h"
48
#include "yb/util/uuid.h"
49
#include "yb/util/yb_partition.h"
50
51
namespace yb {
52
53
bool operator ==(const QLValuePB& lhs, const QLValuePB& rhs);
54
55
namespace bfql {
56
57
//--------------------------------------------------------------------------------------------------
58
// Dummy function for minimum opcode.
59
0
inline CHECKED_STATUS NoOp() {
60
0
  return Status::OK();
61
0
}
62
63
// ServerOperator that takes no argument and has no return value.
64
0
inline CHECKED_STATUS ServerOperator() {
65
0
  LOG(ERROR) << "Only tablet servers can execute this builtin call";
66
0
  return STATUS(RuntimeError, "Only tablet servers can execute this builtin call");
67
0
}
68
69
// ServerOperator that takes 1 argument and has a return value.
70
template<typename PTypePtr, typename RTypePtr>
71
0
CHECKED_STATUS ServerOperator(PTypePtr arg1, RTypePtr result) {
72
0
  LOG(ERROR) << "Only tablet servers can execute this builtin call";
73
0
  return STATUS(RuntimeError, "Only tablet servers can execute this builtin call");
74
0
}
Unexecuted instantiation: yb::Status yb::bfql::ServerOperator<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::ServerOperator<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*)
75
76
// This is not used but implemented as an example for future coding.
77
// ServerOperator that takes 2 arguments and has a return value.
78
template<typename PTypePtr, typename RTypePtr>
79
0
CHECKED_STATUS ServerOperator(PTypePtr arg1, PTypePtr arg2, RTypePtr result) {
80
0
  LOG(ERROR) << "Only tablet servers can execute this builtin call";
81
0
  return STATUS(RuntimeError, "Only tablet servers can execute this builtin call");
82
0
}
Unexecuted instantiation: yb::Status yb::bfql::ServerOperator<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::ServerOperator<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
83
84
//--------------------------------------------------------------------------------------------------
85
86
template<typename PTypePtr, typename RTypePtr>
87
13
uint16_t YBHash(const vector<PTypePtr>& params, RTypePtr result) {
88
13
  string encoded_key = "";
89
23
  for (const PTypePtr& param : params) {
90
23
    param->AppendToKeyBytes(&encoded_key);
91
23
  }
92
93
13
  return YBPartition::HashColumnCompoundValue(encoded_key);
94
13
}
Unexecuted instantiation: unsigned short yb::bfql::YBHash<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
unsigned short yb::bfql::YBHash<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
87
13
uint16_t YBHash(const vector<PTypePtr>& params, RTypePtr result) {
88
13
  string encoded_key = "";
89
23
  for (const PTypePtr& param : params) {
90
23
    param->AppendToKeyBytes(&encoded_key);
91
23
  }
92
93
13
  return YBPartition::HashColumnCompoundValue(encoded_key);
94
13
}
95
96
template<typename PTypePtr, typename RTypePtr>
97
8
CHECKED_STATUS Token(const vector<PTypePtr>& params, RTypePtr result) {
98
8
  uint16_t hash = YBHash(params, result);
99
  // Convert to CQL hash since this may be used in expressions above.
100
8
  result->set_int64_value(YBPartition::YBToCqlHashCode(hash));
101
8
  return Status::OK();
102
8
}
Unexecuted instantiation: yb::Status yb::bfql::Token<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::Token<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
97
8
CHECKED_STATUS Token(const vector<PTypePtr>& params, RTypePtr result) {
98
8
  uint16_t hash = YBHash(params, result);
99
  // Convert to CQL hash since this may be used in expressions above.
100
8
  result->set_int64_value(YBPartition::YBToCqlHashCode(hash));
101
8
  return Status::OK();
102
8
}
103
104
template<typename PTypePtr, typename RTypePtr>
105
5
CHECKED_STATUS PartitionHash(const vector<PTypePtr>& params, RTypePtr result) {
106
5
  result->set_int32_value(YBHash(params, result));
107
5
  return Status::OK();
108
5
}
Unexecuted instantiation: yb::Status yb::bfql::PartitionHash<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::PartitionHash<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
105
5
CHECKED_STATUS PartitionHash(const vector<PTypePtr>& params, RTypePtr result) {
106
5
  result->set_int32_value(YBHash(params, result));
107
5
  return Status::OK();
108
5
}
109
110
template<typename PTypePtr, typename RTypePtr>
111
48
CHECKED_STATUS ToJson(PTypePtr col, RTypePtr result) {
112
48
  common::Jsonb jsonb;
113
48
  Status s = jsonb.FromQLValuePB(col->value());
114
115
48
  if (!s.ok()) {
116
0
    return s.CloneAndPrepend(strings::Substitute(
117
0
        "Cannot convert $0 value $1 to $2",
118
0
        QLType::ToCQLString(InternalToDataType(col->type())),
119
0
        col->ToString(),
120
0
        QLType::ToCQLString(DataType::JSONB)));
121
0
  }
122
123
48
  result->set_jsonb_value(jsonb.MoveSerializedJsonb());
124
48
  return Status::OK();
125
48
}
Unexecuted instantiation: yb::Status yb::bfql::ToJson<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::ToJson<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*)
Line
Count
Source
111
48
CHECKED_STATUS ToJson(PTypePtr col, RTypePtr result) {
112
48
  common::Jsonb jsonb;
113
48
  Status s = jsonb.FromQLValuePB(col->value());
114
115
48
  if (!s.ok()) {
116
0
    return s.CloneAndPrepend(strings::Substitute(
117
0
        "Cannot convert $0 value $1 to $2",
118
0
        QLType::ToCQLString(InternalToDataType(col->type())),
119
0
        col->ToString(),
120
0
        QLType::ToCQLString(DataType::JSONB)));
121
0
  }
122
123
48
  result->set_jsonb_value(jsonb.MoveSerializedJsonb());
124
48
  return Status::OK();
125
48
}
126
127
template<typename PTypePtr, typename RTypePtr>
128
CHECKED_STATUS ttl(PTypePtr col, RTypePtr result) {
129
  return Status::OK();
130
}
131
132
template<typename PTypePtr, typename RTypePtr>
133
CHECKED_STATUS writetime(PTypePtr col, RTypePtr result) {
134
  return Status::OK();
135
}
136
137
//--------------------------------------------------------------------------------------------------
138
// Special ops for counter: "+counter" and "-counter".
139
140
template<typename PTypePtr, typename RTypePtr>
141
15
CHECKED_STATUS IncCounter(PTypePtr x, PTypePtr y, RTypePtr result) {
142
15
  if (x->IsNull()) {
143
7
    result->set_int64_value(y->int64_value());
144
8
  } else {
145
8
    result->set_int64_value(x->int64_value() + y->int64_value());
146
8
  }
147
15
  return Status::OK();
148
15
}
Unexecuted instantiation: yb::Status yb::bfql::IncCounter<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::IncCounter<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
Line
Count
Source
141
15
CHECKED_STATUS IncCounter(PTypePtr x, PTypePtr y, RTypePtr result) {
142
15
  if (x->IsNull()) {
143
7
    result->set_int64_value(y->int64_value());
144
8
  } else {
145
8
    result->set_int64_value(x->int64_value() + y->int64_value());
146
8
  }
147
15
  return Status::OK();
148
15
}
149
150
template<typename PTypePtr, typename RTypePtr>
151
4
CHECKED_STATUS DecCounter(PTypePtr x, PTypePtr y, RTypePtr result) {
152
4
  if (x->IsNull()) {
153
1
    result->set_int64_value(-y->int64_value());
154
3
  } else {
155
3
    result->set_int64_value(x->int64_value() - y->int64_value());
156
3
  }
157
4
  return Status::OK();
158
4
}
Unexecuted instantiation: yb::Status yb::bfql::DecCounter<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::DecCounter<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
Line
Count
Source
151
4
CHECKED_STATUS DecCounter(PTypePtr x, PTypePtr y, RTypePtr result) {
152
4
  if (x->IsNull()) {
153
1
    result->set_int64_value(-y->int64_value());
154
3
  } else {
155
3
    result->set_int64_value(x->int64_value() - y->int64_value());
156
3
  }
157
4
  return Status::OK();
158
4
}
159
160
//--------------------------------------------------------------------------------------------------
161
// "+" and "-".
162
163
template<typename PTypePtr, typename RTypePtr>
164
31
CHECKED_STATUS AddI64I64(PTypePtr x, PTypePtr y, RTypePtr result) {
165
31
  if (x->IsNull() || 
y->IsNull()27
) {
166
4
    result->SetNull();
167
27
  } else {
168
27
    result->set_int64_value(x->int64_value() + y->int64_value());
169
27
  }
170
31
  return Status::OK();
171
31
}
Unexecuted instantiation: yb::Status yb::bfql::AddI64I64<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::AddI64I64<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
Line
Count
Source
164
31
CHECKED_STATUS AddI64I64(PTypePtr x, PTypePtr y, RTypePtr result) {
165
31
  if (x->IsNull() || 
y->IsNull()27
) {
166
4
    result->SetNull();
167
27
  } else {
168
27
    result->set_int64_value(x->int64_value() + y->int64_value());
169
27
  }
170
31
  return Status::OK();
171
31
}
172
173
template<typename PTypePtr, typename RTypePtr>
174
0
CHECKED_STATUS AddDoubleDouble(PTypePtr x, PTypePtr y, RTypePtr result) {
175
0
  if (x->IsNull() || y->IsNull()) {
176
0
    result->SetNull();
177
0
  } else {
178
0
    result->set_double_value(x->double_value() + y->double_value());
179
0
  }
180
0
  return Status::OK();
181
0
}
Unexecuted instantiation: yb::Status yb::bfql::AddDoubleDouble<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::AddDoubleDouble<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
182
183
template<typename PTypePtr, typename RTypePtr>
184
0
CHECKED_STATUS AddStringString(PTypePtr x, PTypePtr y, RTypePtr result) {
185
0
  if (x->IsNull() || y->IsNull()) {
186
0
    result->SetNull();
187
0
  } else {
188
0
    result->set_string_value(x->string_value() + y->string_value());
189
0
  }
190
0
  return Status::OK();
191
0
}
Unexecuted instantiation: yb::Status yb::bfql::AddStringString<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::AddStringString<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
192
193
template<typename PTypePtr, typename RTypePtr>
194
0
CHECKED_STATUS AddStringDouble(PTypePtr x, PTypePtr y, RTypePtr result) {
195
0
  if (x->IsNull() || y->IsNull()) {
196
0
    result->SetNull();
197
0
  } else {
198
0
    result->set_string_value(x->string_value() + std::to_string(y->double_value()));
199
0
  }
200
0
  return Status::OK();
201
0
}
Unexecuted instantiation: yb::Status yb::bfql::AddStringDouble<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::AddStringDouble<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
202
203
template<typename PTypePtr, typename RTypePtr>
204
0
CHECKED_STATUS AddDoubleString(PTypePtr x, PTypePtr y, RTypePtr result) {
205
0
  if (x->IsNull() || y->IsNull()) {
206
0
    result->SetNull();
207
0
  } else {
208
0
    result->set_string_value(std::to_string(x->double_value()) + y->string_value());
209
0
  }
210
0
  return Status::OK();
211
0
}
Unexecuted instantiation: yb::Status yb::bfql::AddDoubleString<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::AddDoubleString<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
212
213
template<typename PTypePtr, typename RTypePtr>
214
CHECKED_STATUS AddMapMap(PTypePtr x, PTypePtr y, RTypePtr result) {
215
  // All calls allowed for this builtin are optimized away to avoid evaluating such expressions
216
  return STATUS(RuntimeError, "Arbitrary collection expressions are not supported");
217
}
218
219
template<typename PTypePtr, typename RTypePtr>
220
CHECKED_STATUS AddSetSet(PTypePtr x, PTypePtr y, RTypePtr result) {
221
  // All calls allowed for this builtin are optimized away to avoid evaluating such expressions
222
  return STATUS(RuntimeError, "Arbitrary collection expressions are not supported");
223
}
224
225
template<typename PTypePtr, typename RTypePtr>
226
CHECKED_STATUS AddListList(PTypePtr x, PTypePtr y, RTypePtr result) {
227
  // All calls allowed for this builtin are optimized away to avoid evaluating such expressions
228
  return STATUS(RuntimeError, "Arbitrary collection expressions are not supported");
229
}
230
231
template<typename PTypePtr, typename RTypePtr>
232
27
CHECKED_STATUS SubI64I64(PTypePtr x, PTypePtr y, RTypePtr result) {
233
27
  if (x->IsNull() || 
y->IsNull()23
) {
234
4
    result->SetNull();
235
23
  } else {
236
23
    result->set_int64_value(x->int64_value() - y->int64_value());
237
23
  }
238
27
  return Status::OK();
239
27
}
Unexecuted instantiation: yb::Status yb::bfql::SubI64I64<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::SubI64I64<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
Line
Count
Source
232
27
CHECKED_STATUS SubI64I64(PTypePtr x, PTypePtr y, RTypePtr result) {
233
27
  if (x->IsNull() || 
y->IsNull()23
) {
234
4
    result->SetNull();
235
23
  } else {
236
23
    result->set_int64_value(x->int64_value() - y->int64_value());
237
23
  }
238
27
  return Status::OK();
239
27
}
240
241
template<typename PTypePtr, typename RTypePtr>
242
0
CHECKED_STATUS SubDoubleDouble(PTypePtr x, PTypePtr y, RTypePtr result) {
243
0
  if (x->IsNull() || y->IsNull()) {
244
0
    result->SetNull();
245
0
  } else {
246
0
    result->set_double_value(x->double_value() - y->double_value());
247
0
  }
248
0
  return Status::OK();
249
0
}
Unexecuted instantiation: yb::Status yb::bfql::SubDoubleDouble<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::SubDoubleDouble<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
250
251
template<typename PTypePtr, typename RTypePtr>
252
CHECKED_STATUS SubMapSet(PTypePtr x, PTypePtr y, RTypePtr result) {
253
  // All calls allowed for this builtin are optimized away to avoid evaluating such expressions
254
  return STATUS(RuntimeError, "Arbitrary collection expressions are not supported");
255
}
256
257
template<typename PTypePtr, typename RTypePtr>
258
CHECKED_STATUS SubSetSet(PTypePtr x, PTypePtr y, RTypePtr result) {
259
  // All calls allowed for this builtin are optimized away to avoid evaluating such expressions
260
  return STATUS(RuntimeError, "Arbitrary collection expressions are not supported");
261
}
262
263
template<typename PTypePtr, typename RTypePtr>
264
CHECKED_STATUS SubListList(PTypePtr x, PTypePtr y, RTypePtr result) {
265
  // TODO All calls allowed for this builtin should be optimized away to avoid evaluating here.
266
  // But this is not yet implemented in DocDB so evaluating inefficiently and in-memory for now.
267
  // For clarity, this implementation should be removed (see e.g. SubSetSet above) as soon as
268
  // RemoveFromList is implemented in DocDB.
269
  result->set_list_value();
270
  if (x->IsNull() || y->IsNull()) {
271
    return Status::OK();
272
  }
273
274
  const QLSeqValuePB& xl = x->list_value();
275
  const QLSeqValuePB& yl = y->list_value();
276
  for (const QLValuePB& x_elem : xl.elems()) {
277
    bool should_remove = false;
278
    for (const QLValuePB& y_elem : yl.elems()) {
279
      if (x_elem == y_elem) {
280
        should_remove = true;
281
        break;
282
      }
283
    }
284
    if (!should_remove) {
285
      result->add_list_elem()->CopyFrom(x_elem);
286
    }
287
  }
288
  return Status::OK();
289
}
290
291
//--------------------------------------------------------------------------------------------------
292
// Now().
293
template<typename RTypePtr>
294
1
CHECKED_STATUS NowDate(RTypePtr result) {
295
1
  result->set_date_value(DateTime::DateNow());
296
1
  return Status::OK();
297
1
}
Unexecuted instantiation: yb::Status yb::bfql::NowDate<std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::NowDate<yb::QLValue*>(yb::QLValue*)
Line
Count
Source
294
1
CHECKED_STATUS NowDate(RTypePtr result) {
295
1
  result->set_date_value(DateTime::DateNow());
296
1
  return Status::OK();
297
1
}
298
299
template<typename RTypePtr>
300
1
CHECKED_STATUS NowTime(RTypePtr result) {
301
1
  result->set_time_value(DateTime::TimeNow());
302
1
  return Status::OK();
303
1
}
Unexecuted instantiation: yb::Status yb::bfql::NowTime<std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::NowTime<yb::QLValue*>(yb::QLValue*)
Line
Count
Source
300
1
CHECKED_STATUS NowTime(RTypePtr result) {
301
1
  result->set_time_value(DateTime::TimeNow());
302
1
  return Status::OK();
303
1
}
304
305
template<typename RTypePtr>
306
1
CHECKED_STATUS NowTimestamp(RTypePtr result) {
307
1
  result->set_timestamp_value(DateTime::TimestampNow());
308
1
  return Status::OK();
309
1
}
Unexecuted instantiation: yb::Status yb::bfql::NowTimestamp<std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::NowTimestamp<yb::QLValue*>(yb::QLValue*)
Line
Count
Source
306
1
CHECKED_STATUS NowTimestamp(RTypePtr result) {
307
1
  result->set_timestamp_value(DateTime::TimestampNow());
308
1
  return Status::OK();
309
1
}
310
311
template<typename RTypePtr>
312
59
CHECKED_STATUS NowTimeUuid(RTypePtr result) {
313
59
  uuid_t linux_time_uuid;
314
59
  uuid_generate_time(linux_time_uuid);
315
59
  Uuid time_uuid(linux_time_uuid);
316
59
  CHECK_OK(time_uuid.IsTimeUuid());
317
59
  CHECK_OK(time_uuid.HashMACAddress());
318
59
  result->set_timeuuid_value(time_uuid);
319
59
  return Status::OK();
320
59
}
Unexecuted instantiation: yb::Status yb::bfql::NowTimeUuid<std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::NowTimeUuid<yb::QLValue*>(yb::QLValue*)
Line
Count
Source
312
59
CHECKED_STATUS NowTimeUuid(RTypePtr result) {
313
59
  uuid_t linux_time_uuid;
314
59
  uuid_generate_time(linux_time_uuid);
315
59
  Uuid time_uuid(linux_time_uuid);
316
59
  CHECK_OK(time_uuid.IsTimeUuid());
317
59
  CHECK_OK(time_uuid.HashMACAddress());
318
59
  result->set_timeuuid_value(time_uuid);
319
59
  return Status::OK();
320
59
}
321
322
//--------------------------------------------------------------------------------------------------
323
// uuid().
324
static const uint16_t kUUIDType = 4;
325
template<typename RTypePtr>
326
7
CHECKED_STATUS GetUuid(RTypePtr result) {
327
7
  Uuid uuid = Uuid::Generate();
328
7
  DCHECK_EQ(uuid.version(), kUUIDType);
329
7
  if (uuid.version() != kUUIDType) {
330
0
    return STATUS_FORMAT(IllegalState, "Unexpected UUID type $0, expected $1.",
331
0
                         uuid.version(), kUUIDType);
332
0
  }
333
7
  result->set_uuid_value(uuid);
334
7
  return Status::OK();
335
7
}
Unexecuted instantiation: yb::Status yb::bfql::GetUuid<std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::GetUuid<yb::QLValue*>(yb::QLValue*)
Line
Count
Source
326
7
CHECKED_STATUS GetUuid(RTypePtr result) {
327
7
  Uuid uuid = Uuid::Generate();
328
7
  DCHECK_EQ(uuid.version(), kUUIDType);
329
7
  if (uuid.version() != kUUIDType) {
330
0
    return STATUS_FORMAT(IllegalState, "Unexpected UUID type $0, expected $1.",
331
0
                         uuid.version(), kUUIDType);
332
0
  }
333
7
  result->set_uuid_value(uuid);
334
7
  return Status::OK();
335
7
}
336
337
//--------------------------------------------------------------------------------------------------
338
// Map::Map
339
template<typename PTypePtr, typename RTypePtr>
340
5
CHECKED_STATUS MapConstructor(const vector<PTypePtr>& params, RTypePtr result) {
341
5
  auto *qlmap = result->mutable_map_value();
342
5
  RSTATUS_DCHECK(params.size()%2 == 0, RuntimeError, "Unexpected argument count for map::map");
343
21
  for (size_t i = 0; i < params.size(); 
i++16
) {
344
16
    *qlmap->add_keys() = params[i]->value();
345
16
    *qlmap->add_values() = params[++i]->value();
346
16
  }
347
5
  return Status::OK();
348
5
}
Unexecuted instantiation: yb::Status yb::bfql::MapConstructor<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::MapConstructor<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
340
5
CHECKED_STATUS MapConstructor(const vector<PTypePtr>& params, RTypePtr result) {
341
5
  auto *qlmap = result->mutable_map_value();
342
5
  RSTATUS_DCHECK(params.size()%2 == 0, RuntimeError, "Unexpected argument count for map::map");
343
21
  for (size_t i = 0; i < params.size(); 
i++16
) {
344
16
    *qlmap->add_keys() = params[i]->value();
345
16
    *qlmap->add_values() = params[++i]->value();
346
16
  }
347
5
  return Status::OK();
348
5
}
349
350
// Set::Set
351
template<typename PTypePtr, typename RTypePtr>
352
1
CHECKED_STATUS SetConstructor(const vector<PTypePtr>& params, RTypePtr result) {
353
1
  auto *qlset = result->mutable_set_value();
354
3
  for (const auto& param : params) {
355
3
    *qlset->add_elems() = param->value();
356
3
  }
357
1
  return Status::OK();
358
1
}
Unexecuted instantiation: yb::Status yb::bfql::SetConstructor<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::SetConstructor<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
352
1
CHECKED_STATUS SetConstructor(const vector<PTypePtr>& params, RTypePtr result) {
353
1
  auto *qlset = result->mutable_set_value();
354
3
  for (const auto& param : params) {
355
3
    *qlset->add_elems() = param->value();
356
3
  }
357
1
  return Status::OK();
358
1
}
359
360
// List::List
361
template<typename PTypePtr, typename RTypePtr>
362
3
CHECKED_STATUS ListConstructor(const vector<PTypePtr>& params, RTypePtr result) {
363
3
  auto *qllist = result->mutable_list_value();
364
9
  for (const auto& param : params) {
365
9
    *qllist->add_elems() = param->value();
366
9
  }
367
3
  return Status::OK();
368
3
}
Unexecuted instantiation: yb::Status yb::bfql::ListConstructor<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::ListConstructor<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
362
3
CHECKED_STATUS ListConstructor(const vector<PTypePtr>& params, RTypePtr result) {
363
3
  auto *qllist = result->mutable_list_value();
364
9
  for (const auto& param : params) {
365
9
    *qllist->add_elems() = param->value();
366
9
  }
367
3
  return Status::OK();
368
3
}
369
370
// Map::Frozen
371
template<typename PType>
372
0
std::map<PType, PType> MapFromVector(const std::vector<PType*>& params) {
373
0
  std::map<PType, PType> ordered_values;
374
0
  for (size_t vidx = 0; vidx < params.size(); vidx++) {
375
0
    auto kidx = vidx++;
376
0
    ordered_values[*params[kidx]] = *params[vidx];
377
0
  }
378
0
  return ordered_values;
379
0
}
380
381
template<typename PType>
382
0
std::map<PType, PType> MapFromVector(const std::vector<std::shared_ptr<PType>>& params) {
383
0
  std::map<PType, PType> ordered_values;
384
0
  for (size_t vidx = 0; vidx < params.size(); vidx++) {
385
0
    auto kidx = vidx++;
386
0
    ordered_values[*params[kidx]] = *params[vidx];
387
0
  }
388
0
  return ordered_values;
389
0
}
390
391
template<typename PTypePtr, typename RTypePtr>
392
0
CHECKED_STATUS MapFrozen(const vector<PTypePtr>& params, RTypePtr result) {
393
0
  auto map_elems = MapFromVector(params);
394
395
0
  auto *frozen_value = result->mutable_frozen_value();
396
0
  for (auto &elem : map_elems) {
397
0
    *frozen_value->add_elems() = elem.first.value();
398
0
    *frozen_value->add_elems() = elem.second.value();
399
0
  }
400
0
  return Status::OK();
401
0
}
Unexecuted instantiation: yb::Status yb::bfql::MapFrozen<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::MapFrozen<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
402
403
// Set::Frozen.
404
template<typename PType>
405
0
std::set<PType> SetFromVector(const std::vector<PType*>& params) {
406
0
  std::set<PType> ordered_values;
407
0
  for (size_t i = 0; i < params.size(); i++) {
408
0
    ordered_values.insert(*params[i]);
409
0
  }
410
0
  return ordered_values;
411
0
}
412
413
template<typename PType>
414
0
std::set<PType> SetFromVector(const std::vector<std::shared_ptr<PType>>& params) {
415
0
  std::set<PType> ordered_values;
416
0
  for (const auto& param : params) {
417
0
    ordered_values.insert(*param);
418
0
  }
419
0
  return ordered_values;
420
0
}
421
422
template<typename PTypePtr, typename RTypePtr>
423
0
CHECKED_STATUS SetFrozen(const vector<PTypePtr>& params, RTypePtr result) {
424
0
  auto set_elems = SetFromVector(params);
425
426
0
  auto *frozen_value = result->mutable_frozen_value();
427
0
  for (auto &elem : set_elems) {
428
0
    *frozen_value->add_elems() = elem.value();
429
0
  }
430
0
  return Status::OK();
431
0
}
Unexecuted instantiation: yb::Status yb::bfql::SetFrozen<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfql::SetFrozen<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
432
433
// List::Frozen.
434
template<typename PTypePtr, typename RTypePtr>
435
1
CHECKED_STATUS ListFrozen(const vector<PTypePtr>& params, RTypePtr result) {
436
1
  auto *frozen_value = result->mutable_frozen_value();
437
3
  for (const auto& param : params) {
438
3
    *frozen_value->add_elems() = param->value();
439
3
  }
440
1
  return Status::OK();
441
1
}
Unexecuted instantiation: yb::Status yb::bfql::ListFrozen<std::__1::shared_ptr<yb::QLValue>, std::__1::shared_ptr<yb::QLValue> >(std::__1::vector<std::__1::shared_ptr<yb::QLValue>, std::__1::allocator<std::__1::shared_ptr<yb::QLValue> > > const&, std::__1::shared_ptr<yb::QLValue>)
yb::Status yb::bfql::ListFrozen<yb::QLValue*, yb::QLValue*>(std::__1::vector<yb::QLValue*, std::__1::allocator<yb::QLValue*> > const&, yb::QLValue*)
Line
Count
Source
435
1
CHECKED_STATUS ListFrozen(const vector<PTypePtr>& params, RTypePtr result) {
436
1
  auto *frozen_value = result->mutable_frozen_value();
437
3
  for (const auto& param : params) {
438
3
    *frozen_value->add_elems() = param->value();
439
3
  }
440
1
  return Status::OK();
441
1
}
442
443
//--------------------------------------------------------------------------------------------------
444
445
} // namespace bfql
446
} // namespace yb
447
448
#endif  // YB_BFQL_BFUNC_STANDARD_H_