/Users/deen/code/yugabyte-db/src/yb/master/yql_keyspaces_vtable.cc
Line | Count | Source |
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 | | #include "yb/master/yql_keyspaces_vtable.h" |
15 | | |
16 | | #include <stdint.h> |
17 | | |
18 | | #include <glog/logging.h> |
19 | | |
20 | | #include "yb/common/ql_type.h" |
21 | | #include "yb/common/schema.h" |
22 | | |
23 | | #include "yb/master/catalog_entity_info.h" |
24 | | #include "yb/master/catalog_manager_if.h" |
25 | | |
26 | | #include "yb/util/status_log.h" |
27 | | #include "yb/util/uuid.h" |
28 | | |
29 | | namespace yb { |
30 | | namespace master { |
31 | | |
32 | | YQLKeyspacesVTable::YQLKeyspacesVTable(const TableName& table_name, |
33 | | const NamespaceName& namespace_name, |
34 | | Master * const master) |
35 | 2.00k | : YQLVirtualTable(table_name, namespace_name, master, CreateSchema()) { |
36 | 2.00k | } |
37 | | |
38 | | Result<std::shared_ptr<QLRowBlock>> YQLKeyspacesVTable::RetrieveData( |
39 | 13.6k | const QLReadRequestPB& request) const { |
40 | 13.6k | auto vtable = std::make_shared<QLRowBlock>(schema()); |
41 | 13.6k | std::vector<scoped_refptr<NamespaceInfo> > namespaces; |
42 | 13.6k | catalog_manager().GetAllNamespaces(&namespaces, true); |
43 | 56.0k | for (scoped_refptr<NamespaceInfo> ns : namespaces) { |
44 | | // Skip non-YQL namespace. |
45 | 56.0k | if (!IsYcqlNamespace(*ns)) { |
46 | 47 | continue; |
47 | 47 | } |
48 | | |
49 | 56.0k | QLRow& row = vtable->Extend(); |
50 | 56.0k | RETURN_NOT_OK(SetColumnValue(kKeyspaceName, ns->name(), &row)); |
51 | 56.0k | RETURN_NOT_OK(SetColumnValue(kDurableWrites, true, &row)); |
52 | | |
53 | 56.0k | auto repl_factor = VERIFY_RESULT(catalog_manager().GetReplicationFactor(ns->name())); |
54 | 56.0k | RETURN_NOT_OK(SetColumnValue(kReplication, util::GetReplicationValue(repl_factor), &row)); |
55 | 56.0k | } |
56 | | |
57 | 13.6k | return vtable; |
58 | 13.6k | } |
59 | | |
60 | 2.00k | Schema YQLKeyspacesVTable::CreateSchema() const { |
61 | 2.00k | SchemaBuilder builder; |
62 | 2.00k | CHECK_OK(builder.AddHashKeyColumn(kKeyspaceName, QLType::Create(DataType::STRING))); |
63 | 2.00k | CHECK_OK(builder.AddColumn(kDurableWrites, QLType::Create(DataType::BOOL))); |
64 | | // TODO: replication needs to be a frozen map. |
65 | 2.00k | CHECK_OK(builder.AddColumn(kReplication, |
66 | 2.00k | QLType::CreateTypeMap(DataType::STRING, DataType::STRING))); |
67 | 2.00k | return builder.Build(); |
68 | 2.00k | } |
69 | | |
70 | | } // namespace master |
71 | | } // namespace yb |