OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 1207 of file DdlCommandExecutor.cpp.

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

1210  : DdlCommand(ddl_data, session_ptr) {
1211  auto& ddl_payload = extractPayload(ddl_data_);
1212  if (ddl_payload.HasMember("tableNames")) {
1213  CHECK(ddl_payload["tableNames"].IsArray());
1214  for (const auto& table_name : ddl_payload["tableNames"].GetArray()) {
1215  CHECK(table_name.IsString());
1216  }
1217  }
1218 }
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:211

+ 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 1220 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().

1220  {
1221  const auto catalog = session_ptr_->get_catalog_ptr();
1222  std::vector<std::string> filtered_table_names = getFilteredTableNames();
1223 
1224  std::vector<TargetMetaInfo> label_infos;
1225  set_headers_with_type(label_infos,
1226  {// { label, type, notNull }
1227  {"table_id", kBIGINT, true},
1228  {"table_name", kTEXT, true},
1229  {"column_count", kBIGINT, true},
1230  {"is_sharded_table", kBOOLEAN, true},
1231  {"shard_count", kBIGINT, true},
1232  {"max_rows", kBIGINT, true},
1233  {"fragment_size", kBIGINT, true},
1234  {"max_rollback_epochs", kBIGINT, true},
1235  {"min_epoch", kBIGINT, true},
1236  {"max_epoch", kBIGINT, true},
1237  {"min_epoch_floor", kBIGINT, true},
1238  {"max_epoch_floor", kBIGINT, true},
1239  {"metadata_file_count", kBIGINT, true},
1240  {"total_metadata_file_size", kBIGINT, true},
1241  {"total_metadata_page_count", kBIGINT, true},
1242  {"total_free_metadata_page_count", kBIGINT, false},
1243  {"data_file_count", kBIGINT, true},
1244  {"total_data_file_size", kBIGINT, true},
1245  {"total_data_page_count", kBIGINT, true},
1246  {"total_free_data_page_count", kBIGINT, false}});
1247 
1248  std::vector<RelLogicalValues::RowValues> logical_values;
1249  for (const auto& table_name : filtered_table_names) {
1250  auto [td, td_with_lock] =
1251  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1252  auto agg_storage_stats = get_agg_storage_stats(td, catalog.get());
1253  add_table_details(logical_values, td, agg_storage_stats);
1254  }
1255 
1256  // Create ResultSet
1257  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1258  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1259 
1260  return ExecutionResult(rSet, label_infos);
1261 }
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:52
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 1263 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

1263  {
1264  const auto catalog = session_ptr_->get_catalog_ptr();
1265  auto& ddl_payload = extractPayload(ddl_data_);
1266  auto all_table_names =
1267  catalog->getTableNamesForUser(session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
1268  std::transform(all_table_names.begin(),
1269  all_table_names.end(),
1270  all_table_names.begin(),
1271  [](const std::string& s) { return to_upper(s); });
1272  std::vector<std::string> filtered_table_names;
1273  if (ddl_payload.HasMember("tableNames")) {
1274  std::set<std::string> all_table_names_set(all_table_names.begin(),
1275  all_table_names.end());
1276  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1277  std::string table_name = table_name_json.GetString();
1278  if (all_table_names_set.find(to_upper(table_name)) == all_table_names_set.end()) {
1279  throw std::runtime_error{"Unable to show table details for table: " + table_name +
1280  ". Table does not exist."};
1281  }
1282  auto [td, td_with_lock] =
1283  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1284  if (td->isForeignTable()) {
1285  throw std::runtime_error{
1286  "SHOW TABLE DETAILS is not supported for foreign tables. Table name: " +
1287  table_name + "."};
1288  }
1289  if (td->isTemporaryTable()) {
1290  throw std::runtime_error{
1291  "SHOW TABLE DETAILS is not supported for temporary tables. Table name: " +
1292  table_name + "."};
1293  }
1294  filtered_table_names.emplace_back(table_name);
1295  }
1296  } else {
1297  for (const auto& table_name : all_table_names) {
1298  auto [td, td_with_lock] =
1299  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1300  if (td->isForeignTable() || td->isTemporaryTable()) {
1301  continue;
1302  }
1303  filtered_table_names.emplace_back(table_name);
1304  }
1305  }
1306  return filtered_table_names;
1307 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:288
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: