OmniSciDB  d2f719934e
 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 () 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 127 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 1342 of file DdlCommandExecutor.cpp.

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

1345  : DdlCommand(ddl_data, session_ptr) {
1346  if (!g_enable_fsi) {
1347  throw std::runtime_error("Unsupported command: SHOW FOREIGN SERVERS");
1348  }
1349  // Verify that members are valid
1350  auto& ddl_payload = extractPayload(ddl_data_);
1351  CHECK(ddl_payload.HasMember("command"));
1352  if (ddl_payload.HasMember("filters")) {
1353  CHECK(ddl_payload["filters"].IsArray());
1354  int num_filters = 0;
1355  for (auto const& filter_def : ddl_payload["filters"].GetArray()) {
1356  CHECK(filter_def.IsObject());
1357  CHECK(filter_def.HasMember("attribute"));
1358  CHECK(filter_def["attribute"].IsString());
1359  CHECK(filter_def.HasMember("value"));
1360  CHECK(filter_def["value"].IsString());
1361  CHECK(filter_def.HasMember("operation"));
1362  CHECK(filter_def["operation"].IsString());
1363  if (num_filters > 0) {
1364  CHECK(filter_def.HasMember("chain"));
1365  CHECK(filter_def["chain"].IsString());
1366  } else {
1367  CHECK(!filter_def.HasMember("chain"));
1368  }
1369  num_filters++;
1370  }
1371  }
1372 }
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:211
bool g_enable_fsi
Definition: Catalog.cpp:94

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowForeignServersCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1374 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(), kTEXT, kTIMESTAMP, and DdlCommand::session_ptr_.

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

1374  {
1375  std::vector<TargetMetaInfo> label_infos;
1376  auto& ddl_payload = extractPayload(ddl_data_);
1377 
1378  // label_infos -> column labels
1379  std::vector<std::string> labels{"server_name", "data_wrapper", "created_at", "options"};
1380  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
1381  label_infos.emplace_back(labels[1], SQLTypeInfo(kTEXT, true));
1382  // created_at is a TIMESTAMP
1383  label_infos.emplace_back(labels[2], SQLTypeInfo(kTIMESTAMP, true));
1384  label_infos.emplace_back(labels[3], SQLTypeInfo(kTEXT, true));
1385 
1386  const auto& user = session_ptr_->get_currentUser();
1387 
1388  std::vector<const foreign_storage::ForeignServer*> results;
1389 
1390  session_ptr_->getCatalog().getForeignServersForUser(
1391  extractFilters(ddl_payload), user, results);
1392 
1393  // logical_values -> table data
1394  std::vector<RelLogicalValues::RowValues> logical_values;
1395  for (auto const& server_ptr : results) {
1396  logical_values.emplace_back(RelLogicalValues::RowValues{});
1397  logical_values.back().emplace_back(genLiteralStr(server_ptr->name));
1398  logical_values.back().emplace_back(genLiteralStr(server_ptr->data_wrapper_type));
1399  logical_values.back().emplace_back(genLiteralTimestamp(server_ptr->creation_time));
1400  logical_values.back().emplace_back(
1401  genLiteralStr(server_ptr->getOptionsAsJsonString()));
1402  }
1403 
1404  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1405  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1406 
1407  return ExecutionResult(rSet, label_infos);
1408 }
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:52
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7369
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
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: