YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/bfql/bfql_template.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 a few templates to be used in file "bfql.h". It defines the actual
16
// implementation for compilation and execution of a builtin call.
17
//--------------------------------------------------------------------------------------------------
18
19
#ifndef YB_BFQL_BFQL_TEMPLATE_H_
20
#define YB_BFQL_BFQL_TEMPLATE_H_
21
22
#include <fcntl.h>
23
24
#include <functional>
25
#include <vector>
26
27
#include "yb/bfql/gen_opcodes.h"
28
#include "yb/bfql/gen_operator.h"
29
30
#include "yb/gutil/integral_types.h"
31
#include "yb/gutil/macros.h"
32
#include "yb/gutil/strings/substitute.h"
33
34
#include "yb/util/fault_injection.h"
35
#include "yb/util/logging.h"
36
37
namespace yb {
38
namespace bfql {
39
40
//--------------------------------------------------------------------------------------------------
41
// Find the builtin opcode, declaration, and return type for a builtin call.
42
// Inputs: Builtin function name and parameter types.
43
// Outputs: opcode and bfdecl.
44
// In/Out parameter: return_type
45
//   If return_type is given, check if it is compatible with the declaration.
46
//   If not, return_type is an output parameter whose value is the return type of the builtin.
47
Status FindOpcodeByType(const string& ql_name,
48
                        const std::vector<DataType>& actual_types,
49
                        BFOpcode *opcode,
50
                        const BFDecl **bfdecl,
51
                        DataType *return_type);
52
53
// The effect is the same as function "FindOpcodeByType()", but it takes arguments instead types.
54
// NOTE:
55
//   RTypePtr can be either a raw (*) or shared (const shared_ptr&) pointer.
56
//   PTypePtrCollection can be any standard collection of PType raw or shared pointer.
57
//     std::vector<PTypePtr>, std::list<PTypePtr>,  std::set<PTypePtr>, ...
58
template<typename PTypePtrCollection, typename RTypePtr>
59
Status FindOpcode(const string& ql_name,
60
                  const PTypePtrCollection& params,
61
                  BFOpcode *opcode,
62
                  const BFDecl **bfdecl,
63
1.35k
                  RTypePtr result) {
64
65
  // Read argument types.
66
1.35k
  std::vector<DataType> actual_types(params.size(), DataType::UNKNOWN_DATA);
67
1.35k
  int pindex = 0;
68
1.76k
  for (const auto& param : params) {
69
1.76k
    actual_types[pindex] = param->ql_type_id();
70
1.76k
    pindex++;
71
1.76k
  }
72
73
  // Get the opcode and declaration.
74
1.35k
  if (result == nullptr) {
75
0
    return FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, nullptr);
76
0
  }
77
78
  // Get the opcode, declaration, and return type.
79
1.35k
  DataType return_type = result->ql_type_id();
80
1.35k
  RETURN_NOT_OK(FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, &return_type));
81
1.26k
  result->set_ql_type_id(return_type);
82
83
1.26k
  return Status::OK();
84
1.35k
}
85
} // namespace bfql
86
} // namespace yb
87
88
#endif  // YB_BFQL_BFQL_TEMPLATE_H_