OmniSciDB  a5dc49c757
 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 208 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 1626 of file DdlCommandExecutor.cpp.

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

1629  : DdlCommand(ddl_data, session_ptr) {
1630  auto& ddl_payload = extractPayload(ddl_data_);
1631  if (ddl_payload.HasMember("tableNames")) {
1632  CHECK(ddl_payload["tableNames"].IsArray());
1633  for (const auto& table_name : ddl_payload["tableNames"].GetArray()) {
1634  CHECK(table_name.IsString());
1635  }
1636  }
1637 }
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:291

+ 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 1639 of file DdlCommandExecutor.cpp.

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

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

1639  {
1640  auto execute_read_lock = legacylockmgr::getExecuteReadLock();
1641 
1642  const auto catalog = session_ptr_->get_catalog_ptr();
1643  std::vector<std::string> filtered_table_names = getFilteredTableNames();
1644 
1645  // valid in read_only_mode
1646 
1647  std::vector<TargetMetaInfo> label_infos;
1648  set_headers_with_type(label_infos,
1649  {// { label, type, notNull }
1650  {"table_id", kBIGINT, true},
1651  {"table_name", kTEXT, true},
1652  {"column_count", kBIGINT, true},
1653  {"is_sharded_table", kBOOLEAN, true},
1654  {"shard_count", kBIGINT, true},
1655  {"max_rows", kBIGINT, true},
1656  {"fragment_size", kBIGINT, true},
1657  {"max_rollback_epochs", kBIGINT, true},
1658  {"min_epoch", kBIGINT, true},
1659  {"max_epoch", kBIGINT, true},
1660  {"min_epoch_floor", kBIGINT, true},
1661  {"max_epoch_floor", kBIGINT, true},
1662  {"metadata_file_count", kBIGINT, true},
1663  {"total_metadata_file_size", kBIGINT, true},
1664  {"total_metadata_page_count", kBIGINT, true},
1665  {"total_free_metadata_page_count", kBIGINT, false},
1666  {"data_file_count", kBIGINT, true},
1667  {"total_data_file_size", kBIGINT, true},
1668  {"total_data_page_count", kBIGINT, true},
1669  {"total_free_data_page_count", kBIGINT, false}});
1670 
1671  std::vector<RelLogicalValues::RowValues> logical_values;
1672  exec_for_tables_which_exist(filtered_table_names,
1673  catalog.get(),
1674  [&logical_values, &catalog](const TableDescriptor* td,
1675  const std::string& table_name) {
1676  auto agg_storage_stats =
1677  get_agg_storage_stats(td, catalog.get());
1678  add_table_details(logical_values, td, agg_storage_stats);
1679  });
1680 
1681  // Create ResultSet
1682  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1683  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1684 
1685  return ExecutionResult(rSet, label_infos);
1686 }
auto getExecuteReadLock()
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:79
std::vector< std::string > getFilteredTableNames()
AggregratedStorageStats get_agg_storage_stats(const TableDescriptor *td, const Catalog_Namespace::Catalog *catalog)
void exec_for_tables_which_exist(const std::vector< std::string > &table_names, Catalog_Namespace::Catalog *cat_ptr, Func func)
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 1688 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

1688  {
1689  const auto catalog = session_ptr_->get_catalog_ptr();
1690  auto& ddl_payload = extractPayload(ddl_data_);
1691  auto all_table_names =
1692  catalog->getTableNamesForUser(session_ptr_->get_currentUser(), GET_PHYSICAL_TABLES);
1693  std::transform(all_table_names.begin(),
1694  all_table_names.end(),
1695  all_table_names.begin(),
1696  [](const std::string& s) { return to_upper(s); });
1697  std::vector<std::string> filtered_table_names;
1698  if (ddl_payload.HasMember("tableNames")) {
1699  std::set<std::string> all_table_names_set(all_table_names.begin(),
1700  all_table_names.end());
1701  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1702  std::string table_name = table_name_json.GetString();
1703  if (all_table_names_set.find(to_upper(table_name)) == all_table_names_set.end()) {
1704  throw std::runtime_error{"Unable to show table details for table: " + table_name +
1705  ". Table does not exist."};
1706  }
1707  auto [td, td_with_lock] =
1708  get_table_descriptor_with_lock<lockmgr::ReadLock>(*catalog, table_name, false);
1709  if (td->isForeignTable()) {
1710  throw std::runtime_error{
1711  "SHOW TABLE DETAILS is not supported for foreign tables. Table name: " +
1712  table_name + "."};
1713  }
1714  if (td->isTemporaryTable()) {
1715  throw std::runtime_error{
1716  "SHOW TABLE DETAILS is not supported for temporary tables. Table name: " +
1717  table_name + "."};
1718  }
1719  filtered_table_names.emplace_back(table_name);
1720  }
1721  } else {
1722  exec_for_tables_which_exist(all_table_names,
1723  catalog.get(),
1724  [&filtered_table_names](const TableDescriptor* td,
1725  const std::string& table_name) {
1726  if (td->isForeignTable() || td->isTemporaryTable()) {
1727  return;
1728  }
1729  filtered_table_names.emplace_back(table_name);
1730  });
1731  }
1732  return filtered_table_names;
1733 }
bool isForeignTable() const
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:329
std::string to_upper(const std::string &str)
bool isTemporaryTable() const
void exec_for_tables_which_exist(const std::vector< std::string > &table_names, Catalog_Namespace::Catalog *cat_ptr, Func func)
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: