/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_dml_write_property.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_YQL_CQL_QL_PTREE_PT_DML_WRITE_PROPERTY_H_ |
15 | | #define YB_YQL_CQL_QL_PTREE_PT_DML_WRITE_PROPERTY_H_ |
16 | | |
17 | | #include "yb/gutil/strings/substitute.h" |
18 | | |
19 | | #include "yb/yql/cql/ql/ptree/list_node.h" |
20 | | #include "yb/yql/cql/ql/ptree/pt_property.h" |
21 | | #include "yb/yql/cql/ql/ptree/tree_node.h" |
22 | | |
23 | | namespace yb { |
24 | | namespace ql { |
25 | | |
26 | | enum class DmlWritePropertyType : int { |
27 | | kDmlWriteProperty = 0, |
28 | | kDmlWritePropertyMap, |
29 | | }; |
30 | | |
31 | | class PTDmlWriteProperty : public PTProperty { |
32 | | public: |
33 | | enum class KVProperty : int { |
34 | | kOptions |
35 | | }; |
36 | | |
37 | | //------------------------------------------------------------------------------------------------ |
38 | | // Public types. |
39 | | typedef MCSharedPtr<PTDmlWriteProperty> SharedPtr; |
40 | | typedef MCSharedPtr<const PTDmlWriteProperty> SharedPtrConst; |
41 | | |
42 | | //------------------------------------------------------------------------------------------------ |
43 | | // Constructor and destructor. |
44 | | // Constructor for DmlWritePropertyType::kDmlWriteProperty. |
45 | | PTDmlWriteProperty(MemoryContext *memctx, |
46 | | YBLocationPtr loc, |
47 | | const MCSharedPtr<MCString>& lhs_, |
48 | | const PTExprPtr& rhs_); |
49 | | |
50 | | PTDmlWriteProperty(MemoryContext *memctx, |
51 | | YBLocationPtr loc); |
52 | | |
53 | | virtual ~PTDmlWriteProperty(); |
54 | | |
55 | | template<typename... TypeArgs> |
56 | | inline static PTDmlWriteProperty::SharedPtr MakeShared(MemoryContext *memctx, |
57 | 56 | TypeArgs&&... args) { |
58 | 56 | return MCMakeShared<PTDmlWriteProperty>(memctx, std::forward<TypeArgs>(args)...); |
59 | 56 | } |
60 | | |
61 | | // Node semantics analysis. |
62 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override; |
63 | | void PrintSemanticAnalysisResult(SemContext *sem_context); |
64 | | |
65 | 276 | DmlWritePropertyType property_type() const { |
66 | 276 | return property_type_; |
67 | 276 | } |
68 | | |
69 | | protected: |
70 | 0 | bool IsValidProperty(const string& property_name) { |
71 | 0 | return kPropertyDataTypes.find(property_name) != kPropertyDataTypes.end(); |
72 | 0 | } |
73 | | |
74 | | DmlWritePropertyType property_type_ = DmlWritePropertyType::kDmlWriteProperty; |
75 | | |
76 | | private: |
77 | | static const std::map<std::string, PTDmlWriteProperty::KVProperty> kPropertyDataTypes; |
78 | | }; |
79 | | |
80 | | std::ostream& operator<<(ostream& os, const DmlWritePropertyType& property_type); |
81 | | |
82 | | class PTDmlWritePropertyListNode : public TreeListNode<PTDmlWriteProperty> { |
83 | | public: |
84 | | //------------------------------------------------------------------------------------------------ |
85 | | // Public types. |
86 | | typedef MCSharedPtr<PTDmlWritePropertyListNode> SharedPtr; |
87 | | typedef MCSharedPtr<const PTDmlWritePropertyListNode> SharedPtrConst; |
88 | | |
89 | | explicit PTDmlWritePropertyListNode(MemoryContext *memory_context, |
90 | | YBLocationPtr loc, |
91 | | const MCSharedPtr<PTDmlWriteProperty>& tnode = nullptr) |
92 | 56 | : TreeListNode<PTDmlWriteProperty>(memory_context, loc, tnode) { |
93 | 56 | } |
94 | | |
95 | 32 | virtual ~PTDmlWritePropertyListNode() { |
96 | 32 | } |
97 | | |
98 | | // Append a PTDmlWritePropertyListNode to this list. |
99 | 2 | void AppendList(const MCSharedPtr<PTDmlWritePropertyListNode>& tnode_list) { |
100 | 2 | if (tnode_list == nullptr) { |
101 | 0 | return; |
102 | 0 | } |
103 | 2 | for (const auto& tnode : tnode_list->node_list()) { |
104 | 2 | Append(tnode); |
105 | 2 | } |
106 | 2 | } |
107 | | |
108 | | template<typename... TypeArgs> |
109 | | inline static PTDmlWritePropertyListNode::SharedPtr MakeShared(MemoryContext *memctx, |
110 | 56 | TypeArgs&&...args) { |
111 | 56 | return MCMakeShared<PTDmlWritePropertyListNode>(memctx, std::forward<TypeArgs>(args)...); |
112 | 56 | } |
113 | | |
114 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override; |
115 | | |
116 | | bool ignore_null_jsonb_attributes(); |
117 | | }; |
118 | | |
119 | | class PTDmlWritePropertyMap : public PTDmlWriteProperty { |
120 | | public: |
121 | | enum class PropertyMapType : int { |
122 | | kOptions |
123 | | }; |
124 | | //------------------------------------------------------------------------------------------------ |
125 | | // Public types. |
126 | | typedef MCSharedPtr<PTDmlWritePropertyMap> SharedPtr; |
127 | | typedef MCSharedPtr<const PTDmlWritePropertyMap> SharedPtrConst; |
128 | | |
129 | | PTDmlWritePropertyMap(MemoryContext *memctx, |
130 | | YBLocationPtr loc); |
131 | | |
132 | | virtual ~PTDmlWritePropertyMap(); |
133 | | |
134 | | template<typename... TypeArgs> |
135 | | inline static PTDmlWritePropertyMap::SharedPtr MakeShared(MemoryContext *memctx, |
136 | 56 | TypeArgs&&... args) { |
137 | 56 | return MCMakeShared<PTDmlWritePropertyMap>(memctx, std::forward<TypeArgs>(args)...); |
138 | 56 | } |
139 | | |
140 | | // Node semantics analysis. |
141 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override; |
142 | | void PrintSemanticAnalysisResult(SemContext *sem_context); |
143 | | |
144 | 56 | void SetPropertyName(MCSharedPtr<MCString> property_name) { |
145 | 56 | lhs_ = property_name; |
146 | 56 | } |
147 | | |
148 | 56 | void AppendMapElement(PTDmlWriteProperty::SharedPtr DmlWrite_property) { |
149 | 56 | DCHECK_EQ(property_type_, DmlWritePropertyType::kDmlWritePropertyMap); |
150 | 56 | map_elements_->Append(DmlWrite_property); |
151 | 56 | } |
152 | | |
153 | | bool ignore_null_jsonb_attributes(); |
154 | | |
155 | | private: |
156 | | Status AnalyzeOptions(SemContext *sem_context); |
157 | | |
158 | | static const std::map<std::string, PTDmlWritePropertyMap::PropertyMapType> kPropertyDataTypes; |
159 | | TreeListNode<PTDmlWriteProperty>::SharedPtr map_elements_; |
160 | | }; |
161 | | |
162 | | struct Options { |
163 | | enum class Subproperty : int { |
164 | | kIgnoreNullJsonbAttributes |
165 | | }; |
166 | | |
167 | | static const std::map<std::string, Subproperty> kSubpropertyDataTypes; |
168 | | }; |
169 | | |
170 | | } // namespace ql |
171 | | } // namespace yb |
172 | | |
173 | | #endif // YB_YQL_CQL_QL_PTREE_PT_DML_WRITE_PROPERTY_H_ |