OmniSciDB  c0231cc57d
 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 126 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 1806 of file DdlCommandExecutor.cpp.

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

1809  : DdlCommand(ddl_data, session_ptr) {
1810  if (!g_enable_fsi) {
1811  throw std::runtime_error("Unsupported command: SHOW FOREIGN SERVERS");
1812  }
1813  // Verify that members are valid
1814  auto& ddl_payload = extractPayload(ddl_data_);
1815  CHECK(ddl_payload.HasMember("command"));
1816  if (ddl_payload.HasMember("filters")) {
1817  CHECK(ddl_payload["filters"].IsArray());
1818  int num_filters = 0;
1819  for (auto const& filter_def : ddl_payload["filters"].GetArray()) {
1820  CHECK(filter_def.IsObject());
1821  CHECK(filter_def.HasMember("attribute"));
1822  CHECK(filter_def["attribute"].IsString());
1823  CHECK(filter_def.HasMember("value"));
1824  CHECK(filter_def["value"].IsString());
1825  CHECK(filter_def.HasMember("operation"));
1826  CHECK(filter_def["operation"].IsString());
1827  if (num_filters > 0) {
1828  CHECK(filter_def.HasMember("chain"));
1829  CHECK(filter_def["chain"].IsString());
1830  } else {
1831  CHECK(!filter_def.HasMember("chain"));
1832  }
1833  num_filters++;
1834  }
1835  }
1836 }
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:222
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 1838 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 heavydb.cursor.Cursor::executemany().

1838  {
1839  // valid in read_only_mode
1840 
1841  std::vector<TargetMetaInfo> label_infos;
1842  auto& ddl_payload = extractPayload(ddl_data_);
1843 
1844  // label_infos -> column labels
1845  std::vector<std::string> labels{"server_name", "data_wrapper", "created_at", "options"};
1846  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
1847  label_infos.emplace_back(labels[1], SQLTypeInfo(kTEXT, true));
1848  // created_at is a TIMESTAMP
1849  label_infos.emplace_back(labels[2], SQLTypeInfo(kTIMESTAMP, true));
1850  label_infos.emplace_back(labels[3], SQLTypeInfo(kTEXT, true));
1851 
1852  const auto& user = session_ptr_->get_currentUser();
1853 
1854  std::vector<const foreign_storage::ForeignServer*> results;
1855 
1856  session_ptr_->getCatalog().getForeignServersForUser(
1857  extractFilters(ddl_payload), user, results);
1858 
1859  // logical_values -> table data
1860  std::vector<RelLogicalValues::RowValues> logical_values;
1861  for (auto const& server_ptr : results) {
1862  logical_values.emplace_back(RelLogicalValues::RowValues{});
1863  logical_values.back().emplace_back(genLiteralStr(server_ptr->name));
1864  logical_values.back().emplace_back(genLiteralStr(server_ptr->data_wrapper_type));
1865  logical_values.back().emplace_back(genLiteralTimestamp(server_ptr->creation_time));
1866  logical_values.back().emplace_back(
1867  genLiteralStr(server_ptr->getOptionsAsJsonString()));
1868  }
1869 
1870  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1871  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1872 
1873  return ExecutionResult(rSet, label_infos);
1874 }
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:66
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7263
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2226
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: