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/pt_update.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
// Tree node definitions for UPDATE statement.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_PTREE_PT_UPDATE_H_
19
#define YB_YQL_CQL_QL_PTREE_PT_UPDATE_H_
20
21
#include "yb/yql/cql/ql/ptree/list_node.h"
22
#include "yb/yql/cql/ql/ptree/tree_node.h"
23
#include "yb/yql/cql/ql/ptree/pt_dml.h"
24
#include "yb/yql/cql/ql/ptree/pt_select.h"
25
#include "yb/yql/cql/ql/ptree/pt_dml_write_property.h"
26
27
namespace yb {
28
namespace ql {
29
30
//--------------------------------------------------------------------------------------------------
31
32
class PTAssign : public TreeNode {
33
 public:
34
  //------------------------------------------------------------------------------------------------
35
  // Public types.
36
  typedef MCSharedPtr<PTAssign> SharedPtr;
37
  typedef MCSharedPtr<const PTAssign> SharedPtrConst;
38
39
  //------------------------------------------------------------------------------------------------
40
  // Constructor and destructor.
41
  PTAssign(MemoryContext *memctx,
42
           YBLocationPtr loc,
43
           const PTQualifiedName::SharedPtr& lhs_,
44
           const PTExprPtr& rhs_,
45
           const PTExprListNode::SharedPtr& subscript_args = nullptr,
46
           const PTExprListNode::SharedPtr& json_ops = nullptr);
47
  virtual ~PTAssign();
48
49
  template<typename... TypeArgs>
50
  inline static PTAssign::SharedPtr MakeShared(MemoryContext *memctx,
51
7.03k
                                               TypeArgs&&... args) {
52
7.03k
    return MCMakeShared<PTAssign>(memctx, std::forward<TypeArgs>(args)...);
53
7.03k
  }
_ZN2yb2ql8PTAssign10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEERNS4_INS0_6PTExprEEEEEENS4_IS1_EEPNS_8internal9ArenaBaseINSE_11ArenaTraitsEEEDpOT_
Line
Count
Source
51
6.75k
                                               TypeArgs&&... args) {
52
6.75k
    return MCMakeShared<PTAssign>(memctx, std::forward<TypeArgs>(args)...);
53
6.75k
  }
_ZN2yb2ql8PTAssign10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEERNS4_INS0_6PTExprEEERNS4_INS0_12TreeListNodeISA_EEEEEEENS4_IS1_EEPNS_8internal9ArenaBaseINSI_11ArenaTraitsEEEDpOT_
Line
Count
Source
51
91
                                               TypeArgs&&... args) {
52
91
    return MCMakeShared<PTAssign>(memctx, std::forward<TypeArgs>(args)...);
53
91
  }
_ZN2yb2ql8PTAssign10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEERNS4_INS0_6PTExprEEEDnRNS4_INS0_12TreeListNodeISA_EEEEEEENS4_IS1_EEPNS_8internal9ArenaBaseINSI_11ArenaTraitsEEEDpOT_
Line
Count
Source
51
191
                                               TypeArgs&&... args) {
52
191
    return MCMakeShared<PTAssign>(memctx, std::forward<TypeArgs>(args)...);
53
191
  }
54
55
  // Node semantics analysis.
56
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
57
  void PrintSemanticAnalysisResult(SemContext *sem_context);
58
59
  // Node type.
60
0
  virtual TreeNodeOpcode opcode() const override {
61
0
    return TreeNodeOpcode::kPTAssign;
62
0
  }
63
64
13.6k
  const ColumnDesc *col_desc() const {
65
13.6k
    return col_desc_;
66
13.6k
  }
67
68
54
  const PTExprListNode::SharedPtr subscript_args() const {
69
54
    return subscript_args_;
70
54
  }
71
72
186
  const PTExprListNode::SharedPtr json_ops() const {
73
186
    return json_ops_;
74
186
  }
75
76
13.8k
  bool has_subscripted_column() const {
77
13.8k
    return subscript_args_ != nullptr && subscript_args_->size() > 0;
78
13.8k
  }
79
80
13.7k
  bool has_json_ops() const {
81
13.7k
    return json_ops_ != nullptr && json_ops_->size() > 0;
82
13.7k
  }
83
84
6.83k
  PTExprPtr rhs() {
85
6.83k
    return rhs_;
86
6.83k
  }
87
88
6.83k
  bool require_column_read() const {
89
6.83k
    return require_column_read_;
90
6.83k
  }
91
92
 private:
93
  PTQualifiedName::SharedPtr lhs_;
94
95
  PTExprPtr rhs_;
96
97
  // for assigning specific indexes for collection columns: e.g.: lhs[key1][key2] = value
98
  PTExprListNode::SharedPtr subscript_args_;
99
100
  // Denotes json operators applied to a column e.g.: c1->'a'->'b'->'c'.
101
  PTExprListNode::SharedPtr json_ops_;
102
103
  // Semantic phase will fill in this value.
104
  const ColumnDesc *col_desc_;
105
106
  // Indicate if a column read is required to execute this assign statement.
107
  bool require_column_read_ = false;
108
};
109
110
using PTAssignListNode = TreeListNode<PTAssign>;
111
112
//--------------------------------------------------------------------------------------------------
113
114
class PTUpdateStmt : public PTDmlStmt {
115
 public:
116
  //------------------------------------------------------------------------------------------------
117
  // Public types.
118
  typedef MCSharedPtr<PTUpdateStmt> SharedPtr;
119
  typedef MCSharedPtr<const PTUpdateStmt> SharedPtrConst;
120
121
  //------------------------------------------------------------------------------------------------
122
  // Constructor and destructor.
123
  PTUpdateStmt(MemoryContext *memctx,
124
               YBLocationPtr loc,
125
               PTTableRef::SharedPtr relation,
126
               PTAssignListNode::SharedPtr set_clause,
127
               PTExprPtr where_clause,
128
               PTExprPtr if_clause = nullptr,
129
               bool else_error = false,
130
               PTDmlUsingClausePtr using_clause = nullptr,
131
               const bool return_status = false,
132
               PTDmlWritePropertyListNode::SharedPtr update_properties = nullptr);
133
  virtual ~PTUpdateStmt();
134
135
  template<typename... TypeArgs>
136
  inline static PTUpdateStmt::SharedPtr MakeShared(MemoryContext *memctx,
137
3.33k
                                                   TypeArgs&&... args) {
138
3.33k
    return MCMakeShared<PTUpdateStmt>(memctx, std::forward<TypeArgs>(args)...);
139
3.33k
  }
_ZN2yb2ql12PTUpdateStmt10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_10PTTableRefEEERNS4_INS0_12TreeListNodeINS0_8PTAssignEEEEERNS4_INS0_6PTExprEEEDnbRNS4_INS0_16PTDmlUsingClauseEEERbRNS4_INS0_26PTDmlWritePropertyListNodeEEEEEENS4_IS1_EEPNS_8internal9ArenaBaseINSQ_11ArenaTraitsEEEDpOT_
Line
Count
Source
137
3.25k
                                                   TypeArgs&&... args) {
138
3.25k
    return MCMakeShared<PTUpdateStmt>(memctx, std::forward<TypeArgs>(args)...);
139
3.25k
  }
_ZN2yb2ql12PTUpdateStmt10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_10PTTableRefEEERNS4_INS0_12TreeListNodeINS0_8PTAssignEEEEERNS4_INS0_6PTExprEEESH_RbRNS4_INS0_16PTDmlUsingClauseEEESI_RNS4_INS0_26PTDmlWritePropertyListNodeEEEEEENS4_IS1_EEPNS_8internal9ArenaBaseINSQ_11ArenaTraitsEEEDpOT_
Line
Count
Source
137
80
                                                   TypeArgs&&... args) {
138
80
    return MCMakeShared<PTUpdateStmt>(memctx, std::forward<TypeArgs>(args)...);
139
80
  }
140
141
  // Node semantics analysis.
142
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
143
  void PrintSemanticAnalysisResult(SemContext *sem_context);
144
  CHECKED_STATUS AnalyzeSetExpr(PTAssign *assign_expr, SemContext *sem_context);
145
  ExplainPlanPB AnalysisResultToPB() override;
146
147
  // Table name.
148
9.72k
  client::YBTableName table_name() const override {
149
9.72k
    return relation_->table_name();
150
9.72k
  }
151
152
  // Returns location of table name.
153
3
  const YBLocation& table_loc() const override {
154
3
    return relation_->loc();
155
3
  }
156
157
  // Node type.
158
58.0k
  virtual TreeNodeOpcode opcode() const override {
159
58.0k
    return TreeNodeOpcode::kPTUpdateStmt;
160
58.0k
  }
161
162
0
  bool require_column_read() const {
163
0
    return require_column_read_;
164
0
  }
165
166
0
  const PTAssignListNode::SharedPtr& set_clause() const {
167
0
    return set_clause_;
168
0
  }
169
170
318
  const PTDmlWritePropertyListNode::SharedPtr& update_properties() const {
171
318
    return update_properties_;
172
318
  }
173
174
12.0k
  bool IsWriteOp() const override {
175
12.0k
    return true;
176
12.0k
  }
177
178
 private:
179
  // --- The parser will decorate this node with the following information --
180
181
  PTTableRef::SharedPtr relation_;
182
  PTAssignListNode::SharedPtr set_clause_;
183
184
  // -- The semantic analyzer will decorate this node with the following information --
185
186
  // Indicate if a column read is required to execute this update statement.
187
  bool require_column_read_ = false;
188
189
  // Properties added via the WITH clause in UPDATE statement.
190
  PTDmlWritePropertyListNode::SharedPtr update_properties_ = nullptr;
191
};
192
193
}  // namespace ql
194
}  // namespace yb
195
196
#endif  // YB_YQL_CQL_QL_PTREE_PT_UPDATE_H_