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

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowForeignServersCommand:
+ Collaboration diagram for ShowForeignServersCommand:

Public Member Functions

 ShowForeignServersCommand (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 179 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 2540 of file DdlCommandExecutor.cpp.

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

2543  : DdlCommand(ddl_data, session_ptr) {
2544  if (!g_enable_fsi) {
2545  throw std::runtime_error("Unsupported command: SHOW FOREIGN SERVERS");
2546  }
2547  // Verify that members are valid
2548  auto& ddl_payload = extractPayload(ddl_data_);
2549  CHECK(ddl_payload.HasMember("command"));
2550  if (ddl_payload.HasMember("filters")) {
2551  CHECK(ddl_payload["filters"].IsArray());
2552  int num_filters = 0;
2553  for (auto const& filter_def : ddl_payload["filters"].GetArray()) {
2554  CHECK(filter_def.IsObject());
2555  CHECK(filter_def.HasMember("attribute"));
2556  CHECK(filter_def["attribute"].IsString());
2557  CHECK(filter_def.HasMember("value"));
2558  CHECK(filter_def["value"].IsString());
2559  CHECK(filter_def.HasMember("operation"));
2560  CHECK(filter_def["operation"].IsString());
2561  if (num_filters > 0) {
2562  CHECK(filter_def.HasMember("chain"));
2563  CHECK(filter_def["chain"].IsString());
2564  } else {
2565  CHECK(!filter_def.HasMember("chain"));
2566  }
2567  num_filters++;
2568  }
2569  }
2570 }
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 ShowForeignServersCommand::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 2572 of file DdlCommandExecutor.cpp.

References ResultSetLogicalValuesBuilder::create(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractFilters(), anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), genLiteralStr(), anonymous_namespace{DdlCommandExecutor.cpp}::genLiteralTimestamp(), legacylockmgr::getExecuteReadLock(), kTEXT, kTIMESTAMP, and DdlCommand::session_ptr_.

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

2572  {
2573  auto execute_read_lock = legacylockmgr::getExecuteReadLock();
2574 
2575  // valid in read_only_mode
2576 
2577  std::vector<TargetMetaInfo> label_infos;
2578  auto& ddl_payload = extractPayload(ddl_data_);
2579 
2580  // label_infos -> column labels
2581  std::vector<std::string> labels{"server_name", "data_wrapper", "created_at", "options"};
2582  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
2583  label_infos.emplace_back(labels[1], SQLTypeInfo(kTEXT, true));
2584  // created_at is a TIMESTAMP
2585  label_infos.emplace_back(labels[2], SQLTypeInfo(kTIMESTAMP, true));
2586  label_infos.emplace_back(labels[3], SQLTypeInfo(kTEXT, true));
2587 
2588  const auto& user = session_ptr_->get_currentUser();
2589 
2590  std::vector<const foreign_storage::ForeignServer*> results;
2591 
2592  session_ptr_->getCatalog().getForeignServersForUser(
2593  extractFilters(ddl_payload), user, results);
2594 
2595  // logical_values -> table data
2596  std::vector<RelLogicalValues::RowValues> logical_values;
2597  for (auto const& server_ptr : results) {
2598  logical_values.emplace_back(RelLogicalValues::RowValues{});
2599  logical_values.back().emplace_back(genLiteralStr(server_ptr->name));
2600  logical_values.back().emplace_back(genLiteralStr(server_ptr->data_wrapper_type));
2601  logical_values.back().emplace_back(genLiteralTimestamp(server_ptr->creation_time));
2602  logical_values.back().emplace_back(
2603  genLiteralStr(server_ptr->getOptionsAsJsonString()));
2604  }
2605 
2606  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
2607  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
2608 
2609  return ExecutionResult(rSet, label_infos);
2610 }
auto getExecuteReadLock()
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
std::unique_ptr< RexLiteral > genLiteralTimestamp(time_t val)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
Definition: sqltypes.h:79
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7770
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2656
const rapidjson::Value * extractFilters(const rapidjson::Value &payload)

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