OmniSciDB  a5dc49c757
 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 337 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 3432 of file DdlCommandExecutor.cpp.

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

3435  : DdlCommand(ddl_data, session_ptr) {
3436  auto& ddl_payload = extractPayload(ddl_data);
3437  if (ddl_payload.HasMember("userNames")) {
3438  CHECK(ddl_payload["userNames"].IsArray());
3439  for (const auto& user_name : ddl_payload["userNames"].GetArray()) {
3440  CHECK(user_name.IsString());
3441  }
3442  }
3443  CHECK(ddl_payload.HasMember("all"));
3444  CHECK(ddl_payload["all"].IsBool());
3445 }
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:291

+ 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 3447 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(), legacylockmgr::getExecuteReadLock(), Catalog_Namespace::SysCatalog::instance(), kBIGINT, kBOOLEAN, kTEXT, DBObject::loadKey(), DdlCommand::session_ptr_, and to_string().

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

3447  {
3448  auto execute_read_lock = legacylockmgr::getExecuteReadLock();
3449 
3450  // valid in read_only_mode
3451 
3452  auto& ddl_payload = extractPayload(ddl_data_);
3453  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
3454 
3455  Catalog_Namespace::UserMetadata self = session_ptr_->get_currentUser();
3456  bool all = ddl_payload.HasMember("all") ? ddl_payload["all"].GetBool() : false;
3457  if (all && !self.isSuper) {
3458  throw std::runtime_error(
3459  "SHOW ALL USER DETAILS is only available to superusers. (Try SHOW USER "
3460  "DETAILS instead?)");
3461  }
3462 
3463  // label_infos -> column labels
3464  std::vector<TargetMetaInfo> label_infos;
3465  label_infos.emplace_back("NAME", SQLTypeInfo(kTEXT, true));
3466  label_infos.emplace_back("ID", SQLTypeInfo(kBIGINT, true));
3467  if (all) {
3468  label_infos.emplace_back("IS_SUPER", SQLTypeInfo(kBOOLEAN, true));
3469  }
3470  label_infos.emplace_back("DEFAULT_DB", SQLTypeInfo(kTEXT, true));
3471  if (self.isSuper) {
3472  label_infos.emplace_back("CAN_LOGIN", SQLTypeInfo(kBOOLEAN, true));
3473  }
3474  std::vector<RelLogicalValues::RowValues> logical_values;
3475 
3476  auto cat = session_ptr_->get_catalog_ptr();
3477  DBObject dbObject(cat->name(), DatabaseDBObjectType);
3478  dbObject.loadKey();
3479  dbObject.setPrivileges(AccessPrivileges::ACCESS);
3480 
3481  std::map<std::string, Catalog_Namespace::UserMetadata> user_map;
3482  auto user_list = !all ? sys_cat.getAllUserMetadata(cat->getDatabaseId())
3483  : sys_cat.getAllUserMetadata();
3484  for (auto& user : user_list) {
3485  if (user.can_login || self.isSuper) { // hide users who have disabled accounts
3486  user_map[user.userName] = user;
3487  }
3488  }
3489 
3490  if (ddl_payload.HasMember("userNames")) {
3491  std::map<std::string, Catalog_Namespace::UserMetadata> user_map2;
3492  for (const auto& user_name_json : ddl_payload["userNames"].GetArray()) {
3493  std::string user_name = user_name_json.GetString();
3494  auto uit = user_map.find(user_name);
3495  if (uit == user_map.end()) {
3496  throw std::runtime_error("User \"" + user_name + "\" not found. ");
3497  }
3498  user_map2[uit->first] = uit->second;
3499  }
3500  user_map = user_map2;
3501  }
3502 
3503  Catalog_Namespace::DBSummaryList dbsums = sys_cat.getDatabaseListForUser(self);
3504  std::unordered_set<std::string> visible_databases;
3505  if (!self.isSuper) {
3506  for (const auto& dbsum : dbsums) {
3507  visible_databases.insert(dbsum.dbName);
3508  }
3509  }
3510 
3511  for (const auto& [user_name, user] : user_map) {
3512  // database
3513  std::string dbname;
3515  if (sys_cat.getMetadataForDBById(user.defaultDbId, db)) {
3516  if (self.isSuper || visible_databases.count(db.dbName)) {
3517  dbname = db.dbName;
3518  }
3519  }
3520  if (self.isSuper) {
3521  dbname += "(" + std::to_string(user.defaultDbId) + ")";
3522  }
3523 
3524  // logical_values -> table data
3525  logical_values.emplace_back(RelLogicalValues::RowValues{});
3526  logical_values.back().emplace_back(genLiteralStr(user.userName));
3527  logical_values.back().emplace_back(genLiteralBigInt(user.userId));
3528  if (all) {
3529  logical_values.back().emplace_back(genLiteralBoolean(user.isSuper));
3530  }
3531  logical_values.back().emplace_back(genLiteralStr(dbname));
3532  if (self.isSuper) {
3533  logical_values.back().emplace_back(genLiteralBoolean(user.can_login));
3534  }
3535  }
3536 
3537  // Create ResultSet
3538  CHECK_EQ(logical_values.size(), user_map.size());
3539  if (logical_values.size() >= 1U) {
3540  CHECK_EQ(logical_values[0].size(), label_infos.size());
3541  }
3542  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
3543  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
3544 
3545  return ExecutionResult(rSet, label_infos);
3546 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::string cat(Ts &&...args)
auto getExecuteReadLock()
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:343
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:79
static const AccessPrivileges ACCESS
Definition: DBObject.h:153
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7770
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:2656

+ 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: