OmniSciDB  c0231cc57d
 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 (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)
 

Private Member Functions

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

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 155 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 1402 of file DdlCommandExecutor.cpp.

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

1405  : DdlCommand(ddl_data, session_ptr) {
1406  auto& ddl_payload = extractPayload(ddl_data_);
1407  if (ddl_payload.HasMember("tableNames")) {
1408  CHECK(ddl_payload["tableNames"].IsArray());
1409  for (const auto& table_name : ddl_payload["tableNames"].GetArray()) {
1410  CHECK(table_name.IsString());
1411  }
1412  }
1413 }
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:222

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowTableDetailsCommand::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 1415 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 heavydb.cursor.Cursor::executemany().

1415  {
1416  const auto catalog = session_ptr_->get_catalog_ptr();
1417  std::vector<std::string> filtered_table_names = getFilteredTableNames();
1418 
1419  // valid in read_only_mode
1420 
1421  std::vector<TargetMetaInfo> label_infos;
1422  set_headers_with_type(label_infos,
1423  {// { label, type, notNull }
1424  {"table_id", kBIGINT, true},
1425  {"table_name", kTEXT, true},
1426  {"column_count", kBIGINT, true},
1427  {"is_sharded_table", kBOOLEAN, true},
1428  {"shard_count", kBIGINT, true},
1429  {"max_rows", kBIGINT, true},
1430  {"fragment_size", kBIGINT, true},
1431  {"max_rollback_epochs", kBIGINT, true},
1432  {"min_epoch", kBIGINT, true},
1433  {"max_epoch", kBIGINT, true},
1434  {"min_epoch_floor", kBIGINT, true},
1435  {"max_epoch_floor", kBIGINT, true},
1436  {"metadata_file_count", kBIGINT, true},
1437  {"total_metadata_file_size", kBIGINT, true},
1438  {"total_metadata_page_count", kBIGINT, true},
1439  {"total_free_metadata_page_count", kBIGINT, false},
1440  {"data_file_count", kBIGINT, true},
1441  {"total_data_file_size", kBIGINT, true},
1442  {"total_data_page_count", kBIGINT, true},
1443  {"total_free_data_page_count", kBIGINT, false}});
1444 
1445  std::vector<RelLogicalValues::RowValues> logical_values;
1446  for (const auto& table_name : filtered_table_names) {
1447  auto [td, td_with_lock] =
1448  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1449  auto agg_storage_stats = get_agg_storage_stats(td, catalog.get());
1450  add_table_details(logical_values, td, agg_storage_stats);
1451  }
1452 
1453  // Create ResultSet
1454  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1455  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1456 
1457  return ExecutionResult(rSet, label_infos);
1458 }
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:66
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 1460 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().

1460  {
1461  const auto catalog = session_ptr_->get_catalog_ptr();
1462  auto& ddl_payload = extractPayload(ddl_data_);
1463  auto all_table_names =
1464  catalog->getTableNamesForUser(session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
1465  std::transform(all_table_names.begin(),
1466  all_table_names.end(),
1467  all_table_names.begin(),
1468  [](const std::string& s) { return to_upper(s); });
1469  std::vector<std::string> filtered_table_names;
1470  if (ddl_payload.HasMember("tableNames")) {
1471  std::set<std::string> all_table_names_set(all_table_names.begin(),
1472  all_table_names.end());
1473  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1474  std::string table_name = table_name_json.GetString();
1475  if (all_table_names_set.find(to_upper(table_name)) == all_table_names_set.end()) {
1476  throw std::runtime_error{"Unable to show table details for table: " + table_name +
1477  ". Table does not exist."};
1478  }
1479  auto [td, td_with_lock] =
1480  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1481  if (td->isForeignTable()) {
1482  throw std::runtime_error{
1483  "SHOW TABLE DETAILS is not supported for foreign tables. Table name: " +
1484  table_name + "."};
1485  }
1486  if (td->isTemporaryTable()) {
1487  throw std::runtime_error{
1488  "SHOW TABLE DETAILS is not supported for temporary tables. Table name: " +
1489  table_name + "."};
1490  }
1491  filtered_table_names.emplace_back(table_name);
1492  }
1493  } else {
1494  for (const auto& table_name : all_table_names) {
1495  auto [td, td_with_lock] =
1496  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1497  if (td->isForeignTable() || td->isTemporaryTable()) {
1498  continue;
1499  }
1500  filtered_table_names.emplace_back(table_name);
1501  }
1502  }
1503  return filtered_table_names;
1504 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296
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: