YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
2.72M
        implemented_(implemented) {
54
2.72M
  }
55
56
0
  const char *cpp_name() const {
57
0
    return cpp_name_;
58
0
  }
59
60
0
  const char *ql_name() const {
61
0
    return ql_name_;
62
0
  }
63
64
0
  const char *bfopcode_name() const {
65
0
    return bfopcode_name_;
66
0
  }
67
68
1.13k
  const DataType& return_type() const {
69
1.13k
    return return_type_;
70
1.13k
  }
71
72
8.20k
  const std::vector<DataType>& param_types() const {
73
8.20k
    return param_types_;
74
8.20k
  }
75
76
0
  size_t param_count() const {
77
0
    return param_types_.size();
78
0
  }
79
80
334
  TSOpcode tsopcode() const {
81
334
    return tsopcode_;
82
334
  }
83
84
979
  bool is_server_operator() const {
85
979
    return tsopcode_ != TSOpcode::kNoOp;
86
979
  }
87
88
1.09k
  bool implemented() const {
89
1.09k
    return implemented_;
90
1.09k
  }
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.60k
  static bool is_aggregate_op(TSOpcode tsopcode) {
116
1.60k
    switch (tsopcode) {
117
58
      case TSOpcode::kAvg: FALLTHROUGH_INTENDED;
118
244
      case TSOpcode::kCount: FALLTHROUGH_INTENDED;
119
322
      case TSOpcode::kMax: FALLTHROUGH_INTENDED;
120
397
      case TSOpcode::kMin: FALLTHROUGH_INTENDED;
121
475
      case TSOpcode::kSum:
122
475
        return true;
123
1.12k
      default:
124
1.12k
        return false;
125
1.60k
    }
126
1.60k
  }
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_