YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/yql_virtual_table.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_MASTER_YQL_VIRTUAL_TABLE_H
15
#define YB_MASTER_YQL_VIRTUAL_TABLE_H
16
17
#include "yb/common/ql_rowblock.h"
18
19
#include "yb/docdb/ql_storage_interface.h"
20
21
#include "yb/master/ts_descriptor.h"
22
#include "yb/master/util/yql_vtable_helpers.h"
23
24
#include "yb/util/metrics_fwd.h"
25
26
namespace yb {
27
namespace master {
28
29
// A YQL virtual table which is based on in memory data.
30
class YQLVirtualTable : public docdb::YQLStorageIf {
31
 public:
32
  explicit YQLVirtualTable(const TableName& table_name,
33
                           const NamespaceName &namespace_name,
34
                           const Master* const master,
35
                           const Schema& schema);
36
  ~YQLVirtualTable();
37
38
  // Access methods.
39
278k
  const Schema& schema() const { return *schema_; }
40
41
0
  const TableName& table_name() const { return table_name_; }
42
43
  //------------------------------------------------------------------------------------------------
44
  // CQL Support.
45
  //------------------------------------------------------------------------------------------------
46
47
  // Retrieves all the data for the yql virtual table in form of a QLRowBlock. This data is then
48
  // used by the iterator.
49
  virtual Result<std::shared_ptr<QLRowBlock>> RetrieveData(
50
      const QLReadRequestPB& request) const = 0;
51
52
  CHECKED_STATUS GetIterator(const QLReadRequestPB& request,
53
                             const Schema& projection,
54
                             const Schema& schema,
55
                             const TransactionOperationContext& txn_op_context,
56
                             CoarseTimePoint deadline,
57
                             const ReadHybridTime& read_time,
58
                             const QLScanSpec& spec,
59
                             std::unique_ptr<docdb::YQLRowwiseIteratorIf>* iter) const override;
60
61
  CHECKED_STATUS BuildYQLScanSpec(
62
      const QLReadRequestPB& request,
63
      const ReadHybridTime& read_time,
64
      const Schema& schema,
65
      bool include_static_columns,
66
      const Schema& static_projection,
67
      std::unique_ptr<QLScanSpec>* spec,
68
      std::unique_ptr<QLScanSpec>* static_row_spec) const override;
69
70
  //------------------------------------------------------------------------------------------------
71
  // PGSQL Support.
72
  //------------------------------------------------------------------------------------------------
73
74
  CHECKED_STATUS CreateIterator(const Schema& projection,
75
                                const Schema& schema,
76
                                const TransactionOperationContext& txn_op_context,
77
                                CoarseTimePoint deadline,
78
                                const ReadHybridTime& read_time,
79
0
                                std::unique_ptr<docdb::YQLRowwiseIteratorIf>* iter) const override {
80
0
    LOG(FATAL) << "Postgresql virtual tables are not yet implemented";
81
0
    return Status::OK();
82
0
  }
83
84
  CHECKED_STATUS InitIterator(docdb::YQLRowwiseIteratorIf* iter,
85
                              const PgsqlReadRequestPB& request,
86
                              const Schema& schema,
87
0
                              const QLValuePB& ybctid) const override {
88
0
    LOG(FATAL) << "Postgresql virtual tables are not yet implemented";
89
0
    return Status::OK();
90
0
  }
91
92
  CHECKED_STATUS GetIterator(const PgsqlReadRequestPB& request,
93
                             const Schema& projection,
94
                             const Schema& schema,
95
                             const TransactionOperationContext& txn_op_context,
96
                             CoarseTimePoint deadline,
97
                             const ReadHybridTime& read_time,
98
                             const docdb::DocKey& start_doc_key,
99
0
                             docdb::YQLRowwiseIteratorIf::UniPtr* iter) const override {
100
0
    LOG(FATAL) << "Postgresql virtual tables are not yet implemented";
101
0
    return Status::OK();
102
0
  }
103
104
  CHECKED_STATUS GetIterator(uint64 stmt_id,
105
                             const Schema& projection,
106
                             const Schema& schema,
107
                             const TransactionOperationContext& txn_op_context,
108
                             CoarseTimePoint deadline,
109
                             const ReadHybridTime& read_time,
110
                             const QLValuePB& ybctid,
111
0
                             docdb::YQLRowwiseIteratorIf::UniPtr* iter) const override {
112
0
    LOG(FATAL) << "Postgresql virtual tables are not yet implemented";
113
0
    return Status::OK();
114
0
  }
115
116
 protected:
117
  // Finds the given column name in the schema and updates the specified column in the given row
118
  // with the provided value.
119
  template<class T>
120
18.3M
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
18.3M
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
18.3M
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
18.3M
    return Status::OK();
124
18.3M
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueINSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEEENS_6StatusERKS9_RKT_PNS_5QLRowE
Line
Count
Source
120
12.9M
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
12.9M
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
12.9M
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
12.9M
    return Status::OK();
124
12.9M
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIbEENS_6StatusERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
90.4k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
90.4k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
90.4k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
90.4k
    return Status::OK();
124
90.4k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueINS_9QLValuePBEEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
814k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
814k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
814k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
814k
    return Status::OK();
124
814k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA14_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
316k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
316k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
316k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
316k
    return Status::OK();
124
316k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIiEENS_6StatusERKNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
2.34M
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
2.34M
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
2.34M
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
2.34M
    return Status::OK();
124
2.34M
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA11_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
258k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
258k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
258k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
258k
    return Status::OK();
124
258k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueINS_4UuidEEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
649k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
649k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
649k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
649k
    return Status::OK();
124
649k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueINS_11InetAddressEEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
495k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
495k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
495k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
495k
    return Status::OK();
124
495k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA6_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
139k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
139k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
139k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
139k
    return Status::OK();
124
139k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA10_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
70.0k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
70.0k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
70.0k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
70.0k
    return Status::OK();
124
70.0k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA2_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
70.2k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
70.2k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
70.2k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
70.2k
    return Status::OK();
124
70.2k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA44_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
70.1k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
70.1k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
70.1k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
70.1k
    return Status::OK();
124
70.1k
  }
_ZNK2yb6master15YQLVirtualTable14SetColumnValueIA7_cEENS_6StatusERKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEERKT_PNS_5QLRowE
Line
Count
Source
120
70.1k
  CHECKED_STATUS SetColumnValue(const std::string& col_name, const T& value, QLRow* row) const {
121
70.1k
    auto p = VERIFY_RESULT(ColumnIndexAndType(col_name));
122
70.1k
    row->SetColumn(p.first, util::GetValue(value, p.second));
123
70.1k
    return Status::OK();
124
70.1k
  }
125
126
  Result<std::pair<int, DataType>> ColumnIndexAndType(const std::string& col_name) const;
127
128
  // Get all live tserver descriptors sorted by their UUIDs. For cases like system.local and
129
  // system.peers tables to return the token map of each tserver node so that each maps to a
130
  // consistent token.
131
  void GetSortedLiveDescriptors(std::vector<std::shared_ptr<TSDescriptor>>* descs) const;
132
133
  CatalogManagerIf& catalog_manager() const;
134
135
  const Master* const master_;
136
  TableName table_name_;
137
  std::unique_ptr<Schema> schema_;
138
  scoped_refptr<Histogram> histogram_;
139
};
140
141
extern const std::string kSystemTablesReleaseVersion;
142
extern const std::string kSystemTablesReleaseVersionColumn;
143
144
}  // namespace master
145
}  // namespace yb
146
#endif // YB_MASTER_YQL_VIRTUAL_TABLE_H