OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RefreshForeignTablesCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for RefreshForeignTablesCommand:
+ Collaboration diagram for RefreshForeignTablesCommand:

Public Member Functions

 RefreshForeignTablesCommand (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 354 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 2659 of file DdlCommandExecutor.cpp.

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

2662  : DdlCommand(ddl_data, session_ptr) {
2663  if (!g_enable_fsi) {
2664  throw std::runtime_error("Unsupported command: REFRESH FOREIGN TABLE");
2665  }
2666  auto& ddl_payload = extractPayload(ddl_data_);
2667  CHECK(ddl_payload.HasMember("tableNames"));
2668  CHECK(ddl_payload["tableNames"].IsArray());
2669  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
2670  CHECK(tablename_def.IsString());
2671  }
2672 }
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
bool g_enable_fsi
Definition: Catalog.cpp:96

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult RefreshForeignTablesCommand::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 2674 of file DdlCommandExecutor.cpp.

References cat(), CHECK, shared::contains(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), legacylockmgr::getExecuteReadLock(), Catalog_Namespace::SysCatalog::instance(), join(), foreign_storage::OptionsContainer::options, foreign_storage::OptionsContainer::populateOptionsMap(), foreign_storage::refresh_foreign_table(), Catalog_Namespace::REQUEST_LOGS_SYS_TABLE_NAME, Catalog_Namespace::SERVER_LOGS_SYS_TABLE_NAME, DdlCommand::session_ptr_, TableDBObjectType, Catalog_Namespace::WS_SERVER_ACCESS_LOGS_SYS_TABLE_NAME, and Catalog_Namespace::WS_SERVER_LOGS_SYS_TABLE_NAME.

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

2674  {
2675  if (read_only_mode) {
2676  throw std::runtime_error("REFRESH FOREIGN TABLE invalid in read only mode.");
2677  }
2678 
2679  const auto execute_read_lock = legacylockmgr::getExecuteReadLock();
2680 
2681  bool evict_cached_entries{false};
2683  auto& ddl_payload = extractPayload(ddl_data_);
2684  if (ddl_payload.HasMember("options") && !ddl_payload["options"].IsNull()) {
2685  opt.populateOptionsMap(ddl_payload["options"]);
2686  for (const auto& entry : opt.options) {
2687  if (entry.first != "EVICT") {
2688  throw std::runtime_error{
2689  "Invalid option \"" + entry.first +
2690  "\" provided for refresh command. Only \"EVICT\" option is supported."};
2691  }
2692  }
2693  CHECK(opt.options.find("EVICT") != opt.options.end());
2694 
2695  if (boost::iequals(opt.options["EVICT"], "true") ||
2696  boost::iequals(opt.options["EVICT"], "false")) {
2697  if (boost::iequals(opt.options["EVICT"], "true")) {
2698  evict_cached_entries = true;
2699  }
2700  } else {
2701  throw std::runtime_error{
2702  "Invalid value \"" + opt.options["EVICT"] +
2703  "\" provided for EVICT option. Value must be either \"true\" or \"false\"."};
2704  }
2705  }
2706 
2707  auto& cat = session_ptr_->getCatalog();
2708  const auto& current_user = session_ptr_->get_currentUser();
2709  /* verify object ownership if not suser */
2710  if (!current_user.isSuper) {
2711  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
2712  std::string table_name = table_name_json.GetString();
2713  if (!Catalog_Namespace::SysCatalog::instance().verifyDBObjectOwnership(
2714  current_user, DBObject(table_name, TableDBObjectType), cat)) {
2715  throw std::runtime_error(
2716  std::string("REFRESH FOREIGN TABLES failed on table \"") + table_name +
2717  "\". It can only be executed by super user or "
2718  "owner of the "
2719  "object.");
2720  }
2721  }
2722  }
2723 
2724  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
2725  std::string table_name = table_name_json.GetString();
2726  static const std::array<std::string, 4> log_system_tables{
2731  if (cat.isInfoSchemaDb() && !shared::contains(log_system_tables, table_name)) {
2732  throw std::runtime_error(
2733  "REFRESH FOREIGN TABLE can only be executed for the following tables: " +
2734  join(log_system_tables, ","));
2735  }
2736  foreign_storage::refresh_foreign_table(cat, table_name, evict_cached_entries);
2737  }
2738  return ExecutionResult();
2739 }
bool contains(const T &container, const U &element)
Definition: misc.h:195
static constexpr const char * WS_SERVER_ACCESS_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:128
static constexpr const char * SERVER_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:125
std::string cat(Ts &&...args)
auto getExecuteReadLock()
std::string join(T const &container, std::string const &delim)
void refresh_foreign_table(Catalog_Namespace::Catalog &catalog, const std::string &table_name, const bool evict_cached_entries)
static constexpr const char * REQUEST_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:126
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:343
void populateOptionsMap(OptionsMap &&options_map, bool clear=false)
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
#define CHECK(condition)
Definition: Logger.h:291
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
static constexpr const char * WS_SERVER_LOGS_SYS_TABLE_NAME
Definition: Catalog.h:127

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