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_alter_table.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 ALTER TABLE statement.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_PTREE_PT_ALTER_TABLE_H_
19
#define YB_YQL_CQL_QL_PTREE_PT_ALTER_TABLE_H_
20
21
#include "yb/yql/cql/ql/ptree/list_node.h"
22
#include "yb/yql/cql/ql/ptree/pt_name.h"
23
#include "yb/yql/cql/ql/ptree/pt_table_property.h"
24
#include "yb/yql/cql/ql/ptree/pt_type.h"
25
#include "yb/yql/cql/ql/ptree/tree_node.h"
26
27
namespace yb {
28
namespace ql {
29
30
//--------------------------------------------------------------------------------------------------
31
32
typedef enum AlterColumnType : int {
33
  ALTER_ADD,
34
  ALTER_DROP,
35
  ALTER_RENAME,
36
  ALTER_TYPE
37
} ModColumnType;
38
39
const string supported_properties[] = {"ttl"};
40
41
//--------------------------------------------------------------------------------------------------
42
// Drop/rename/alter type column operation details
43
44
class PTAlterColumnDefinition : public TreeNode {
45
 public:
46
  //------------------------------------------------------------------------------------------------
47
  // Public types.
48
  typedef MCSharedPtr<PTAlterColumnDefinition> SharedPtr;
49
  typedef MCSharedPtr<const PTAlterColumnDefinition> SharedPtrConst;
50
51
  //------------------------------------------------------------------------------------------------
52
  // Constructor and destructor.
53
  PTAlterColumnDefinition(MemoryContext *memctx,
54
              YBLocationPtr loc,
55
              PTQualifiedName::SharedPtr name,
56
              const MCSharedPtr<MCString>& new_name,
57
              const PTBaseType::SharedPtr& datatype,
58
              AlterColumnType type);
59
  virtual ~PTAlterColumnDefinition();
60
61
  // Node type.
62
0
  virtual TreeNodeOpcode opcode() const override {
63
0
    return TreeNodeOpcode::kPTAlterColumnDefinition;
64
0
  }
65
66
  template<typename... TypeArgs>
67
  inline static PTAlterColumnDefinition::SharedPtr MakeShared(MemoryContext *memctx,
68
69
                                                  TypeArgs&& ... args) {
69
69
    return MCMakeShared<PTAlterColumnDefinition>(memctx, std::forward<TypeArgs>(args)...);
70
69
  }
_ZN2yb2ql23PTAlterColumnDefinition10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEEDnRNS4_INS3_12basic_stringIcNS3_11char_traitsIcEENS_8internal18ArenaAllocatorBaseIcNSA_11ArenaTraitsEEEEEEERNS4_INS0_10PTBaseTypeEEENS0_15AlterColumnTypeEEEENS4_IS1_EEPNSA_9ArenaBaseISC_EEDpOT_
Line
Count
Source
68
42
                                                  TypeArgs&& ... args) {
69
42
    return MCMakeShared<PTAlterColumnDefinition>(memctx, std::forward<TypeArgs>(args)...);
70
42
  }
_ZN2yb2ql23PTAlterColumnDefinition10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEEDnDnNS0_15AlterColumnTypeEEEENS4_IS1_EEPNS_8internal9ArenaBaseINSC_11ArenaTraitsEEEDpOT_
Line
Count
Source
68
13
                                                  TypeArgs&& ... args) {
69
13
    return MCMakeShared<PTAlterColumnDefinition>(memctx, std::forward<TypeArgs>(args)...);
70
13
  }
_ZN2yb2ql23PTAlterColumnDefinition10MakeSharedIJNSt3__110shared_ptrINS0_8LocationEEERNS4_INS0_15PTQualifiedNameEEERNS4_INS3_12basic_stringIcNS3_11char_traitsIcEENS_8internal18ArenaAllocatorBaseIcNSD_11ArenaTraitsEEEEEEEDnNS0_15AlterColumnTypeEEEENS4_IS1_EEPNSD_9ArenaBaseISF_EEDpOT_
Line
Count
Source
68
14
                                                  TypeArgs&& ... args) {
69
14
    return MCMakeShared<PTAlterColumnDefinition>(memctx, std::forward<TypeArgs>(args)...);
70
14
  }
71
72
  // Node semantics analysis.
73
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
74
75
  // Qualified name of column that's already present.
76
117
  PTQualifiedName::SharedPtr old_name() const {
77
117
    return name_;
78
117
  }
79
80
82
  AlterColumnType mod_type() const {
81
82
    return type_;
82
82
  }
83
84
0
  const PTBaseType::SharedPtr& datatype() const {
85
0
    return datatype_;
86
0
  }
87
88
35
  std::shared_ptr<QLType> ql_type() const {
89
35
    return datatype_->ql_type();
90
35
  }
91
92
  // New string name of column to be created or altered.
93
168
  const MCSharedPtr<MCString> new_name() const {
94
168
    return new_name_;
95
168
  }
96
97
 private:
98
  PTQualifiedName::SharedPtr name_;
99
  const MCSharedPtr<MCString> new_name_;
100
  const PTBaseType::SharedPtr datatype_;
101
  AlterColumnType type_;
102
};
103
104
//--------------------------------------------------------------------------------------------------
105
// ALTER TABLE
106
107
class PTAlterTable : public TreeNode {
108
 public:
109
  // Public types.
110
  typedef MCSharedPtr<PTAlterTable> SharedPtr;
111
  typedef MCSharedPtr<const PTAlterTable> SharedPtrConst;
112
113
  // Node type.
114
  PTAlterTable(MemoryContext *memctx,
115
               YBLocationPtr loc,
116
               PTQualifiedName::SharedPtr name,
117
               const PTListNode::SharedPtr& commands);
118
  virtual ~PTAlterTable();
119
120
291
  virtual TreeNodeOpcode opcode() const override {
121
291
    return TreeNodeOpcode::kPTAlterTable;
122
291
  }
123
124
  // Support for shared_ptr.
125
  template<typename... TypeArgs>
126
69
  inline static PTAlterTable::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&& ... args) {
127
69
    return MCMakeShared<PTAlterTable>(memctx, std::forward<TypeArgs>(args)...);
128
69
  }
129
130
0
  const PTQualifiedName::SharedPtr& table_name() const {
131
0
    return name_;
132
0
  }
133
134
  // Table name.
135
99
  client::YBTableName yb_table_name() const {
136
99
    return name_->ToTableName();
137
99
  }
138
139
  // Column modifications to be made.
140
55
  const MCList<PTAlterColumnDefinition* >& mod_columns() const {
141
55
    return mod_columns_;
142
55
  }
143
144
  // Table property modifications to be made.
145
55
  const MCList<PTTableProperty* >& mod_props() const {
146
55
    return mod_props_;
147
55
  }
148
149
0
  const std::shared_ptr<client::YBTable>& table() const {
150
0
    return table_;
151
0
  }
152
153
  // Node semantics analysis.
154
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
155
156
  void PrintSemanticAnalysisResult(SemContext *sem_context);
157
158
  CHECKED_STATUS AppendModColumn(SemContext *sem_context, PTAlterColumnDefinition *column);
159
160
  CHECKED_STATUS AppendAlterProperty(SemContext *sem_context, PTTableProperty *prop);
161
162
  CHECKED_STATUS ToTableProperties(TableProperties *table_properties) const;
163
164
 private:
165
  PTQualifiedName::SharedPtr name_;
166
  PTListNode::SharedPtr commands_;
167
168
  std::shared_ptr<client::YBTable> table_;
169
  MCVector<ColumnDesc> table_columns_;
170
  MCList<PTAlterColumnDefinition *> mod_columns_;
171
  MCList<PTTableProperty *> mod_props_;
172
};
173
174
}  // namespace ql
175
}  // namespace yb
176
177
#endif  // YB_YQL_CQL_QL_PTREE_PT_ALTER_TABLE_H_