OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::DumpRestoreTableStmtBase Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::DumpRestoreTableStmtBase:
+ Collaboration diagram for Parser::DumpRestoreTableStmtBase:

Public Types

enum  CompressionType { CompressionType::kGZIP, CompressionType::kLZ4, CompressionType::kNONE }
 

Public Member Functions

 DumpRestoreTableStmtBase (const rapidjson::Value &payload, const bool is_restore)
 
CompressionType defaultCompression (bool is_restore)
 
CompressionType validateCompression (const std::string &compression, const bool is_restore)
 
std::string tarCompressionStr (CompressionType compression, const bool is_restore)
 
const std::string * getTable () const
 
const std::string * getPath () const
 
const CompressionType getCompression () const
 
- Public Member Functions inherited from Parser::DDLStmt
virtual void execute (const Catalog_Namespace::SessionInfo &session, bool read_only_mode)=0
 
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Protected Attributes

std::unique_ptr< std::string > table_
 
std::unique_ptr< std::string > path_
 
CompressionType compression_
 
TableArchiverS3Options s3_options_
 

Detailed Description

Definition at line 1424 of file ParserNode.h.

Member Enumeration Documentation

Enumerator
kGZIP 
kLZ4 
kNONE 

Definition at line 1428 of file ParserNode.h.

1428 { kGZIP, kLZ4, kNONE };

Constructor & Destructor Documentation

Parser::DumpRestoreTableStmtBase::DumpRestoreTableStmtBase ( const rapidjson::Value &  payload,
const bool  is_restore 
)

Definition at line 6797 of file ParserNode.cpp.

References CHECK, compression_, defaultCompression(), Parser::anonymous_namespace{ParserNode.cpp}::get_string_option(), json_str(), Parser::anonymous_namespace{ParserNode.cpp}::parse_options(), path_, TableArchiverS3Options::s3_access_key, TableArchiverS3Options::s3_endpoint, s3_options_, TableArchiverS3Options::s3_region, TableArchiverS3Options::s3_secret_key, TableArchiverS3Options::s3_session_token, table_, and validateCompression().

6798  {
6799  CHECK(payload.HasMember("tableName"));
6800  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
6801 
6802  CHECK(payload.HasMember("filePath"));
6803  path_ = std::make_unique<std::string>(json_str(payload["filePath"]));
6804 
6805  compression_ = defaultCompression(is_restore);
6806 
6807  std::list<std::unique_ptr<NameValueAssign>> options;
6808  parse_options(payload, options);
6809 
6810  if (!options.empty()) {
6811  for (const auto& option : options) {
6812  if (auto compression = get_string_option(option.get(), "compression");
6813  compression.has_value()) {
6814  compression_ = validateCompression(compression.value(), is_restore);
6815 #ifdef HAVE_AWS_S3
6816  } else if (auto s3_access_key = get_string_option(option.get(), "s3_access_key");
6817  s3_access_key.has_value()) {
6818  s3_options_.s3_access_key = s3_access_key.value();
6819  } else if (auto s3_secret_key = get_string_option(option.get(), "s3_secret_key");
6820  s3_secret_key.has_value()) {
6821  s3_options_.s3_secret_key = s3_secret_key.value();
6822  } else if (auto s3_session_token =
6823  get_string_option(option.get(), "s3_session_token");
6824  s3_session_token.has_value()) {
6825  s3_options_.s3_session_token = s3_session_token.value();
6826  } else if (auto s3_region = get_string_option(option.get(), "s3_region");
6827  s3_region.has_value()) {
6828  s3_options_.s3_region = s3_region.value();
6829  } else if (auto s3_endpoint = get_string_option(option.get(), "s3_endpoint");
6830  s3_endpoint.has_value()) {
6831  s3_options_.s3_endpoint = s3_endpoint.value();
6832 #endif
6833  } else {
6834  throw std::runtime_error("Invalid WITH option: " + *option->get_name());
6835  }
6836  }
6837  }
6838 
6839  for (const auto& program : {"tar", "rm", "mkdir", "mv", "cat"}) {
6840  if (boost::process::search_path(program).empty()) {
6841  throw std::runtime_error{"Required program \"" + std::string{program} +
6842  "\" was not found."};
6843  }
6844  }
6845 }
std::string s3_secret_key
Definition: TableArchiver.h:26
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
TableArchiverS3Options s3_options_
Definition: ParserNode.h:1448
CompressionType defaultCompression(bool is_restore)
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1445
std::unique_ptr< std::string > path_
Definition: ParserNode.h:1446
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
std::string s3_session_token
Definition: TableArchiver.h:27
#define CHECK(condition)
Definition: Logger.h:291
std::string s3_access_key
Definition: TableArchiver.h:25
CompressionType validateCompression(const std::string &compression, const bool is_restore)
std::optional< std::string > get_string_option(const NameValueAssign *option, const std::string &option_name)

+ Here is the call graph for this function:

Member Function Documentation

DumpRestoreTableStmtBase::CompressionType Parser::DumpRestoreTableStmtBase::defaultCompression ( bool  is_restore)

Definition at line 6848 of file ParserNode.cpp.

References kGZIP, kLZ4, kNONE, Parser::Compress::sGZIP, Parser::Compress::sLZ4, Parser::Compress::sUNGZIP, and Parser::Compress::sUNLZ4.

Referenced by DumpRestoreTableStmtBase().

6849  {
6850  if (boost::process::search_path(is_restore ? Compress::sUNGZIP : Compress::sGZIP)
6851  .string()
6852  .size()) {
6853  return CompressionType::kGZIP;
6854  } else if (boost::process::search_path(is_restore ? Compress::sUNLZ4 : Compress::sLZ4)
6855  .string()
6856  .size()) {
6857  return CompressionType::kLZ4;
6858  }
6859  return CompressionType::kNONE;
6860 }
const std::string sLZ4
const std::string sUNGZIP
const std::string sGZIP
const std::string sUNLZ4

+ Here is the caller graph for this function:

const CompressionType Parser::DumpRestoreTableStmtBase::getCompression ( ) const
inline

Definition at line 1442 of file ParserNode.h.

References compression_.

1442 { return compression_; }
const std::string* Parser::DumpRestoreTableStmtBase::getPath ( ) const
inline

Definition at line 1441 of file ParserNode.h.

References path_.

1441 { return path_.get(); }
std::unique_ptr< std::string > path_
Definition: ParserNode.h:1446
const std::string* Parser::DumpRestoreTableStmtBase::getTable ( ) const
inline

Definition at line 1440 of file ParserNode.h.

References table_.

1440 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1445
std::string Parser::DumpRestoreTableStmtBase::tarCompressionStr ( CompressionType  compression,
const bool  is_restore 
)

Definition at line 6893 of file ParserNode.cpp.

References kGZIP, kLZ4, Parser::Compress::sGZIP, Parser::Compress::sLZ4, Parser::Compress::sUNGZIP, and Parser::Compress::sUNLZ4.

Referenced by Parser::DumpTableStmt::execute(), and Parser::RestoreTableStmt::execute().

6894  {
6895  if (compression_type == CompressionType::kGZIP) {
6896  return "--use-compress-program=" + (is_restore ? Compress::sUNGZIP : Compress::sGZIP);
6897  } else if (compression_type == CompressionType::kLZ4) {
6898  return "--use-compress-program=" + (is_restore ? Compress::sUNLZ4 : Compress::sLZ4);
6899  }
6900  // kNONE uses "none' as a user input, but an empty string "" for tar
6901  return "";
6902 }
const std::string sLZ4
const std::string sUNGZIP
const std::string sGZIP
const std::string sUNLZ4

+ Here is the caller graph for this function:

DumpRestoreTableStmtBase::CompressionType Parser::DumpRestoreTableStmtBase::validateCompression ( const std::string &  compression,
const bool  is_restore 
)

Definition at line 6862 of file ParserNode.cpp.

References kGZIP, kLZ4, kNONE, Parser::Compress::sGZIP, Parser::Compress::sLZ4, Parser::Compress::sNONE, Parser::Compress::sUNGZIP, and Parser::Compress::sUNLZ4.

Referenced by DumpRestoreTableStmtBase().

6864  {
6865  // only allow ('gzip', 'lz4', 'none') compression types
6866  const std::string compression = boost::algorithm::to_lower_copy(compression_type);
6867 
6868  // verify correct compression executable is available
6869  if (boost::iequals(compression, Compress::sGZIP)) {
6870  const auto prog_name = is_restore ? Compress::sUNGZIP : Compress::sGZIP;
6871  const auto prog_path = boost::process::search_path(prog_name);
6872  if (prog_path.string().empty()) {
6873  throw std::runtime_error("Compression program " + prog_name + " is not found.");
6874  }
6875  return CompressionType::kGZIP;
6876 
6877  } else if (boost::iequals(compression, Compress::sLZ4)) {
6878  const auto prog_name = is_restore ? Compress::sUNLZ4 : Compress::sLZ4;
6879  const auto prog_path = boost::process::search_path(prog_name);
6880  if (prog_path.string().empty()) {
6881  throw std::runtime_error("Compression program " + prog_name + " is not found.");
6882  }
6883  return CompressionType::kLZ4;
6884 
6885  } else if (!boost::iequals(compression, Compress::sNONE)) {
6886  throw std::runtime_error("Compression program " + compression + " is not supported.");
6887  }
6888 
6889  return CompressionType::kNONE;
6890 }
const std::string sLZ4
const std::string sNONE
const std::string sUNGZIP
const std::string sGZIP
const std::string sUNLZ4

+ Here is the caller graph for this function:

Member Data Documentation

CompressionType Parser::DumpRestoreTableStmtBase::compression_
protected
std::unique_ptr<std::string> Parser::DumpRestoreTableStmtBase::path_
protected
TableArchiverS3Options Parser::DumpRestoreTableStmtBase::s3_options_
protected

Definition at line 1448 of file ParserNode.h.

Referenced by DumpRestoreTableStmtBase(), and Parser::RestoreTableStmt::execute().

std::unique_ptr<std::string> Parser::DumpRestoreTableStmtBase::table_
protected

The documentation for this class was generated from the following files: