OmniSciDB  a5dc49c757
 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 7101 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().

7102  {
7103  CHECK(payload.HasMember("tableName"));
7104  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
7105 
7106  CHECK(payload.HasMember("filePath"));
7107  path_ = std::make_unique<std::string>(json_str(payload["filePath"]));
7108 
7109  compression_ = defaultCompression(is_restore);
7110 
7111  std::list<std::unique_ptr<NameValueAssign>> options;
7112  parse_options(payload, options);
7113 
7114  if (!options.empty()) {
7115  for (const auto& option : options) {
7116  if (auto compression = get_string_option(option.get(), "compression");
7117  compression.has_value()) {
7118  compression_ = validateCompression(compression.value(), is_restore);
7119 #ifdef HAVE_AWS_S3
7120  } else if (auto s3_access_key = get_string_option(option.get(), "s3_access_key");
7121  s3_access_key.has_value()) {
7122  s3_options_.s3_access_key = s3_access_key.value();
7123  } else if (auto s3_secret_key = get_string_option(option.get(), "s3_secret_key");
7124  s3_secret_key.has_value()) {
7125  s3_options_.s3_secret_key = s3_secret_key.value();
7126  } else if (auto s3_session_token =
7127  get_string_option(option.get(), "s3_session_token");
7128  s3_session_token.has_value()) {
7129  s3_options_.s3_session_token = s3_session_token.value();
7130  } else if (auto s3_region = get_string_option(option.get(), "s3_region");
7131  s3_region.has_value()) {
7132  s3_options_.s3_region = s3_region.value();
7133  } else if (auto s3_endpoint = get_string_option(option.get(), "s3_endpoint");
7134  s3_endpoint.has_value()) {
7135  s3_options_.s3_endpoint = s3_endpoint.value();
7136 #endif
7137  } else {
7138  throw std::runtime_error("Invalid WITH option: " + *option->get_name());
7139  }
7140  }
7141  }
7142 
7143  for (const auto& program : {"tar", "rm", "mkdir", "mv", "cat"}) {
7144  if (boost::process::search_path(program).empty()) {
7145  throw std::runtime_error{"Required program \"" + std::string{program} +
7146  "\" was not found."};
7147  }
7148  }
7149 }
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 7152 of file ParserNode.cpp.

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

Referenced by DumpRestoreTableStmtBase().

7153  {
7154  if (boost::process::search_path(is_restore ? Compress::sUNGZIP : Compress::sGZIP)
7155  .string()
7156  .size()) {
7157  return CompressionType::kGZIP;
7158  } else if (boost::process::search_path(is_restore ? Compress::sUNLZ4 : Compress::sLZ4)
7159  .string()
7160  .size()) {
7161  return CompressionType::kLZ4;
7162  }
7163  return CompressionType::kNONE;
7164 }
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 7197 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().

7198  {
7199  if (compression_type == CompressionType::kGZIP) {
7200  return "--use-compress-program=" + (is_restore ? Compress::sUNGZIP : Compress::sGZIP);
7201  } else if (compression_type == CompressionType::kLZ4) {
7202  return "--use-compress-program=" + (is_restore ? Compress::sUNLZ4 : Compress::sLZ4);
7203  }
7204  // kNONE uses "none' as a user input, but an empty string "" for tar
7205  return "";
7206 }
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 7166 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().

7168  {
7169  // only allow ('gzip', 'lz4', 'none') compression types
7170  const std::string compression = boost::algorithm::to_lower_copy(compression_type);
7171 
7172  // verify correct compression executable is available
7173  if (boost::iequals(compression, Compress::sGZIP)) {
7174  const auto prog_name = is_restore ? Compress::sUNGZIP : Compress::sGZIP;
7175  const auto prog_path = boost::process::search_path(prog_name);
7176  if (prog_path.string().empty()) {
7177  throw std::runtime_error("Compression program " + prog_name + " is not found.");
7178  }
7179  return CompressionType::kGZIP;
7180 
7181  } else if (boost::iequals(compression, Compress::sLZ4)) {
7182  const auto prog_name = is_restore ? Compress::sUNLZ4 : Compress::sLZ4;
7183  const auto prog_path = boost::process::search_path(prog_name);
7184  if (prog_path.string().empty()) {
7185  throw std::runtime_error("Compression program " + prog_name + " is not found.");
7186  }
7187  return CompressionType::kLZ4;
7188 
7189  } else if (!boost::iequals(compression, Compress::sNONE)) {
7190  throw std::runtime_error("Compression program " + compression + " is not supported.");
7191  }
7192 
7193  return CompressionType::kNONE;
7194 }
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: