OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowCreateTableCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowCreateTableCommand:
+ Collaboration diagram for ShowCreateTableCommand:

Public Member Functions

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

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

Constructor & Destructor Documentation

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

Definition at line 1735 of file DdlCommandExecutor.cpp.

1738  : DdlCommand(ddl_data, session_ptr) {}
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)

Member Function Documentation

ExecutionResult ShowCreateTableCommand::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 1740 of file DdlCommandExecutor.cpp.

References CHECK, query_state::QueryState::create(), run_benchmark_import::create_table_sql, DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), g_enable_watchdog, legacylockmgr::getExecuteReadLock(), lockmgr::TableLockMgrImpl< TableSchemaLockMgr >::getReadLockForTable(), Catalog_Namespace::SysCatalog::instance(), Catalog_Namespace::SysCatalog::isAggregator(), TableDescriptor::isView, DBObject::loadKey(), run_benchmark_import::result, DdlCommand::session_ptr_, ExecutionResult::SimpleResult, TableDBObjectType, TableDescriptor::tableName, ExecutionResult::updateResultSet(), ViewDBObjectType, and TableDescriptor::viewSQL.

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

1740  {
1741  auto execute_read_lock = legacylockmgr::getExecuteReadLock();
1742 
1743  // valid in read_only_mode
1744 
1745  auto& ddl_payload = extractPayload(ddl_data_);
1746  CHECK(ddl_payload.HasMember("tableName"));
1747  CHECK(ddl_payload["tableName"].IsString());
1748  const std::string& table_name = ddl_payload["tableName"].GetString();
1749 
1750  auto& catalog = session_ptr_->getCatalog();
1751  auto table_read_lock =
1753 
1754  const TableDescriptor* td = catalog.getMetadataForTable(table_name, false);
1755  if (!td) {
1756  throw std::runtime_error("Table/View " + table_name + " does not exist.");
1757  }
1758 
1760  dbObject.loadKey(catalog);
1761  std::vector<DBObject> privObjects = {dbObject};
1762 
1763  if (!Catalog_Namespace::SysCatalog::instance().hasAnyPrivileges(
1764  session_ptr_->get_currentUser(), privObjects)) {
1765  throw std::runtime_error("Table/View " + table_name + " does not exist.");
1766  }
1767  if (td->isView && !session_ptr_->get_currentUser().isSuper) {
1768  auto query_state = query_state::QueryState::create(session_ptr_, td->viewSQL);
1769  auto query_state_proxy = query_state->createQueryStateProxy();
1770  auto calcite_mgr = catalog.getCalciteMgr();
1771  const auto calciteQueryParsingOption =
1772  calcite_mgr->getCalciteQueryParsingOption(true, false, false, false);
1773  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
1774  false,
1776  {},
1778  auto result = calcite_mgr->process(query_state_proxy,
1779  td->viewSQL,
1780  calciteQueryParsingOption,
1781  calciteOptimizationOption);
1782  try {
1783  calcite_mgr->checkAccessedObjectsPrivileges(query_state_proxy, result);
1784  } catch (const std::runtime_error&) {
1785  throw std::runtime_error("Not enough privileges to show the view SQL");
1786  }
1787  }
1788  // Construct
1789  auto create_table_sql = catalog.dumpCreateTable(td);
1792  return result;
1793 }
std::string tableName
auto getExecuteReadLock()
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:148
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:343
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
bool g_enable_watchdog
void updateResultSet(const std::string &query_ra, RType type, bool success=true)
#define CHECK(condition)
Definition: Logger.h:291
std::string viewSQL
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
static ReadLock getReadLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)

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