YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/bfpg/bfdecl.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
// A builtin function is specified in PGSQL but implemented in C++, and this module represents the
16
// metadata of a builtin function.
17
//--------------------------------------------------------------------------------------------------
18
19
#ifndef YB_BFPG_BFDECL_H
20
#define YB_BFPG_BFDECL_H
21
22
#include "yb/bfpg/tserver_opcodes.h"
23
24
#include "yb/common/value.pb.h"
25
26
#include "yb/gutil/macros.h"
27
28
namespace yb {
29
namespace bfpg {
30
31
// This class contains the metadata of a builtin function, which has to principal components.
32
// 1. Specification of a builtin function.
33
//    - A PGSQL name: This is the name of the builtin function.
34
//    - A PGSQL parameter types: This is the signature of the builtin function.
35
//    - A PGSQL return type.
36
// 2. Definition or body of a builtin function.
37
//    - A C++ function name: This represents the implementation of the builtin function in C++.
38
class BFDecl {
39
 public:
40
  BFDecl(const char *cpp_name,
41
         const char *ql_name,
42
         DataType return_type,
43
         std::initializer_list<DataType> param_types,
44
         TSOpcode tsopcode = TSOpcode::kNoOp,
45
         bool implemented = true)
46
      : cpp_name_(cpp_name),
47
        ql_name_(ql_name),
48
        return_type_(return_type),
49
        param_types_(param_types),
50
        tsopcode_(tsopcode),
51
1.68M
        implemented_(implemented) {
52
1.68M
  }
53
54
300
  const char *cpp_name() const {
55
300
    return cpp_name_;
56
300
  }
57
58
363
  const char *ql_name() const {
59
363
    return ql_name_;
60
363
  }
61
62
196
  const DataType& return_type() const {
63
196
    return return_type_;
64
196
  }
65
66
546
  const std::vector<DataType>& param_types() const {
67
546
    return param_types_;
68
546
  }
69
70
0
  size_t param_count() const {
71
0
    return param_types_.size();
72
0
  }
73
74
0
  TSOpcode tsopcode() const {
75
0
    return tsopcode_;
76
0
  }
77
78
0
  bool is_server_operator() const {
79
0
    return tsopcode_ != TSOpcode::kNoOp;
80
0
  }
81
82
13
  bool implemented() const {
83
13
    return implemented_;
84
13
  }
85
86
0
  bool is_collection_bcall() const {
87
0
    return is_collection_op(tsopcode_);
88
0
  }
89
90
0
  bool is_aggregate_bcall() const {
91
0
    return is_aggregate_op(tsopcode_);
92
0
  }
93
94
0
  static bool is_collection_op(TSOpcode tsopcode) {
95
0
    switch (tsopcode) {
96
0
      case TSOpcode::kMapExtend: FALLTHROUGH_INTENDED;
97
0
      case TSOpcode::kMapRemove: FALLTHROUGH_INTENDED;
98
0
      case TSOpcode::kSetExtend: FALLTHROUGH_INTENDED;
99
0
      case TSOpcode::kSetRemove: FALLTHROUGH_INTENDED;
100
0
      case TSOpcode::kListAppend: FALLTHROUGH_INTENDED;
101
0
      case TSOpcode::kListPrepend: FALLTHROUGH_INTENDED;
102
0
      case TSOpcode::kListRemove:
103
0
        return true;
104
0
      default:
105
0
        return false;
106
0
    }
107
0
  }
108
109
0
  static bool is_aggregate_op(TSOpcode tsopcode) {
110
0
    switch (tsopcode) {
111
0
      case TSOpcode::kAvg: FALLTHROUGH_INTENDED;
112
0
      case TSOpcode::kCount: FALLTHROUGH_INTENDED;
113
0
      case TSOpcode::kMax: FALLTHROUGH_INTENDED;
114
0
      case TSOpcode::kMin: FALLTHROUGH_INTENDED;
115
0
      case TSOpcode::kSumInt8: FALLTHROUGH_INTENDED;
116
0
      case TSOpcode::kSumInt16: FALLTHROUGH_INTENDED;
117
0
      case TSOpcode::kSumInt32: FALLTHROUGH_INTENDED;
118
0
      case TSOpcode::kSumInt64: FALLTHROUGH_INTENDED;
119
0
      case TSOpcode::kSumFloat: FALLTHROUGH_INTENDED;
120
0
      case TSOpcode::kSumDouble:
121
0
        return true;
122
0
      default:
123
0
        return false;
124
0
    }
125
0
  }
126
127
 private:
128
  const char *cpp_name_;
129
  const char *ql_name_;
130
  DataType return_type_;
131
  std::vector<DataType> param_types_;
132
  TSOpcode tsopcode_;
133
  bool implemented_;
134
};
135
136
} // namespace bfpg
137
} // namespace yb
138
139
#endif  // YB_BFPG_BFDECL_H