OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShowTableDetailsCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowTableDetailsCommand:
+ Collaboration diagram for ShowTableDetailsCommand:

Public Member Functions

 ShowTableDetailsCommand (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)
 

Private Member Functions

std::vector< std::string > getFilteredTableNames ()
 

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 144 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 1075 of file DdlCommandExecutor.cpp.

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

1078  : DdlCommand(ddl_data, session_ptr) {
1079  auto& ddl_payload = extractPayload(ddl_data_);
1080  if (ddl_payload.HasMember("tableNames")) {
1081  CHECK(ddl_payload["tableNames"].IsArray());
1082  for (const auto& table_name : ddl_payload["tableNames"].GetArray()) {
1083  CHECK(table_name.IsString());
1084  }
1085  }
1086 }
const DdlCommandData & ddl_data_
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:206

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowTableDetailsCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1088 of file DdlCommandExecutor.cpp.

References anonymous_namespace{DdlCommandExecutor.cpp}::add_table_details(), ResultSetLogicalValuesBuilder::create(), anonymous_namespace{DdlCommandExecutor.cpp}::get_agg_storage_stats(), getFilteredTableNames(), kBIGINT, kBOOLEAN, kTEXT, DdlCommand::session_ptr_, and anonymous_namespace{DdlCommandExecutor.cpp}::set_headers_with_type().

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

1088  {
1089  const auto catalog = session_ptr_->get_catalog_ptr();
1090  std::vector<std::string> filtered_table_names = getFilteredTableNames();
1091 
1092  std::vector<TargetMetaInfo> label_infos;
1093  set_headers_with_type(label_infos,
1094  {// { label, type, notNull }
1095  {"table_id", kBIGINT, true},
1096  {"table_name", kTEXT, true},
1097  {"column_count", kBIGINT, true},
1098  {"is_sharded_table", kBOOLEAN, true},
1099  {"shard_count", kBIGINT, true},
1100  {"max_rows", kBIGINT, true},
1101  {"fragment_size", kBIGINT, true},
1102  {"max_rollback_epochs", kBIGINT, true},
1103  {"min_epoch", kBIGINT, true},
1104  {"max_epoch", kBIGINT, true},
1105  {"min_epoch_floor", kBIGINT, true},
1106  {"max_epoch_floor", kBIGINT, true},
1107  {"metadata_file_count", kBIGINT, true},
1108  {"total_metadata_file_size", kBIGINT, true},
1109  {"total_metadata_page_count", kBIGINT, true},
1110  {"total_free_metadata_page_count", kBIGINT, false},
1111  {"data_file_count", kBIGINT, true},
1112  {"total_data_file_size", kBIGINT, true},
1113  {"total_data_page_count", kBIGINT, true},
1114  {"total_free_data_page_count", kBIGINT, false}});
1115 
1116  std::vector<RelLogicalValues::RowValues> logical_values;
1117  for (const auto& table_name : filtered_table_names) {
1118  auto [td, td_with_lock] =
1119  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1120  auto agg_storage_stats = get_agg_storage_stats(td, catalog.get());
1121  add_table_details(logical_values, td, agg_storage_stats);
1122  }
1123 
1124  // Create ResultSet
1125  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1126  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1127 
1128  return ExecutionResult(rSet, label_infos);
1129 }
void add_table_details(std::vector< RelLogicalValues::RowValues > &logical_values, const TableDescriptor *logical_table, const AggregratedStorageStats &agg_storage_stats)
void set_headers_with_type(std::vector< TargetMetaInfo > &label_infos, const std::vector< std::tuple< std::string, SQLTypes, bool >> &headers)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
Definition: sqltypes.h:51
std::vector< std::string > getFilteredTableNames()
AggregratedStorageStats get_agg_storage_stats(const TableDescriptor *td, const Catalog_Namespace::Catalog *catalog)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > ShowTableDetailsCommand::getFilteredTableNames ( )
private

Definition at line 1131 of file DdlCommandExecutor.cpp.

References DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), GET_PHYSICAL_TABLES, DdlCommand::session_ptr_, and to_upper().

Referenced by execute().

1131  {
1132  const auto catalog = session_ptr_->get_catalog_ptr();
1133  auto& ddl_payload = extractPayload(ddl_data_);
1134  auto all_table_names =
1135  catalog->getTableNamesForUser(session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
1136  std::transform(all_table_names.begin(),
1137  all_table_names.end(),
1138  all_table_names.begin(),
1139  [](const std::string& s) { return to_upper(s); });
1140  std::vector<std::string> filtered_table_names;
1141  if (ddl_payload.HasMember("tableNames")) {
1142  std::set<std::string> all_table_names_set(all_table_names.begin(),
1143  all_table_names.end());
1144  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1145  std::string table_name = table_name_json.GetString();
1146  if (all_table_names_set.find(to_upper(table_name)) == all_table_names_set.end()) {
1147  throw std::runtime_error{"Unable to show table details for table: " + table_name +
1148  ". Table does not exist."};
1149  }
1150  auto [td, td_with_lock] =
1151  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1152  if (td->isForeignTable()) {
1153  throw std::runtime_error{
1154  "SHOW TABLE DETAILS is not supported for foreign tables. Table name: " +
1155  table_name + "."};
1156  }
1157  if (td->isTemporaryTable()) {
1158  throw std::runtime_error{
1159  "SHOW TABLE DETAILS is not supported for temporary tables. Table name: " +
1160  table_name + "."};
1161  }
1162  filtered_table_names.emplace_back(table_name);
1163  }
1164  } else {
1165  for (const auto& table_name : all_table_names) {
1166  auto [td, td_with_lock] =
1167  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1168  if (td->isForeignTable() || td->isTemporaryTable()) {
1169  continue;
1170  }
1171  filtered_table_names.emplace_back(table_name);
1172  }
1173  }
1174  return filtered_table_names;
1175 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
std::string to_upper(const std::string &str)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_

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