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_insert.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 INSERT statement.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_PTREE_PT_INSERT_H_
19
#define YB_YQL_CQL_QL_PTREE_PT_INSERT_H_
20
21
#include "yb/yql/cql/ql/ptree/list_node.h"
22
#include "yb/yql/cql/ql/ptree/pt_dml.h"
23
#include "yb/yql/cql/ql/ptree/pt_insert_values_clause.h"
24
#include "yb/yql/cql/ql/ptree/pt_name.h"
25
#include "yb/yql/cql/ql/ptree/tree_node.h"
26
27
namespace yb {
28
namespace ql {
29
30
//--------------------------------------------------------------------------------------------------
31
32
class PTInsertStmt : public PTDmlStmt {
33
 public:
34
  //------------------------------------------------------------------------------------------------
35
  // Public types.
36
  typedef MCSharedPtr<PTInsertStmt> SharedPtr;
37
  typedef MCSharedPtr<const PTInsertStmt> SharedPtrConst;
38
39
  //------------------------------------------------------------------------------------------------
40
  // Constructor and destructor.
41
  PTInsertStmt(MemoryContext *memctx,
42
               YBLocationPtr loc,
43
               PTQualifiedName::SharedPtr relation,
44
               PTQualifiedNameListNode::SharedPtr columns,
45
               const PTCollection::SharedPtr& inserting_value,
46
               PTExprPtr if_clause = nullptr,
47
               bool else_error = false,
48
               PTDmlUsingClausePtr using_clause = nullptr,
49
               const bool returns_status = false);
50
  virtual ~PTInsertStmt();
51
52
  template<typename... TypeArgs>
53
  inline static PTInsertStmt::SharedPtr MakeShared(MemoryContext *memctx,
54
47.4k
                                                   TypeArgs&&... args) {
55
47.4k
    return MCMakeShared<PTInsertStmt>(memctx, std::forward<TypeArgs>(args)...);
56
47.4k
  }
_ZN2yb2ql12PTInsertStmt10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEERNS4_INS0_12TreeListNodeIS7_EEEERNS4_INS0_20PTInsertValuesClauseEEEDnbRNS4_INS0_16PTDmlUsingClauseEEERbEEENS4_IS1_EEPNS_8internal9ArenaBaseINSM_11ArenaTraitsEEEDpOT_
Line
Count
Source
54
47.3k
                                                   TypeArgs&&... args) {
55
47.3k
    return MCMakeShared<PTInsertStmt>(memctx, std::forward<TypeArgs>(args)...);
56
47.3k
  }
_ZN2yb2ql12PTInsertStmt10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEERNS4_INS0_12TreeListNodeIS7_EEEERNS4_INS0_20PTInsertValuesClauseEEERNS4_INS0_6PTExprEEERbRNS4_INS0_16PTDmlUsingClauseEEESK_EEENS4_IS1_EEPNS_8internal9ArenaBaseINSP_11ArenaTraitsEEEDpOT_
Line
Count
Source
54
78
                                                   TypeArgs&&... args) {
55
78
    return MCMakeShared<PTInsertStmt>(memctx, std::forward<TypeArgs>(args)...);
56
78
  }
_ZN2yb2ql12PTInsertStmt10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEEDnRNS4_INS0_18PTInsertJsonClauseEEEDnbRNS4_INS0_16PTDmlUsingClauseEEERbEEENS4_IS1_EEPNS_8internal9ArenaBaseINSI_11ArenaTraitsEEEDpOT_
Line
Count
Source
54
86
                                                   TypeArgs&&... args) {
55
86
    return MCMakeShared<PTInsertStmt>(memctx, std::forward<TypeArgs>(args)...);
56
86
  }
57
58
  // Node semantics analysis.
59
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
60
  void PrintSemanticAnalysisResult(SemContext *sem_context);
61
  ExplainPlanPB AnalysisResultToPB() override;
62
63
  // Node type.
64
8.14M
  virtual TreeNodeOpcode opcode() const override {
65
8.14M
    return TreeNodeOpcode::kPTInsertStmt;
66
8.14M
  }
67
68
  // Table name.
69
98.6k
  client::YBTableName table_name() const override {
70
98.6k
    return relation_->ToTableName();
71
98.6k
  }
72
73
  // Returns location of table name.
74
142
  const YBLocation& table_loc() const override {
75
142
    return relation_->loc();
76
142
  }
77
78
2.46M
  const PTCollection::SharedPtr& InsertingValue() const {
79
2.46M
    return inserting_value_;
80
2.46M
  }
81
82
1.37M
  bool IsWriteOp() const override {
83
1.37M
    return true;
84
1.37M
  }
85
86
 private:
87
88
  //
89
  // Analyze helper functions
90
  //
91
92
  CHECKED_STATUS AnalyzeInsertingValue(PTCollection* inserting_value,
93
                                       SemContext* sem_context);
94
95
  CHECKED_STATUS AnanlyzeValuesClause(PTInsertValuesClause* values_clause,
96
                                      SemContext* sem_context);
97
98
  CHECKED_STATUS AnanlyzeJsonClause(PTInsertJsonClause* json_clause,
99
                                    SemContext* sem_context);
100
101
  CHECKED_STATUS ProcessColumn(const MCSharedPtr<MCString>& mc_col_name,
102
                               const ColumnDesc* col_desc,
103
                               const PTExprPtr& value_expr,
104
                               SemContext* sem_context);
105
106
  // Initialize all non-initialized columns according to their configured defaults
107
  CHECKED_STATUS InitRemainingColumns(bool is_json_clause,
108
                                      SemContext* sem_context);
109
110
  // --- The parser will decorate this node with the following information --
111
112
  PTQualifiedName::SharedPtr relation_;
113
  PTQualifiedNameListNode::SharedPtr columns_;
114
  PTCollection::SharedPtr inserting_value_;
115
116
  // -- The semantic analyzer will decorate this node with the following information --
117
118
};
119
120
}  // namespace ql
121
}  // namespace yb
122
123
#endif  // YB_YQL_CQL_QL_PTREE_PT_INSERT_H_