OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 () 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 Member Functions inherited from DdlCommand
bool isDefaultServer (const std::string &server_name)
 
- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 176 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 1278 of file DdlCommandExecutor.cpp.

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

1281  : DdlCommand(ddl_data, session_ptr) {
1282  auto& ddl_payload = extractPayload(ddl_data_);
1283  CHECK(ddl_payload.HasMember("tableNames"));
1284  CHECK(ddl_payload["tableNames"].IsArray());
1285  for (auto const& tablename_def : ddl_payload["tableNames"].GetArray()) {
1286  CHECK(tablename_def.IsString());
1287  }
1288 }
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:206

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult RefreshForeignTablesCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1290 of file DdlCommandExecutor.cpp.

References cat(), CHECK, DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), Catalog_Namespace::SysCatalog::instance(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), foreign_storage::OptionsContainer::options, foreign_storage::OptionsContainer::populateOptionsMap(), foreign_storage::refresh_foreign_table(), DdlCommand::session_ptr_, and TableDBObjectType.

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

1290  {
1291  bool evict_cached_entries{false};
1293  auto& ddl_payload = extractPayload(ddl_data_);
1294  if (ddl_payload.HasMember("options") && !ddl_payload["options"].IsNull()) {
1295  opt.populateOptionsMap(ddl_payload["options"]);
1296  for (const auto& entry : opt.options) {
1297  if (entry.first != "EVICT") {
1298  throw std::runtime_error{
1299  "Invalid option \"" + entry.first +
1300  "\" provided for refresh command. Only \"EVICT\" option is supported."};
1301  }
1302  }
1303  CHECK(opt.options.find("EVICT") != opt.options.end());
1304 
1305  if (boost::iequals(opt.options["EVICT"], "true") ||
1306  boost::iequals(opt.options["EVICT"], "false")) {
1307  if (boost::iequals(opt.options["EVICT"], "true")) {
1308  evict_cached_entries = true;
1309  }
1310  } else {
1311  throw std::runtime_error{
1312  "Invalid value \"" + opt.options["EVICT"] +
1313  "\" provided for EVICT option. Value must be either \"true\" or \"false\"."};
1314  }
1315  }
1316 
1317  auto& cat = session_ptr_->getCatalog();
1318  const auto& current_user = session_ptr_->get_currentUser();
1319  /* verify object ownership if not suser */
1320  if (!current_user.isSuper) {
1321  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1322  std::string table_name = table_name_json.GetString();
1323  if (!Catalog_Namespace::SysCatalog::instance().verifyDBObjectOwnership(
1324  current_user, DBObject(table_name, TableDBObjectType), cat)) {
1325  throw std::runtime_error(
1326  std::string("REFRESH FOREIGN TABLES failed on table \"") + table_name +
1327  "\". It can only be executed by super user or "
1328  "owner of the "
1329  "object.");
1330  }
1331  }
1332  }
1333 
1334  for (const auto& table_name_json : ddl_payload["tableNames"].GetArray()) {
1335  std::string table_name = table_name_json.GetString();
1336  foreign_storage::refresh_foreign_table(cat, table_name, evict_cached_entries);
1337  }
1338 
1340 
1341  return ExecutionResult();
1342 }
std::string cat(Ts &&...args)
void refresh_foreign_table(Catalog_Namespace::Catalog &catalog, const std::string &table_name, const bool evict_cached_entries)
static void invalidateCaches()
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:292
void populateOptionsMap(OptionsMap &&options_map, bool clear=false)
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
#define CHECK(condition)
Definition: Logger.h:206
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: