YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/column_arg.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
// Structure definitions for column descriptor of a table.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_PTREE_COLUMN_ARG_H_
19
#define YB_YQL_CQL_QL_PTREE_COLUMN_ARG_H_
20
21
#include "yb/common/types.h"
22
#include "yb/util/memory/mc_types.h"
23
#include "yb/yql/cql/ql/ptree/ptree_fwd.h"
24
25
namespace yb {
26
namespace ql {
27
28
// This class represents an argument in expressions, but it is not part of the parse tree. It is
29
// used during semantic and execution phase.
30
class ColumnArg {
31
 public:
32
  //------------------------------------------------------------------------------------------------
33
  // Public types.
34
  typedef std::shared_ptr<ColumnArg> SharedPtr;
35
  typedef std::shared_ptr<const ColumnArg> SharedPtrConst;
36
37
  ColumnArg(const ColumnDesc *desc = nullptr,
38
            const PTExprPtr& expr = nullptr)
39
481k
      : desc_(desc), expr_(expr) {
40
481k
  }
41
0
  ColumnArg(const ColumnArg &arg) : ColumnArg(arg.desc_, arg.expr_) {
42
0
  }
Unexecuted instantiation: _ZN2yb2ql9ColumnArgC2ERKS1_
Unexecuted instantiation: _ZN2yb2ql9ColumnArgC1ERKS1_
43
475k
  virtual ~ColumnArg() {
44
475k
  }
45
46
233k
  void Init(const ColumnDesc *desc, const PTExprPtr& expr) {
47
233k
    desc_ = desc;
48
233k
    expr_ = expr;
49
233k
  }
50
51
4.67M
  bool IsInitialized() const {
52
4.67M
    return desc_ != nullptr;
53
4.67M
  }
54
55
7.86M
  const ColumnDesc *desc() const {
56
7.86M
    return desc_;
57
7.86M
  }
58
59
7.77M
  const PTExprPtr& expr() const {
60
7.77M
    return expr_;
61
7.77M
  }
62
63
 protected:
64
  const ColumnDesc *desc_;
65
  PTExprPtr expr_;
66
};
67
68
// This class represents an operation on a column.
69
class ColumnOp : public ColumnArg {
70
 public:
71
  //------------------------------------------------------------------------------------------------
72
  // Public types.
73
  typedef std::shared_ptr<ColumnOp> SharedPtr;
74
  typedef std::shared_ptr<const ColumnOp> SharedPtrConst;
75
76
  ColumnOp(const ColumnDesc *desc = nullptr,
77
           const PTExprPtr& expr = nullptr,
78
           yb::QLOperator yb_op = yb::QLOperator::QL_OP_NOOP)
79
229k
      : ColumnArg(desc, expr), yb_op_(yb_op) {
80
229k
  }
81
  ColumnOp(const ColumnOp &column_op)
82
361
      : ColumnOp(column_op.desc_, column_op.expr_, column_op.yb_op_) {
83
361
  }
Unexecuted instantiation: _ZN2yb2ql8ColumnOpC2ERKS1_
_ZN2yb2ql8ColumnOpC1ERKS1_
Line
Count
Source
82
361
      : ColumnOp(column_op.desc_, column_op.expr_, column_op.yb_op_) {
83
361
  }
84
227k
  virtual ~ColumnOp() {
85
227k
  }
86
87
108k
  void Init(const ColumnDesc *desc, const PTExprPtr& expr, yb::QLOperator yb_op) {
88
108k
    desc_ = desc;
89
108k
    expr_ = expr;
90
108k
    yb_op_ = yb_op;
91
108k
  }
92
93
3.85M
  yb::QLOperator yb_op() const {
94
3.85M
    return yb_op_;
95
3.85M
  }
96
97
  void OutputTo(std::ostream* out) const;
98
99
 private:
100
  yb::QLOperator yb_op_;
101
};
102
103
class FuncOp {
104
 public:
105
  typedef std::shared_ptr<FuncOp> SharedPtr;
106
  typedef std::shared_ptr<const FuncOp> SharedPtrConst;
107
108
  FuncOp(const PTExprPtr& value_expr,
109
         const PTBcallPtr& func_expr,
110
         yb::QLOperator yb_op = yb::QLOperator::QL_OP_NOOP)
111
46
    : value_expr_(value_expr), func_expr_(func_expr), yb_op_(yb_op) {
112
46
  }
113
114
  void Init(const PTExprPtr& value_expr,
115
            const PTExprPtr& func_expr,
116
            yb::QLOperator yb_op);
117
118
46
  yb::QLOperator yb_op() const {
119
46
    return yb_op_;
120
46
  }
121
122
46
  PTExprPtr value_expr() const {
123
46
    return value_expr_;
124
46
  }
125
126
46
  PTBcallPtr func_expr() const {
127
46
    return func_expr_;
128
46
  }
129
130
 private:
131
  PTExprPtr value_expr_;
132
  PTBcallPtr func_expr_;
133
  yb::QLOperator yb_op_;
134
};
135
136
// This class represents a json column argument (e.g. "WHERE c1->'a'->'b'->>'c' = 'b'")
137
class JsonColumnArg : public ColumnArg {
138
 public:
139
  //------------------------------------------------------------------------------------------------
140
  // Public types.
141
  typedef std::shared_ptr<JsonColumnArg> SharedPtr;
142
  typedef std::shared_ptr<const JsonColumnArg> SharedPtrConst;
143
144
  JsonColumnArg(const ColumnDesc *desc = nullptr,
145
                const PTExprListNodePtr& args = nullptr,
146
                const PTExprPtr& expr = nullptr)
147
522
      : ColumnArg(desc, expr), args_(args) {
148
522
  }
149
150
  JsonColumnArg(const JsonColumnArg &sval)
151
148
      : JsonColumnArg(sval.desc_, sval.args_, sval.expr_) { }
Unexecuted instantiation: _ZN2yb2ql13JsonColumnArgC2ERKS1_
_ZN2yb2ql13JsonColumnArgC1ERKS1_
Line
Count
Source
151
148
      : JsonColumnArg(sval.desc_, sval.args_, sval.expr_) { }
152
153
465
  virtual ~JsonColumnArg() {
154
465
  }
155
156
176
  const PTExprListNodePtr& args() const {
157
176
    return args_;
158
176
  }
159
160
 protected:
161
  PTExprListNodePtr args_;
162
};
163
164
// This class represents a sub-column argument (e.g. "SET l[1] = 'b'")
165
class SubscriptedColumnArg : public ColumnArg {
166
 public:
167
  //------------------------------------------------------------------------------------------------
168
  // Public types.
169
  typedef std::shared_ptr<SubscriptedColumnArg> SharedPtr;
170
  typedef std::shared_ptr<const SubscriptedColumnArg> SharedPtrConst;
171
172
  SubscriptedColumnArg(const ColumnDesc *desc = nullptr,
173
                       const PTExprListNodePtr& args = nullptr,
174
                       const PTExprPtr& expr = nullptr)
175
237
      : ColumnArg(desc, expr), args_(args) {
176
237
  }
177
178
  SubscriptedColumnArg(const SubscriptedColumnArg &sval)
179
5
      : SubscriptedColumnArg(sval.desc_, sval.args_, sval.expr_) { }
Unexecuted instantiation: _ZN2yb2ql20SubscriptedColumnArgC2ERKS1_
_ZN2yb2ql20SubscriptedColumnArgC1ERKS1_
Line
Count
Source
179
5
      : SubscriptedColumnArg(sval.desc_, sval.args_, sval.expr_) { }
180
181
231
  virtual ~SubscriptedColumnArg() {
182
231
  }
183
184
119
  const PTExprListNodePtr& args() const {
185
119
    return args_;
186
119
  }
187
188
 protected:
189
  PTExprListNodePtr args_;
190
};
191
192
// This class represents an operation on a json column (e.g. "WHERE c1->'a'->'b'->>'c' = 'b'").
193
class JsonColumnOp : public JsonColumnArg {
194
 public:
195
  //------------------------------------------------------------------------------------------------
196
  // Public types.
197
  typedef std::shared_ptr<JsonColumnOp> SharedPtr;
198
  typedef std::shared_ptr<const JsonColumnOp> SharedPtrConst;
199
200
  JsonColumnOp(const ColumnDesc *desc = nullptr,
201
                      const PTExprListNodePtr& args = nullptr,
202
                      const PTExprPtr& expr = nullptr,
203
                      yb::QLOperator yb_op = yb::QLOperator::QL_OP_NOOP)
204
188
      : JsonColumnArg(desc, args, expr), yb_op_(yb_op) {
205
188
  }
206
  JsonColumnOp(const JsonColumnOp &subcol_op)
207
0
      : JsonColumnOp(subcol_op.desc_, subcol_op.args_, subcol_op.expr_, subcol_op.yb_op_) {
208
0
  }
209
185
  virtual ~JsonColumnOp() {
210
185
  }
211
212
  void Init(const ColumnDesc *desc, const PTExprListNodePtr& args,
213
0
            const PTExprPtr& expr, yb::QLOperator yb_op) {
214
0
    desc_ = desc;
215
0
    args_ = args;
216
0
    expr_ = expr;
217
0
    yb_op_ = yb_op;
218
0
  }
219
220
112
  yb::QLOperator yb_op() const {
221
112
    return yb_op_;
222
112
  }
223
224
  // Name of a Catalog::IndexTable::ExprColumn is created by mangling original name from users.
225
  string IndexExprToColumnName() const;
226
227
 private:
228
  yb::QLOperator yb_op_;
229
};
230
231
// This class represents an operation on a sub-column (e.g. "WHERE l[1] = 'b'").
232
class SubscriptedColumnOp : public SubscriptedColumnArg {
233
 public:
234
  //------------------------------------------------------------------------------------------------
235
  // Public types.
236
  typedef std::shared_ptr<SubscriptedColumnOp> SharedPtr;
237
  typedef std::shared_ptr<const SubscriptedColumnOp> SharedPtrConst;
238
239
  SubscriptedColumnOp(const ColumnDesc *desc = nullptr,
240
                      const PTExprListNodePtr& args = nullptr,
241
                      const PTExprPtr& expr = nullptr,
242
                      yb::QLOperator yb_op = yb::QLOperator::QL_OP_NOOP)
243
178
      : SubscriptedColumnArg(desc, args, expr), yb_op_(yb_op) {
244
178
  }
245
  SubscriptedColumnOp(const SubscriptedColumnOp &subcol_op)
246
0
      : SubscriptedColumnOp(subcol_op.desc_, subcol_op.args_, subcol_op.expr_, subcol_op.yb_op_) {
247
0
  }
248
172
  virtual ~SubscriptedColumnOp() {
249
172
  }
250
251
  void Init(const ColumnDesc *desc, const PTExprListNodePtr& args,
252
0
            const PTExprPtr& expr, yb::QLOperator yb_op) {
253
0
    desc_ = desc;
254
0
    args_ = args;
255
0
    expr_ = expr;
256
0
    yb_op_ = yb_op;
257
0
  }
258
259
85
  yb::QLOperator yb_op() const {
260
85
    return yb_op_;
261
85
  }
262
263
0
  string IndexExprToColumnName() const {
264
0
    LOG(FATAL) << "Mangling name for subscript operator is not yet supported";
265
0
    return "expr";
266
0
  }
267
268
 private:
269
  yb::QLOperator yb_op_;
270
};
271
272
class PartitionKeyOp {
273
 public:
274
  PartitionKeyOp(yb::QLOperator yb_op, PTExprPtr expr)
275
48
      : yb_op_(yb_op), expr_(expr) {}
276
277
42
  QLOperator yb_op() const {
278
42
    return yb_op_;
279
42
  }
280
281
46
  PTExprPtr expr() const {
282
46
    return expr_;
283
46
  }
284
285
 private:
286
  QLOperator yb_op_;
287
  PTExprPtr expr_;
288
};
289
290
const char* QLOperatorAsString(QLOperator ql_op);
291
292
}  // namespace ql
293
}  // namespace yb
294
295
#endif  // YB_YQL_CQL_QL_PTREE_COLUMN_ARG_H_