OmniSciDB  c0231cc57d
 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 167 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 1506 of file DdlCommandExecutor.cpp.

1509  : 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 1511 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, 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().

1511  {
1512  // valid in read_only_mode
1513 
1514  auto& ddl_payload = extractPayload(ddl_data_);
1515  CHECK(ddl_payload.HasMember("tableName"));
1516  CHECK(ddl_payload["tableName"].IsString());
1517  const std::string& table_name = ddl_payload["tableName"].GetString();
1518 
1519  auto& catalog = session_ptr_->getCatalog();
1520  auto table_read_lock =
1522 
1523  const TableDescriptor* td = catalog.getMetadataForTable(table_name, false);
1524  if (!td) {
1525  throw std::runtime_error("Table/View " + table_name + " does not exist.");
1526  }
1527 
1529  dbObject.loadKey(catalog);
1530  std::vector<DBObject> privObjects = {dbObject};
1531 
1532  if (!Catalog_Namespace::SysCatalog::instance().hasAnyPrivileges(
1533  session_ptr_->get_currentUser(), privObjects)) {
1534  throw std::runtime_error("Table/View " + table_name + " does not exist.");
1535  }
1536  if (td->isView && !session_ptr_->get_currentUser().isSuper) {
1537  auto query_state = query_state::QueryState::create(session_ptr_, td->viewSQL);
1538  auto query_state_proxy = query_state->createQueryStateProxy();
1539  auto calcite_mgr = catalog.getCalciteMgr();
1540  const auto calciteQueryParsingOption =
1541  calcite_mgr->getCalciteQueryParsingOption(true, false, false);
1542  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
1543  false,
1545  {},
1547  auto result = calcite_mgr->process(query_state_proxy,
1548  td->viewSQL,
1549  calciteQueryParsingOption,
1550  calciteOptimizationOption);
1551  try {
1552  calcite_mgr->checkAccessedObjectsPrivileges(query_state_proxy, result);
1553  } catch (const std::runtime_error&) {
1554  throw std::runtime_error("Not enough privileges to show the view SQL");
1555  }
1556  }
1557  // Construct
1558  auto create_table_sql = catalog.dumpCreateTable(td);
1561  return result;
1562 }
std::string tableName
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:145
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:341
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
bool g_enable_watchdog
void updateResultSet(const std::string &query_ra, RType type, bool success=true)
static ReadLock getReadLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:238
#define CHECK(condition)
Definition: Logger.h:222
std::string viewSQL
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: