OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 1210 of file DdlCommandExecutor.cpp.

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

1213  : DdlCommand(ddl_data, session_ptr) {
1214  if (!g_enable_fsi) {
1215  throw std::runtime_error("Unsupported command: SHOW FOREIGN SERVERS");
1216  }
1217  // Verify that members are valid
1218  auto& ddl_payload = extractPayload(ddl_data_);
1219  CHECK(ddl_payload.HasMember("command"));
1220  if (ddl_payload.HasMember("filters")) {
1221  CHECK(ddl_payload["filters"].IsArray());
1222  int num_filters = 0;
1223  for (auto const& filter_def : ddl_payload["filters"].GetArray()) {
1224  CHECK(filter_def.IsObject());
1225  CHECK(filter_def.HasMember("attribute"));
1226  CHECK(filter_def["attribute"].IsString());
1227  CHECK(filter_def.HasMember("value"));
1228  CHECK(filter_def["value"].IsString());
1229  CHECK(filter_def.HasMember("operation"));
1230  CHECK(filter_def["operation"].IsString());
1231  if (num_filters > 0) {
1232  CHECK(filter_def.HasMember("chain"));
1233  CHECK(filter_def["chain"].IsString());
1234  } else {
1235  CHECK(!filter_def.HasMember("chain"));
1236  }
1237  num_filters++;
1238  }
1239  }
1240 }
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
bool g_enable_fsi
Definition: Catalog.cpp:92

+ 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 1242 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().

1242  {
1243  std::vector<TargetMetaInfo> label_infos;
1244  auto& ddl_payload = extractPayload(ddl_data_);
1245 
1246  // label_infos -> column labels
1247  std::vector<std::string> labels{"server_name", "data_wrapper", "created_at", "options"};
1248  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
1249  label_infos.emplace_back(labels[1], SQLTypeInfo(kTEXT, true));
1250  // created_at is a TIMESTAMP
1251  label_infos.emplace_back(labels[2], SQLTypeInfo(kTIMESTAMP, true));
1252  label_infos.emplace_back(labels[3], SQLTypeInfo(kTEXT, true));
1253 
1254  const auto& user = session_ptr_->get_currentUser();
1255 
1256  std::vector<const foreign_storage::ForeignServer*> results;
1257 
1258  session_ptr_->getCatalog().getForeignServersForUser(
1259  extractFilters(ddl_payload), user, results);
1260 
1261  // logical_values -> table data
1262  std::vector<RelLogicalValues::RowValues> logical_values;
1263  for (auto const& server_ptr : results) {
1264  logical_values.emplace_back(RelLogicalValues::RowValues{});
1265  logical_values.back().emplace_back(genLiteralStr(server_ptr->name));
1266  logical_values.back().emplace_back(genLiteralStr(server_ptr->data_wrapper_type));
1267  logical_values.back().emplace_back(genLiteralTimestamp(server_ptr->creation_time));
1268  logical_values.back().emplace_back(
1269  genLiteralStr(server_ptr->getOptionsAsJsonString()));
1270  }
1271 
1272  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
1273  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
1274 
1275  return ExecutionResult(rSet, label_infos);
1276 }
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:51
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:6909
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: