YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/bfpg/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 PGSQL 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/bfpg/bfpg.h" for more general info.
23
//--------------------------------------------------------------------------------------------------
24
25
#ifndef YB_BFPG_BFUNC_STANDARD_H_
26
#define YB_BFPG_BFUNC_STANDARD_H_
27
28
#include <string>
29
30
#include "yb/util/status.h"
31
#include "yb/util/status_log.h"
32
#include "yb/util/uuid.h"
33
34
namespace yb {
35
namespace bfpg {
36
37
//--------------------------------------------------------------------------------------------------
38
// Dummy function for minimum opcode.
39
0
inline CHECKED_STATUS NoOp() {
40
0
  return Status::OK();
41
0
}
42
43
// ServerOperator that takes no argument and has no return value.
44
0
inline CHECKED_STATUS ServerOperator() {
45
0
  LOG(ERROR) << "Only tablet servers can execute this builtin call";
46
0
  return STATUS(RuntimeError, "Only tablet servers can execute this builtin call");
47
0
}
48
49
// ServerOperator that takes 1 argument and has a return value.
50
template<typename PTypePtr, typename RTypePtr>
51
0
CHECKED_STATUS ServerOperator(PTypePtr arg1, RTypePtr result) {
52
0
  LOG(ERROR) << "Only tablet servers can execute this builtin call";
53
0
  return STATUS(RuntimeError, "Only tablet servers can execute this builtin call");
54
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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::bfpg::ServerOperator<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*)
55
56
// This is not used but implemented as an example for future coding.
57
// ServerOperator that takes 2 arguments and has a return value.
58
template<typename PTypePtr, typename RTypePtr>
59
CHECKED_STATUS ServerOperator(PTypePtr arg1, PTypePtr arg2, RTypePtr result) {
60
  LOG(ERROR) << "Only tablet servers can execute this builtin call";
61
  return STATUS(RuntimeError, "Only tablet servers can execute this builtin call");
62
}
63
64
//--------------------------------------------------------------------------------------------------
65
// "+" and "-".
66
67
template<typename PTypePtr, typename RTypePtr>
68
0
Status AddI64I64(PTypePtr x, PTypePtr y, RTypePtr result) {
69
0
  if (x->IsNull() || y->IsNull()) {
70
0
    result->SetNull();
71
0
  } else {
72
0
    result->set_int64_value(x->int64_value() + y->int64_value());
73
0
  }
74
0
  return Status::OK();
75
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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>)
Unexecuted instantiation: yb::Status yb::bfpg::AddI64I64<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
76
77
template<typename PTypePtr, typename RTypePtr>
78
0
Status AddDoubleDouble(PTypePtr x, PTypePtr y, RTypePtr result) {
79
0
  if (x->IsNull() || y->IsNull()) {
80
0
    result->SetNull();
81
0
  } else {
82
0
    result->set_double_value(x->double_value() + y->double_value());
83
0
  }
84
0
  return Status::OK();
85
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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::bfpg::AddDoubleDouble<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
86
87
template<typename PTypePtr, typename RTypePtr>
88
0
Status AddStringString(PTypePtr x, PTypePtr y, RTypePtr result) {
89
0
  if (x->IsNull() || y->IsNull()) {
90
0
    result->SetNull();
91
0
  } else {
92
0
    result->set_string_value(x->string_value() + y->string_value());
93
0
  }
94
0
  return Status::OK();
95
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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::bfpg::AddStringString<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
96
97
template<typename PTypePtr, typename RTypePtr>
98
0
Status AddStringDouble(PTypePtr x, PTypePtr y, RTypePtr result) {
99
0
  if (x->IsNull() || y->IsNull()) {
100
0
    result->SetNull();
101
0
  } else {
102
0
    result->set_string_value(x->string_value() + std::to_string(y->double_value()));
103
0
  }
104
0
  return Status::OK();
105
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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::bfpg::AddStringDouble<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
106
107
template<typename PTypePtr, typename RTypePtr>
108
0
Status AddDoubleString(PTypePtr x, PTypePtr y, RTypePtr result) {
109
0
  if (x->IsNull() || y->IsNull()) {
110
0
    result->SetNull();
111
0
  } else {
112
0
    result->set_string_value(std::to_string(x->double_value()) + y->string_value());
113
0
  }
114
0
  return Status::OK();
115
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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::bfpg::AddDoubleString<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
116
117
template<typename PTypePtr, typename RTypePtr>
118
0
Status SubI64I64(PTypePtr x, PTypePtr y, RTypePtr result) {
119
0
  if (x->IsNull() || y->IsNull()) {
120
0
    result->SetNull();
121
0
  } else {
122
0
    result->set_int64_value(x->int64_value() - y->int64_value());
123
0
  }
124
0
  return Status::OK();
125
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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>)
Unexecuted instantiation: yb::Status yb::bfpg::SubI64I64<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
126
127
template<typename PTypePtr, typename RTypePtr>
128
0
Status SubDoubleDouble(PTypePtr x, PTypePtr y, RTypePtr result) {
129
0
  if (x->IsNull() || y->IsNull()) {
130
0
    result->SetNull();
131
0
  } else {
132
0
    result->set_double_value(x->double_value() - y->double_value());
133
0
  }
134
0
  return Status::OK();
135
0
}
Unexecuted instantiation: yb::Status yb::bfpg::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::bfpg::SubDoubleDouble<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
136
137
//--------------------------------------------------------------------------------------------------
138
// Comparison.
139
template<typename PTypePtr, typename RTypePtr>
140
0
Status Equal(PTypePtr x, PTypePtr y, RTypePtr result) {
141
0
  if (x->IsNull() || y->IsNull()) {
142
0
    result->set_bool_value(false);
143
0
  } else {
144
0
    result->set_bool_value(x->value() == y->value());
145
0
  }
146
0
  return Status::OK();
147
0
}
Unexecuted instantiation: yb::Status yb::bfpg::Equal<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::bfpg::Equal<yb::QLValue*, yb::QLValue*>(yb::QLValue*, yb::QLValue*, yb::QLValue*)
148
149
//--------------------------------------------------------------------------------------------------
150
// Now().
151
template<typename RTypePtr>
152
0
Status NowTimeUuid(RTypePtr result) {
153
0
  uuid_t linux_time_uuid;
154
0
  uuid_generate_time(linux_time_uuid);
155
0
  Uuid time_uuid(linux_time_uuid);
156
0
  CHECK_OK(time_uuid.IsTimeUuid());
157
0
  CHECK_OK(time_uuid.HashMACAddress());
158
0
  result->set_timeuuid_value(time_uuid);
159
0
  return Status::OK();
160
0
}
Unexecuted instantiation: yb::Status yb::bfpg::NowTimeUuid<std::__1::shared_ptr<yb::QLValue> >(std::__1::shared_ptr<yb::QLValue>)
Unexecuted instantiation: yb::Status yb::bfpg::NowTimeUuid<yb::QLValue*>(yb::QLValue*)
161
162
//--------------------------------------------------------------------------------------------------
163
164
} // namespace bfpg
165
} // namespace yb
166
167
#endif  // YB_BFPG_BFUNC_STANDARD_H_