OmniSciDB  f17484ade4
 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 1411 of file ParserNode.h.

Member Enumeration Documentation

Enumerator
kGZIP 
kLZ4 
kNONE 

Definition at line 1415 of file ParserNode.h.

1415 { kGZIP, kLZ4, kNONE };

Constructor & Destructor Documentation

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

Definition at line 7079 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().

7080  {
7081  CHECK(payload.HasMember("tableName"));
7082  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
7083 
7084  CHECK(payload.HasMember("filePath"));
7085  path_ = std::make_unique<std::string>(json_str(payload["filePath"]));
7086 
7087  compression_ = defaultCompression(is_restore);
7088 
7089  std::list<std::unique_ptr<NameValueAssign>> options;
7090  parse_options(payload, options);
7091 
7092  if (!options.empty()) {
7093  for (const auto& option : options) {
7094  if (auto compression = get_string_option(option.get(), "compression");
7095  compression.has_value()) {
7096  compression_ = validateCompression(compression.value(), is_restore);
7097 #ifdef HAVE_AWS_S3
7098  } else if (auto s3_access_key = get_string_option(option.get(), "s3_access_key");
7099  s3_access_key.has_value()) {
7100  s3_options_.s3_access_key = s3_access_key.value();
7101  } else if (auto s3_secret_key = get_string_option(option.get(), "s3_secret_key");
7102  s3_secret_key.has_value()) {
7103  s3_options_.s3_secret_key = s3_secret_key.value();
7104  } else if (auto s3_session_token =
7105  get_string_option(option.get(), "s3_session_token");
7106  s3_session_token.has_value()) {
7107  s3_options_.s3_session_token = s3_session_token.value();
7108  } else if (auto s3_region = get_string_option(option.get(), "s3_region");
7109  s3_region.has_value()) {
7110  s3_options_.s3_region = s3_region.value();
7111  } else if (auto s3_endpoint = get_string_option(option.get(), "s3_endpoint");
7112  s3_endpoint.has_value()) {
7113  s3_options_.s3_endpoint = s3_endpoint.value();
7114 #endif
7115  } else {
7116  throw std::runtime_error("Invalid WITH option: " + *option->get_name());
7117  }
7118  }
7119  }
7120 
7121  for (const auto& program : {"tar", "rm", "mkdir", "mv", "cat"}) {
7122  if (boost::process::search_path(program).empty()) {
7123  throw std::runtime_error{"Required program \"" + std::string{program} +
7124  "\" was not found."};
7125  }
7126  }
7127 }
std::string s3_secret_key
Definition: TableArchiver.h:26
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
TableArchiverS3Options s3_options_
Definition: ParserNode.h:1435
CompressionType defaultCompression(bool is_restore)
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1432
std::unique_ptr< std::string > path_
Definition: ParserNode.h:1433
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 7130 of file ParserNode.cpp.

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

Referenced by DumpRestoreTableStmtBase().

7131  {
7132  if (boost::process::search_path(is_restore ? Compress::sUNGZIP : Compress::sGZIP)
7133  .string()
7134  .size()) {
7135  return CompressionType::kGZIP;
7136  } else if (boost::process::search_path(is_restore ? Compress::sUNLZ4 : Compress::sLZ4)
7137  .string()
7138  .size()) {
7139  return CompressionType::kLZ4;
7140  }
7141  return CompressionType::kNONE;
7142 }
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 1429 of file ParserNode.h.

References compression_.

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

Definition at line 1428 of file ParserNode.h.

References path_.

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

Definition at line 1427 of file ParserNode.h.

References table_.

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

Definition at line 7175 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().

7176  {
7177  if (compression_type == CompressionType::kGZIP) {
7178  return "--use-compress-program=" + (is_restore ? Compress::sUNGZIP : Compress::sGZIP);
7179  } else if (compression_type == CompressionType::kLZ4) {
7180  return "--use-compress-program=" + (is_restore ? Compress::sUNLZ4 : Compress::sLZ4);
7181  }
7182  // kNONE uses "none' as a user input, but an empty string "" for tar
7183  return "";
7184 }
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 7144 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().

7146  {
7147  // only allow ('gzip', 'lz4', 'none') compression types
7148  const std::string compression = boost::algorithm::to_lower_copy(compression_type);
7149 
7150  // verify correct compression executable is available
7151  if (boost::iequals(compression, Compress::sGZIP)) {
7152  const auto prog_name = is_restore ? Compress::sUNGZIP : Compress::sGZIP;
7153  const auto prog_path = boost::process::search_path(prog_name);
7154  if (prog_path.string().empty()) {
7155  throw std::runtime_error("Compression program " + prog_name + " is not found.");
7156  }
7157  return CompressionType::kGZIP;
7158 
7159  } else if (boost::iequals(compression, Compress::sLZ4)) {
7160  const auto prog_name = is_restore ? Compress::sUNLZ4 : Compress::sLZ4;
7161  const auto prog_path = boost::process::search_path(prog_name);
7162  if (prog_path.string().empty()) {
7163  throw std::runtime_error("Compression program " + prog_name + " is not found.");
7164  }
7165  return CompressionType::kLZ4;
7166 
7167  } else if (!boost::iequals(compression, Compress::sNONE)) {
7168  throw std::runtime_error("Compression program " + compression + " is not supported.");
7169  }
7170 
7171  return CompressionType::kNONE;
7172 }
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 1435 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: