OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowUserDetailsCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowUserDetailsCommand:
+ Collaboration diagram for ShowUserDetailsCommand:

Public Member Functions

 ShowUserDetailsCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute (bool read_only_mode) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Additional Inherited Members

- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 231 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

ShowUserDetailsCommand::ShowUserDetailsCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 2199 of file DdlCommandExecutor.cpp.

References CHECK, and anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload().

2202  : DdlCommand(ddl_data, session_ptr) {
2203  auto& ddl_payload = extractPayload(ddl_data);
2204  if (ddl_payload.HasMember("userNames")) {
2205  CHECK(ddl_payload["userNames"].IsArray());
2206  for (const auto& user_name : ddl_payload["userNames"].GetArray()) {
2207  CHECK(user_name.IsString());
2208  }
2209  }
2210  CHECK(ddl_payload.HasMember("all"));
2211  CHECK(ddl_payload["all"].IsBool());
2212 }
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowUserDetailsCommand::execute ( bool  read_only_mode)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 2214 of file DdlCommandExecutor.cpp.

References AccessPrivileges::ACCESS, cat(), CHECK_EQ, ResultSetLogicalValuesBuilder::create(), DatabaseDBObjectType, Catalog_Namespace::DBMetadata::dbName, DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), anonymous_namespace{DdlCommandExecutor.cpp}::genLiteralBigInt(), anonymous_namespace{DdlCommandExecutor.cpp}::genLiteralBoolean(), genLiteralStr(), Catalog_Namespace::SysCatalog::instance(), kBIGINT, kBOOLEAN, kTEXT, DBObject::loadKey(), DdlCommand::session_ptr_, and to_string().

Referenced by heavydb.cursor.Cursor::executemany().

2214  {
2215  // valid in read_only_mode
2216 
2217  auto& ddl_payload = extractPayload(ddl_data_);
2218  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
2219 
2220  Catalog_Namespace::UserMetadata self = session_ptr_->get_currentUser();
2221  bool all = ddl_payload.HasMember("all") ? ddl_payload["all"].GetBool() : false;
2222  if (all && !self.isSuper) {
2223  throw std::runtime_error(
2224  "SHOW ALL USER DETAILS is only available to superusers. (Try SHOW USER "
2225  "DETAILS instead?)");
2226  }
2227 
2228  // label_infos -> column labels
2229  std::vector<TargetMetaInfo> label_infos;
2230  label_infos.emplace_back("NAME", SQLTypeInfo(kTEXT, true));
2231  label_infos.emplace_back("ID", SQLTypeInfo(kBIGINT, true));
2232  if (all) {
2233  label_infos.emplace_back("IS_SUPER", SQLTypeInfo(kBOOLEAN, true));
2234  }
2235  label_infos.emplace_back("DEFAULT_DB", SQLTypeInfo(kTEXT, true));
2236  if (self.isSuper) {
2237  label_infos.emplace_back("CAN_LOGIN", SQLTypeInfo(kBOOLEAN, true));
2238  }
2239  std::vector<RelLogicalValues::RowValues> logical_values;
2240 
2241  auto cat = session_ptr_->get_catalog_ptr();
2242  DBObject dbObject(cat->name(), DatabaseDBObjectType);
2243  dbObject.loadKey();
2244  dbObject.setPrivileges(AccessPrivileges::ACCESS);
2245 
2246  std::map<std::string, Catalog_Namespace::UserMetadata> user_map;
2247  auto user_list = !all ? sys_cat.getAllUserMetadata(cat->getDatabaseId())
2248  : sys_cat.getAllUserMetadata();
2249  for (auto& user : user_list) {
2250  if (user.can_login || self.isSuper) { // hide users who have disabled accounts
2251  user_map[user.userName] = user;
2252  }
2253  }
2254 
2255  if (ddl_payload.HasMember("userNames")) {
2256  std::map<std::string, Catalog_Namespace::UserMetadata> user_map2;
2257  for (const auto& user_name_json : ddl_payload["userNames"].GetArray()) {
2258  std::string user_name = user_name_json.GetString();
2259  auto uit = user_map.find(user_name);
2260  if (uit == user_map.end()) {
2261  throw std::runtime_error("User \"" + user_name + "\" not found. ");
2262  }
2263  user_map2[uit->first] = uit->second;
2264  }
2265  user_map = user_map2;
2266  }
2267 
2268  Catalog_Namespace::DBSummaryList dbsums = sys_cat.getDatabaseListForUser(self);
2269  std::unordered_set<std::string> visible_databases;
2270  if (!self.isSuper) {
2271  for (const auto& dbsum : dbsums) {
2272  visible_databases.insert(dbsum.dbName);
2273  }
2274  }
2275 
2276  for (const auto& [user_name, user] : user_map) {
2277  // database
2278  std::string dbname;
2280  if (sys_cat.getMetadataForDBById(user.defaultDbId, db)) {
2281  if (self.isSuper || visible_databases.count(db.dbName)) {
2282  dbname = db.dbName;
2283  }
2284  }
2285  if (self.isSuper) {
2286  dbname += "(" + std::to_string(user.defaultDbId) + ")";
2287  }
2288 
2289  // logical_values -> table data
2290  logical_values.emplace_back(RelLogicalValues::RowValues{});
2291  logical_values.back().emplace_back(genLiteralStr(user.userName));
2292  logical_values.back().emplace_back(genLiteralBigInt(user.userId));
2293  if (all) {
2294  logical_values.back().emplace_back(genLiteralBoolean(user.isSuper));
2295  }
2296  logical_values.back().emplace_back(genLiteralStr(dbname));
2297  if (self.isSuper) {
2298  logical_values.back().emplace_back(genLiteralBoolean(user.can_login));
2299  }
2300  }
2301 
2302  // Create ResultSet
2303  CHECK_EQ(logical_values.size(), user_map.size());
2304  if (logical_values.size() >= 1U) {
2305  CHECK_EQ(logical_values[0].size(), label_infos.size());
2306  }
2307  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
2308  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
2309 
2310  return ExecutionResult(rSet, label_infos);
2311 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::string cat(Ts &&...args)
std::string to_string(char const *&&v)
std::unique_ptr< RexLiteral > genLiteralBigInt(int64_t val)
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:341
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
std::unique_ptr< RexLiteral > genLiteralBoolean(bool val)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
void loadKey()
Definition: DBObject.cpp:190
Definition: sqltypes.h:66
static const AccessPrivileges ACCESS
Definition: DBObject.h:153
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7263
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:145
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2226

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: