YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/bfql/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 QL but implemented in C++, and this module represents the
16
// metadata of a builtin function.
17
//--------------------------------------------------------------------------------------------------
18
19
#ifndef YB_BFQL_BFDECL_H_
20
#define YB_BFQL_BFDECL_H_
21
22
#include "yb/bfql/tserver_opcodes.h"
23
24
#include "yb/common/value.pb.h"
25
26
#include "yb/gutil/macros.h"
27
28
namespace yb {
29
namespace bfql {
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 QL name: This is the name of the builtin function.
34
//    - A QL parameter types: This is the signature of the builtin function.
35
//    - A QL 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
         const char *bfopcode_name,
43
         DataType return_type,
44
         std::initializer_list<DataType> param_types,
45
         TSOpcode tsopcode = TSOpcode::kNoOp,
46
         bool implemented = true)
47
      : cpp_name_(cpp_name),
48
        ql_name_(ql_name),
49
        bfopcode_name_(bfopcode_name),
50
        return_type_(return_type),
51
        param_types_(param_types),
52
        tsopcode_(tsopcode),
53
4.47M
        implemented_(implemented) {
54
4.47M
  }
55
56
777
  const char *cpp_name() const {
57
777
    return cpp_name_;
58
777
  }
59
60
1.23k
  const char *ql_name() const {
61
1.23k
    return ql_name_;
62
1.23k
  }
63
64
159
  const char *bfopcode_name() const {
65
159
    return bfopcode_name_;
66
159
  }
67
68
1.90k
  const DataType& return_type() const {
69
1.90k
    return return_type_;
70
1.90k
  }
71
72
9.51k
  const std::vector<DataType>& param_types() const {
73
9.51k
    return param_types_;
74
9.51k
  }
75
76
0
  size_t param_count() const {
77
0
    return param_types_.size();
78
0
  }
79
80
344
  TSOpcode tsopcode() const {
81
344
    return tsopcode_;
82
344
  }
83
84
1.26k
  bool is_server_operator() const {
85
1.26k
    return tsopcode_ != TSOpcode::kNoOp;
86
1.26k
  }
87
88
1.38k
  bool implemented() const {
89
1.38k
    return implemented_;
90
1.38k
  }
91
92
101
  bool is_collection_bcall() const {
93
101
    return is_collection_op(tsopcode_);
94
101
  }
95
96
0
  bool is_aggregate_bcall() const {
97
0
    return is_aggregate_op(tsopcode_);
98
0
  }
99
100
101
  static bool is_collection_op(TSOpcode tsopcode) {
101
101
    switch (tsopcode) {
102
19
      case TSOpcode::kMapExtend: FALLTHROUGH_INTENDED;
103
29
      case TSOpcode::kMapRemove: FALLTHROUGH_INTENDED;
104
44
      case TSOpcode::kSetExtend: FALLTHROUGH_INTENDED;
105
55
      case TSOpcode::kSetRemove: FALLTHROUGH_INTENDED;
106
70
      case TSOpcode::kListAppend: FALLTHROUGH_INTENDED;
107
79
      case TSOpcode::kListPrepend: FALLTHROUGH_INTENDED;
108
90
      case TSOpcode::kListRemove:
109
90
        return true;
110
11
      default:
111
11
        return false;
112
101
    }
113
101
  }
114
115
1.41k
  static bool is_aggregate_op(TSOpcode tsopcode) {
116
1.41k
    switch (tsopcode) {
117
58
      case TSOpcode::kAvg: FALLTHROUGH_INTENDED;
118
271
      case TSOpcode::kCount: FALLTHROUGH_INTENDED;
119
349
      case TSOpcode::kMax: FALLTHROUGH_INTENDED;
120
424
      case TSOpcode::kMin: FALLTHROUGH_INTENDED;
121
502
      case TSOpcode::kSum:
122
502
        return true;
123
916
      default:
124
916
        return false;
125
1.41k
    }
126
1.41k
  }
127
128
 private:
129
  const char *cpp_name_;
130
  const char *ql_name_;
131
  const char *bfopcode_name_;
132
  DataType return_type_;
133
  std::vector<DataType> param_types_;
134
  TSOpcode tsopcode_;
135
  bool implemented_;
136
};
137
138
} // namespace bfql
139
} // namespace yb
140
141
#endif  // YB_BFQL_BFDECL_H_