OmniSciDB  72c90bc290
 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 7080 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().

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

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

Referenced by DumpRestoreTableStmtBase().

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

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

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