YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_bcall.h
Line
Count
Source
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
// Tree node definitions for expression.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_PTREE_PT_BCALL_H_
19
#define YB_YQL_CQL_QL_PTREE_PT_BCALL_H_
20
21
#include "yb/yql/cql/ql/ptree/pt_expr.h"
22
#include "yb/bfql/gen_opcodes.h"
23
24
namespace yb {
25
namespace ql {
26
27
// Expression node that represents builtin function calls.
28
class PTBcall : public PTExpr {
29
 public:
30
  //------------------------------------------------------------------------------------------------
31
  // Public types.
32
  typedef MCSharedPtr<PTBcall> SharedPtr;
33
  typedef MCSharedPtr<const PTBcall> SharedPtrConst;
34
35
  //------------------------------------------------------------------------------------------------
36
  // Constructor and destructor.
37
  PTBcall(MemoryContext *memctx,
38
          YBLocationPtr loc,
39
          const MCSharedPtr<MCString>& name,
40
          PTExprListNode::SharedPtr args);
41
  virtual ~PTBcall();
42
43
  // Support for shared_ptr.
44
  template<typename... TypeArgs>
45
953
  inline static PTBcall::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&&... args) {
46
953
    return MCMakeShared<PTBcall>(memctx, std::forward<TypeArgs>(args)...);
47
953
  }
48
49
  // Node semantics analysis.
50
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
51
52
  // Access API for arguments.
53
2.65k
  const MCList<PTExprPtr>& args() const {
54
2.65k
    return args_->node_list();
55
2.65k
  }
56
57
  // Access API for opcode.
58
1.45k
  bool is_server_operator() const {
59
1.45k
    return is_server_operator_;
60
1.45k
  }
61
1.45k
  int32_t bfopcode() const {
62
1.45k
    return bfopcode_;
63
1.45k
  }
64
65
  // Access API for cast opcodes.
66
1.45k
  const MCVector<yb::bfql::BFOpcode>& cast_ops() const {
67
1.45k
    return cast_ops_;
68
1.45k
  }
69
70
1.47k
  yb::bfql::BFOpcode result_cast_op() const {
71
1.47k
    return result_cast_op_;
72
1.47k
  }
73
74
2.21k
  const MCSharedPtr<MCString>& name() const {
75
2.21k
    return name_;
76
2.21k
  }
77
78
  // BCall result set column type in QL format.
79
  void rscol_type_PB(QLTypePB *pb_type) const override;
80
81
  virtual CHECKED_STATUS CheckOperator(SemContext *sem_context) override;
82
83
  virtual CHECKED_STATUS CheckCounterUpdateSupport(SemContext *sem_context) const override;
84
85
  CHECKED_STATUS CheckOperatorAfterArgAnalyze(SemContext *sem_context);
86
87
  void CollectReferencedIndexColnames(MCSet<std::string> *col_names) const override;
88
89
  std::string QLName(QLNameOption option = QLNameOption::kUserOriginalName) const override;
90
  bool IsAggregateCall() const override;
91
  yb::bfql::TSOpcode aggregate_opcode() const override;
92
93
  virtual bool HaveColumnRef() const override;
94
95
 private:
96
  // Builtin function name.
97
  MCSharedPtr<MCString> name_;
98
99
  // Arguments to builtin call.
100
  PTExprListNode::SharedPtr args_;
101
102
  // Builtin opcode can be either "bfql::BFOpcode" or "bfql::TSOpcode".
103
  // If is_tablet_server_operator_ is true, it is a TSOpcode. Otherwise, it is a BFOpcode.
104
  bool is_server_operator_;
105
  int32_t bfopcode_;
106
107
  // Casting arguments to correct datatype before calling the builtin-function.
108
  MCVector<yb::bfql::BFOpcode> cast_ops_;
109
110
  // Casting the returned result to expected type is also needed.
111
  yb::bfql::BFOpcode result_cast_op_;
112
};
113
114
class PTToken : public PTBcall {
115
 public:
116
  //------------------------------------------------------------------------------------------------
117
  // Public types.
118
  typedef MCSharedPtr<PTToken> SharedPtr;
119
  typedef MCSharedPtr<const PTToken> SharedPtrConst;
120
121
  //------------------------------------------------------------------------------------------------
122
  // Constructor and destructor.
123
  PTToken(MemoryContext *memctx,
124
          YBLocationPtr loc,
125
          const MCSharedPtr<MCString>& name,
126
200
          PTExprListNode::SharedPtr args) : PTBcall(memctx, loc, name, args) { }
127
128
50
  virtual ~PTToken() { }
129
130
  // Support for shared_ptr.
131
  template<typename... TypeArgs>
132
180
  inline static PTToken::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&&... args) {
133
180
    return MCMakeShared<PTToken>(memctx, std::forward<TypeArgs>(args)...);
134
180
  }
135
136
  // Node semantics analysis.
137
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
138
139
  // Check if token call is well formed before analyzing it
140
  virtual CHECKED_STATUS CheckOperator(SemContext *sem_context) override;
141
142
188
  bool is_partition_key_ref() const {
143
188
    return is_partition_key_ref_;
144
188
  }
145
146
14
  virtual const std::string func_name() {
147
14
    return "token";
148
14
  }
149
150
 private:
151
  // true if this token call is just reference to the partition key, e.g.: "token(h1, h2, h3)"
152
  // false for regular builtin calls to be evaluated, e.g.: "token(2,3,4)"
153
  bool is_partition_key_ref_ = false;
154
};
155
156
// Represents partition_hash() function.
157
class PTPartitionHash : public PTToken {
158
 public:
159
160
  //------------------------------------------------------------------------------------------------
161
  // Public types.
162
  typedef MCSharedPtr<PTPartitionHash> SharedPtr;
163
  typedef MCSharedPtr<const PTPartitionHash> SharedPtrConst;
164
165
  //------------------------------------------------------------------------------------------------
166
  // Constructor and destructor.
167
  PTPartitionHash(MemoryContext *memctx,
168
                  YBLocationPtr loc,
169
                  const MCSharedPtr<MCString>& name,
170
20
                  PTExprListNode::SharedPtr args) : PTToken(memctx, loc, name, args) { }
171
172
14
  virtual ~PTPartitionHash() {}
173
174
  // Support for shared_ptr.
175
  template<typename... TypeArgs>
176
20
  inline static PTPartitionHash::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&&... args) {
177
20
    return MCMakeShared<PTPartitionHash>(memctx, std::forward<TypeArgs>(args)...);
178
20
  }
179
180
14
  const std::string func_name() override {
181
14
    return "partition_hash";
182
14
  }
183
};
184
185
186
}  // namespace ql
187
}  // namespace yb
188
189
#endif  // YB_YQL_CQL_QL_PTREE_PT_BCALL_H_