YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_table_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_TABLE_PROPERTY_H_
15
#define YB_YQL_CQL_QL_PTREE_PT_TABLE_PROPERTY_H_
16
17
#include "yb/gutil/strings/substitute.h"
18
#include "yb/yql/cql/ql/ptree/list_node.h"
19
#include "yb/yql/cql/ql/ptree/pt_name.h"
20
#include "yb/yql/cql/ql/ptree/pt_property.h"
21
#include "yb/yql/cql/ql/ptree/pt_select.h"
22
#include "yb/yql/cql/ql/ptree/tree_node.h"
23
24
namespace yb {
25
namespace ql {
26
27
enum class PropertyType : int {
28
  kTableProperty = 0,
29
  kClusteringOrder,
30
  kTablePropertyMap,
31
  kCoPartitionTable,
32
};
33
34
class PTTableProperty : public PTProperty {
35
 public:
36
  enum class KVProperty : int {
37
    kBloomFilterFpChance,
38
    kCaching,
39
    kComment,
40
    kCompaction,
41
    kCompression,
42
    kCrcCheckChance,
43
    kDclocalReadRepairChance,
44
    kDefaultTimeToLive,
45
    kGcGraceSeconds,
46
    kIndexInterval,
47
    kMemtableFlushPeriodInMs,
48
    kMinIndexInterval,
49
    kMaxIndexInterval,
50
    kReadRepairChance,
51
    kSpeculativeRetry,
52
    kTransactions,
53
    kNumTablets
54
  };
55
56
  //------------------------------------------------------------------------------------------------
57
  // Public types.
58
  typedef MCSharedPtr<PTTableProperty> SharedPtr;
59
  typedef MCSharedPtr<const PTTableProperty> SharedPtrConst;
60
61
  //------------------------------------------------------------------------------------------------
62
  // Constructor and destructor.
63
  // Constructor for PropertyType::kTableProperty.
64
  PTTableProperty(MemoryContext *memctx,
65
                  YBLocationPtr loc,
66
                  const MCSharedPtr<MCString>& lhs_,
67
                  const PTExprPtr& rhs_);
68
69
  // Constructor for PropertyType::kClusteringOrder.
70
  PTTableProperty(MemoryContext *memctx,
71
                  YBLocationPtr loc,
72
                  const PTExprPtr& expr,
73
                  const PTOrderBy::Direction direction);
74
75
  // Constructor for PropertyType::kCoPartitionTable
76
  PTTableProperty(MemoryContext *memctx,
77
                  YBLocationPtr loc,
78
                  const PTQualifiedName::SharedPtr tname);
79
80
  PTTableProperty(MemoryContext *memctx,
81
                  YBLocationPtr loc);
82
83
  virtual ~PTTableProperty();
84
85
  template<typename... TypeArgs>
86
  inline static PTTableProperty::SharedPtr MakeShared(MemoryContext *memctx,
87
1.86k
                                               TypeArgs&&... args) {
88
1.86k
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
1.86k
  }
std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)16, (yb::DataType)12, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)16, (yb::DataType)12, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&)
Line
Count
Source
87
469
                                               TypeArgs&&... args) {
88
469
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
469
  }
std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)15, (yb::DataType)11, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)15, (yb::DataType)11, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&)
Line
Count
Source
87
135
                                               TypeArgs&&... args) {
88
135
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
135
  }
std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)8, (yb::DataType)6, bool, yb::ql::PTLiteral<bool> > >&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)8, (yb::DataType)6, bool, yb::ql::PTLiteral<bool> > >&)
Line
Count
Source
87
454
                                               TypeArgs&&... args) {
88
454
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
454
  }
std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)7, (yb::DataType)5, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)7, (yb::DataType)5, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&)
Line
Count
Source
87
463
                                               TypeArgs&&... args) {
88
463
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
463
  }
Unexecuted instantiation: std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<yb::ql::PTQualifiedName>&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<yb::ql::PTQualifiedName>&)
std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<yb::ql::PTExpr>&, yb::ql::PTOrderBy::Direction>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<yb::ql::PTExpr>&, yb::ql::PTOrderBy::Direction&&)
Line
Count
Source
87
331
                                               TypeArgs&&... args) {
88
331
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
331
  }
std::__1::shared_ptr<yb::ql::PTTableProperty> yb::ql::PTTableProperty::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExpr>&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >&, std::__1::shared_ptr<yb::ql::PTExpr>&)
Line
Count
Source
87
8
                                               TypeArgs&&... args) {
88
8
    return MCMakeShared<PTTableProperty>(memctx, std::forward<TypeArgs>(args)...);
89
8
  }
90
91
  // Node semantics analysis.
92
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
93
  void PrintSemanticAnalysisResult(SemContext *sem_context);
94
95
  virtual CHECKED_STATUS SetTableProperty(yb::TableProperties *table_property) const;
96
97
1.37k
  PropertyType property_type() const {
98
1.37k
    return property_type_;
99
1.37k
  }
100
101
  string name() const;
102
103
605
  PTOrderBy::Direction direction() const {
104
605
    DCHECK_EQ(property_type_, PropertyType::kClusteringOrder);
105
605
    return direction_;
106
605
  }
107
108
0
  PTQualifiedName table_name() const {
109
0
    DCHECK_EQ(property_type_, PropertyType::kCoPartitionTable);
110
0
    return *copartition_table_name_;
111
0
  }
112
113
  TableId copartition_table_id() const;
114
115
 protected:
116
15
  bool IsValidProperty(const string& property_name) {
117
15
    return kPropertyDataTypes.find(property_name) != kPropertyDataTypes.end();
118
15
  }
119
120
  PTExprPtr order_expr_;
121
  // We just need some default values. These are overridden in various constructors.
122
  PTOrderBy::Direction direction_ = PTOrderBy::Direction::kASC;
123
  PropertyType property_type_ = PropertyType::kTableProperty;
124
  PTQualifiedName::SharedPtr copartition_table_name_;
125
  std::shared_ptr<client::YBTable> copartition_table_;
126
127
 private:
128
  CHECKED_STATUS AnalyzeSpeculativeRetry(const string &val);
129
130
  static const std::map<std::string, PTTableProperty::KVProperty> kPropertyDataTypes;
131
};
132
133
std::ostream& operator<<(ostream& os, const PropertyType& property_type);
134
135
class PTTablePropertyListNode : public TreeListNode<PTTableProperty> {
136
 public:
137
  //------------------------------------------------------------------------------------------------
138
  // Public types.
139
  typedef MCSharedPtr<PTTablePropertyListNode> SharedPtr;
140
  typedef MCSharedPtr<const PTTablePropertyListNode> SharedPtrConst;
141
142
  explicit PTTablePropertyListNode(MemoryContext *memory_context,
143
                                   YBLocationPtr loc,
144
                                   const MCSharedPtr<PTTableProperty>& tnode = nullptr)
145
1.38k
      : TreeListNode<PTTableProperty>(memory_context, loc, tnode) {
146
1.38k
  }
147
148
1.22k
  virtual ~PTTablePropertyListNode() {
149
1.22k
  }
150
151
  // Append a PTTablePropertyList to this list.
152
442
  void AppendList(const MCSharedPtr<PTTablePropertyListNode>& tnode_list) {
153
442
    if (tnode_list == nullptr) {
154
0
      return;
155
0
    }
156
442
    for (const auto& tnode : tnode_list->node_list()) {
157
440
      Append(tnode);
158
440
    }
159
442
  }
160
161
  template<typename... TypeArgs>
162
  inline static PTTablePropertyListNode::SharedPtr MakeShared(MemoryContext *memctx,
163
1.38k
                                                              TypeArgs&&...args) {
164
1.38k
    return MCMakeShared<PTTablePropertyListNode>(memctx, std::forward<TypeArgs>(args)...);
165
1.38k
  }
std::__1::shared_ptr<yb::ql::PTTablePropertyListNode> yb::ql::PTTablePropertyListNode::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<yb::ql::PTTableProperty>&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<yb::ql::PTTableProperty>&)
Line
Count
Source
163
856
                                                              TypeArgs&&...args) {
164
856
    return MCMakeShared<PTTablePropertyListNode>(memctx, std::forward<TypeArgs>(args)...);
165
856
  }
std::__1::shared_ptr<yb::ql::PTTablePropertyListNode> yb::ql::PTTablePropertyListNode::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<yb::ql::PTTablePropertyMap>&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<yb::ql::PTTablePropertyMap>&)
Line
Count
Source
163
526
                                                              TypeArgs&&...args) {
164
526
    return MCMakeShared<PTTablePropertyListNode>(memctx, std::forward<TypeArgs>(args)...);
165
526
  }
std::__1::shared_ptr<yb::ql::PTTablePropertyListNode> yb::ql::PTTablePropertyListNode::MakeShared<std::__1::shared_ptr<yb::ql::Location> >(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&)
Line
Count
Source
163
2
                                                              TypeArgs&&...args) {
164
2
    return MCMakeShared<PTTablePropertyListNode>(memctx, std::forward<TypeArgs>(args)...);
165
2
  }
166
167
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
168
};
169
170
class PTTablePropertyMap : public PTTableProperty {
171
 public:
172
  enum class PropertyMapType : int {
173
    kCaching,
174
    kCompaction,
175
    kCompression,
176
    kTransactions
177
  };
178
  //------------------------------------------------------------------------------------------------
179
  // Public types.
180
  typedef MCSharedPtr<PTTablePropertyMap> SharedPtr;
181
  typedef MCSharedPtr<const PTTablePropertyMap> SharedPtrConst;
182
183
  PTTablePropertyMap(MemoryContext *memctx,
184
                     YBLocationPtr loc);
185
186
  virtual ~PTTablePropertyMap();
187
188
  template<typename... TypeArgs>
189
  inline static PTTablePropertyMap::SharedPtr MakeShared(MemoryContext *memctx,
190
529
                                                         TypeArgs&&... args) {
191
529
    return MCMakeShared<PTTablePropertyMap>(memctx, std::forward<TypeArgs>(args)...);
192
529
  }
193
194
  // Node semantics analysis.
195
  virtual CHECKED_STATUS Analyze(SemContext *sem_context) override;
196
  void PrintSemanticAnalysisResult(SemContext *sem_context);
197
198
  virtual CHECKED_STATUS SetTableProperty(yb::TableProperties *table_property) const override;
199
200
526
  void SetPropertyName(MCSharedPtr<MCString> property_name) {
201
526
    lhs_ = property_name;
202
526
  }
203
204
967
  void AppendMapElement(PTTableProperty::SharedPtr table_property) {
205
967
    DCHECK_EQ(property_type_, PropertyType::kTablePropertyMap);
206
967
    map_elements_->Append(table_property);
207
967
  }
208
209
 private:
210
  Status AnalyzeCaching();
211
  Status AnalyzeCompaction();
212
  Status AnalyzeCompression();
213
  Status AnalyzeTransactions(SemContext *sem_context);
214
215
  static const std::map<std::string, PTTablePropertyMap::PropertyMapType> kPropertyDataTypes;
216
  TreeListNode<PTTableProperty>::SharedPtr map_elements_;
217
};
218
219
struct Compression {
220
  enum class Subproperty : int {
221
    kChunkLengthKb,
222
    kClass,
223
    kCrcCheckChance,
224
    kEnabled,
225
    kSstableCompression
226
  };
227
228
  static const std::map<std::string, Subproperty> kSubpropertyDataTypes;
229
};
230
231
struct Compaction {
232
  enum class Subproperty : int {
233
    kBaseTimeSeconds,
234
    kBucketHigh,
235
    kBucketLow,
236
    kClass,
237
    kCompactionWindowSize,
238
    kCompactionWindowUnit,
239
    kEnabled,
240
    kLogAll,
241
    kMaxSstableAgeDays,
242
    kMaxThreshold,
243
    kMaxWindowSizeSeconds,
244
    kMinSstableSize,
245
    kMinThreshold,
246
    kOnlyPurgeRepairedTombstones,
247
    kSstableSizeInMb,
248
    kTimestampResolution,
249
    kTombstoneCompactionInterval,
250
    kTombstoneThreshold,
251
    kUncheckedTombstoneCompaction
252
  };
253
254
  static const std::map<std::string, Subproperty> kSubpropertyDataTypes;
255
256
  static const std::map<std::string, std::set<Subproperty>> kClassSubproperties;
257
258
  static std::set<std::string> kWindowUnits;
259
  static std::set<std::string> kTimestampResolutionUnits;
260
};
261
262
struct Transactions {
263
  enum class Subproperty : int {
264
    kEnabled,
265
    kConsistencyLevel,
266
  };
267
268
  static constexpr auto kConsistencyLevelUserEnforced = "user_enforced";
269
270
  static const std::map<std::string, Subproperty> kSubpropertyDataTypes;
271
};
272
273
} // namespace ql
274
} // namespace yb
275
276
#endif // YB_YQL_CQL_QL_PTREE_PT_TABLE_PROPERTY_H_