OmniSciDB  d2f719934e
 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 () 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 Member Functions inherited from DdlCommand
bool isDefaultServer (const std::string &server_name)
 
- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 176 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 1655 of file DdlCommandExecutor.cpp.

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

1658  : DdlCommand(ddl_data, session_ptr) {
1659  auto& ddl_payload = extractPayload(ddl_data);
1660  if (ddl_payload.HasMember("userNames")) {
1661  CHECK(ddl_payload["userNames"].IsArray());
1662  for (const auto& user_name : ddl_payload["userNames"].GetArray()) {
1663  CHECK(user_name.IsString());
1664  }
1665  }
1666 }
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:211

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowUserDetailsCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1668 of file DdlCommandExecutor.cpp.

References ResultSetLogicalValuesBuilder::create(), 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, DdlCommand::session_ptr_, and to_string().

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

1668  {
1669  auto& ddl_payload = extractPayload(ddl_data_);
1670  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
1671 
1672  // label_infos -> column labels
1673  std::vector<std::string> labels{"NAME", "ID", "IS_SUPER", "DEFAULT_DB", "CAN_LOGIN"};
1674  std::vector<TargetMetaInfo> label_infos;
1675  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
1676  label_infos.emplace_back(labels[1], SQLTypeInfo(kBIGINT, true));
1677  label_infos.emplace_back(labels[2], SQLTypeInfo(kBOOLEAN, true));
1678  label_infos.emplace_back(labels[3], SQLTypeInfo(kTEXT, true));
1679  label_infos.emplace_back(labels[4], SQLTypeInfo(kBOOLEAN, true));
1680  std::vector<RelLogicalValues::RowValues> logical_values;
1681 
1682  Catalog_Namespace::UserMetadata self = session_ptr_->get_currentUser();
1683  Catalog_Namespace::DBSummaryList dbsums = sys_cat.getDatabaseListForUser(self);
1684  std::unordered_set<std::string> visible_databases;
1685  if (!self.isSuper) {
1686  for (const auto& dbsum : dbsums) {
1687  visible_databases.insert(dbsum.dbName);
1688  }
1689  }
1690 
1691  std::list<Catalog_Namespace::UserMetadata> user_list;
1692  if (ddl_payload.HasMember("userNames")) {
1693  for (const auto& user_name_json : ddl_payload["userNames"].GetArray()) {
1694  std::string user_name = user_name_json.GetString();
1696  if (!sys_cat.getMetadataForUser(user_name, user)) {
1697  throw std::runtime_error("User with username \"" + user_name +
1698  "\" does not exist. ");
1699  }
1700  user_list.emplace_back(std::move(user));
1701  }
1702  } else {
1703  user_list = sys_cat.getAllUserMetadata();
1704  }
1705 
1706  for (const auto& user : user_list) {
1707  // database
1708  std::string dbname;
1710  if (sys_cat.getMetadataForDBById(user.defaultDbId, db)) {
1711  if (self.isSuper.load() || visible_databases.count(db.dbName)) {
1712  dbname = db.dbName;
1713  }
1714  }
1715  if (self.isSuper.load()) {
1716  dbname += "(" + std::to_string(user.defaultDbId) + ")";
1717  }
1718 
1719  // logical_values -> table data
1720  logical_values.emplace_back(RelLogicalValues::RowValues{});
1721  logical_values.back().emplace_back(genLiteralStr(user.userName));
1722  logical_values.back().emplace_back(genLiteralBigInt(user.userId));
1723  logical_values.back().emplace_back(genLiteralBoolean(user.isSuper.load()));
1724  logical_values.back().emplace_back(genLiteralStr(dbname));
1725  logical_values.back().emplace_back(genLiteralBoolean(user.can_login));
1726  }
1727 
1728  // Create ResultSet
1729  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1730  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1731 
1732  return ExecutionResult(rSet, label_infos);
1733 }
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:326
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)
Definition: sqltypes.h:52
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7369
std::list< DBSummary > DBSummaryList
Definition: SysCatalog.h:151
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
std::atomic< bool > isSuper
Definition: SysCatalog.h:120

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