16 #include <boost/algorithm/string.hpp>
25 using boost::algorithm::to_upper_copy;
30 const string& upper = to_upper_copy(name);
31 if (upper ==
"DATABASE") {
32 return TCatalogObjectType::DATABASE;
33 }
else if (upper ==
"TABLE") {
34 return TCatalogObjectType::TABLE;
35 }
else if (upper ==
"VIEW") {
36 return TCatalogObjectType::VIEW;
37 }
else if (upper ==
"FUNCTION") {
38 return TCatalogObjectType::FUNCTION;
39 }
else if (upper ==
"CATALOG") {
40 return TCatalogObjectType::CATALOG;
41 }
else if (upper ==
"DATA_SOURCE") {
42 return TCatalogObjectType::DATA_SOURCE;
43 }
else if (upper ==
"HDFS_CACHE_POOL") {
44 return TCatalogObjectType::HDFS_CACHE_POOL;
45 }
else if (upper ==
"ROLE") {
46 return TCatalogObjectType::ROLE;
47 }
else if (upper ==
"PRIVILEGE") {
48 return TCatalogObjectType::PRIVILEGE;
54 TCatalogObject* catalog_object) {
56 size_t pos = key.find(
":");
57 if (pos == string::npos || pos >= key.size() - 1) {
58 stringstream error_msg;
59 error_msg <<
"Invalid topic entry key format: " << key;
60 return Status(error_msg.str());
64 string object_name = key.substr(pos + 1);
69 const string& object_name, TCatalogObject* catalog_object) {
70 switch (object_type) {
71 case TCatalogObjectType::DATABASE:
72 catalog_object->__set_type(object_type);
73 catalog_object->__set_db(TDatabase());
74 catalog_object->db.__set_db_name(object_name);
76 case TCatalogObjectType::TABLE:
77 case TCatalogObjectType::VIEW: {
78 catalog_object->__set_type(object_type);
79 catalog_object->__set_table(TTable());
81 int pos = object_name.find(
".");
82 if (pos == string::npos || pos >= object_name.size() - 1) {
83 stringstream error_msg;
84 error_msg <<
"Invalid table name: " << object_name;
85 return Status(error_msg.str());
87 catalog_object->table.__set_db_name(object_name.substr(0, pos));
88 catalog_object->table.__set_tbl_name(object_name.substr(pos + 1));
91 case TCatalogObjectType::FUNCTION: {
94 catalog_object->__set_type(object_type);
95 catalog_object->__set_fn(TFunction());
96 int dot = object_name.find(
".");
97 int paren = object_name.find(
"(");
98 if (dot == string::npos || dot >= object_name.size() - 1 ||
99 paren == string::npos || paren >= object_name.size() - 1 ||
101 stringstream error_msg;
102 error_msg <<
"Invalid function name: " << object_name;
103 return Status(error_msg.str());
105 catalog_object->fn.name.__set_db_name(object_name.substr(0, dot));
106 catalog_object->fn.name.__set_function_name(
107 object_name.substr(dot + 1, paren - dot - 1));
108 catalog_object->fn.__set_signature(object_name.substr(dot + 1));
111 case TCatalogObjectType::DATA_SOURCE:
112 catalog_object->__set_type(object_type);
113 catalog_object->__set_data_source(TDataSource());
114 catalog_object->data_source.__set_name(object_name);
116 case TCatalogObjectType::HDFS_CACHE_POOL:
117 catalog_object->__set_type(object_type);
118 catalog_object->__set_cache_pool(THdfsCachePool());
119 catalog_object->cache_pool.__set_pool_name(object_name);
121 case TCatalogObjectType::ROLE:
122 catalog_object->__set_type(object_type);
123 catalog_object->__set_role(TRole());
124 catalog_object->role.__set_role_name(object_name);
126 case TCatalogObjectType::PRIVILEGE: {
127 int pos = object_name.find(
".");
128 if (pos == string::npos || pos >= object_name.size() - 1) {
129 stringstream error_msg;
130 error_msg <<
"Invalid privilege name: " << object_name;
131 return Status(error_msg.str());
133 catalog_object->__set_type(object_type);
134 catalog_object->__set_privilege(TPrivilege());
135 catalog_object->privilege.__set_role_id(atoi(object_name.substr(0, pos).c_str()));
136 catalog_object->privilege.__set_privilege_name(object_name.substr(pos + 1));
139 case TCatalogObjectType::CATALOG:
142 stringstream error_msg;
143 error_msg <<
"Unexpected object type: " << object_type;
144 return Status(error_msg.str());
151 stringstream entry_key;
153 switch (catalog_object.type) {
154 case TCatalogObjectType::DATABASE:
155 entry_key << catalog_object.db.db_name;
157 case TCatalogObjectType::TABLE:
158 case TCatalogObjectType::VIEW:
159 entry_key << catalog_object.table.db_name <<
"." << catalog_object.table.tbl_name;
161 case TCatalogObjectType::FUNCTION:
162 entry_key << catalog_object.fn.name.db_name <<
"."
163 << catalog_object.fn.signature;
165 case TCatalogObjectType::CATALOG:
166 entry_key << catalog_object.catalog.catalog_service_id;
168 case TCatalogObjectType::DATA_SOURCE:
169 entry_key << catalog_object.data_source.name;
171 case TCatalogObjectType::HDFS_CACHE_POOL:
172 entry_key << catalog_object.cache_pool.pool_name;
174 case TCatalogObjectType::ROLE:
175 entry_key << catalog_object.role.role_name;
177 case TCatalogObjectType::PRIVILEGE:
178 entry_key << catalog_object.privilege.role_id <<
"."
179 << catalog_object.privilege.privilege_name;
184 return entry_key.str();
Status TCatalogObjectFromObjectName(const TCatalogObjectType::type &object_type, const string &object_name, TCatalogObject *catalog_object)
string TCatalogObjectToEntryKey(const TCatalogObject &catalog_object)
std::string PrintTCatalogObjectType(const TCatalogObjectType::type &type)
TCatalogObjectType::type TCatalogObjectTypeFromName(const string &name)
Status TCatalogObjectFromEntryKey(const string &key, TCatalogObject *catalog_object)