OmniSciDB  c0231cc57d
 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 (std::string *tab, std::string *path, std::list< NameValueAssign * > *options, const bool is_restore)
 
 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_
 

Detailed Description

Definition at line 1424 of file ParserNode.h.

Member Enumeration Documentation

Enumerator
kGZIP 
kLZ4 
kNONE 

Definition at line 1467 of file ParserNode.h.

1467 { kGZIP, kLZ4, kNONE };

Constructor & Destructor Documentation

Parser::DumpRestoreTableStmtBase::DumpRestoreTableStmtBase ( std::string *  tab,
std::string *  path,
std::list< NameValueAssign * > *  options,
const bool  is_restore 
)
inline

Definition at line 1426 of file ParserNode.h.

References compression_, defaultCompression(), and validateCompression().

1430  : table_(tab), path_(path) {
1431  for (const auto& program : {"tar", "rm", "mkdir", "mv", "cat"}) {
1432  if (boost::process::search_path(program).empty()) {
1433  throw std::runtime_error{"Required program \"" + std::string{program} +
1434  "\" was not found."};
1435  }
1436  }
1437  auto options_deleter = [](std::list<NameValueAssign*>* options) {
1438  for (auto option : *options) {
1439  delete option;
1440  }
1441  delete options;
1442  };
1443 
1444  compression_ = defaultCompression(is_restore);
1445 
1446  std::unique_ptr<std::list<NameValueAssign*>, decltype(options_deleter)> options_ptr(
1447  options, options_deleter);
1448  // specialize decompressor or break on osx bsdtar...
1449  if (options) {
1450  for (const auto option : *options) {
1451  if (boost::iequals(*option->get_name(), "compression")) {
1452  if (const auto str_literal =
1453  dynamic_cast<const StringLiteral*>(option->get_value())) {
1454  compression_ = validateCompression(*str_literal->get_stringval(), is_restore);
1455  } else {
1456  throw std::runtime_error("Compression option must be a string.");
1457  }
1458  } else {
1459  throw std::runtime_error("Invalid WITH option: " + *option->get_name());
1460  }
1461  }
1462  }
1463  }
CompressionType defaultCompression(bool is_restore)
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1484
std::unique_ptr< std::string > path_
Definition: ParserNode.h:1485
CompressionType validateCompression(const std::string &compression, const bool is_restore)

+ Here is the call graph for this function:

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

Definition at line 6754 of file ParserNode.cpp.

References CHECK, Parser::checkStringLiteral(), compression_, defaultCompression(), json_str(), Parser::anonymous_namespace{ParserNode.cpp}::parse_options(), path_, table_, and validateCompression().

6755  {
6756  CHECK(payload.HasMember("tableName"));
6757  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
6758 
6759  CHECK(payload.HasMember("filePath"));
6760  path_ = std::make_unique<std::string>(json_str(payload["filePath"]));
6761 
6762  compression_ = defaultCompression(is_restore);
6763 
6764  std::list<std::unique_ptr<NameValueAssign>> options;
6765  parse_options(payload, options);
6766 
6767  if (!options.empty()) {
6768  for (auto& p : options) {
6769  if (boost::iequals(*p->get_name(), "compression")) {
6770  checkStringLiteral("compression", p);
6771  const auto str_literal = static_cast<const StringLiteral*>(p->get_value());
6772  compression_ = validateCompression(*str_literal->get_stringval(), is_restore);
6773  }
6774  }
6775  }
6776 
6777  for (const auto& program : {"tar", "rm", "mkdir", "mv", "cat"}) {
6778  if (boost::process::search_path(program).empty()) {
6779  throw std::runtime_error{"Required program \"" + std::string{program} +
6780  "\" was not found."};
6781  }
6782  }
6783 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
CompressionType defaultCompression(bool is_restore)
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1484
std::unique_ptr< std::string > path_
Definition: ParserNode.h:1485
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
#define CHECK(condition)
Definition: Logger.h:222
CompressionType validateCompression(const std::string &compression, const bool is_restore)

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 6786 of file ParserNode.cpp.

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

Referenced by DumpRestoreTableStmtBase().

6787  {
6788  if (boost::process::search_path(is_restore ? Compress::sUNGZIP : Compress::sGZIP)
6789  .string()
6790  .size()) {
6791  return CompressionType::kGZIP;
6792  } else if (boost::process::search_path(is_restore ? Compress::sUNLZ4 : Compress::sLZ4)
6793  .string()
6794  .size()) {
6795  return CompressionType::kLZ4;
6796  }
6797  return CompressionType::kNONE;
6798 }
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 1481 of file ParserNode.h.

References compression_.

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

Definition at line 1480 of file ParserNode.h.

References path_.

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

Definition at line 1479 of file ParserNode.h.

References table_.

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

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

6832  {
6833  if (compression_type == CompressionType::kGZIP) {
6834  return "--use-compress-program=" + (is_restore ? Compress::sUNGZIP : Compress::sGZIP);
6835  } else if (compression_type == CompressionType::kLZ4) {
6836  return "--use-compress-program=" + (is_restore ? Compress::sUNLZ4 : Compress::sLZ4);
6837  }
6838  // kNONE uses "none' as a user input, but an empty string "" for tar
6839  return "";
6840 }
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 6800 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().

6802  {
6803  // only allow ('gzip', 'lz4', 'none') compression types
6804  const std::string compression = boost::algorithm::to_lower_copy(compression_type);
6805 
6806  // verify correct compression executable is available
6807  if (boost::iequals(compression, Compress::sGZIP)) {
6808  const auto prog_name = is_restore ? Compress::sUNGZIP : Compress::sGZIP;
6809  const auto prog_path = boost::process::search_path(prog_name);
6810  if (prog_path.string().empty()) {
6811  throw std::runtime_error("Compression program " + prog_name + " is not found.");
6812  }
6813  return CompressionType::kGZIP;
6814 
6815  } else if (boost::iequals(compression, Compress::sLZ4)) {
6816  const auto prog_name = is_restore ? Compress::sUNLZ4 : Compress::sLZ4;
6817  const auto prog_path = boost::process::search_path(prog_name);
6818  if (prog_path.string().empty()) {
6819  throw std::runtime_error("Compression program " + prog_name + " is not found.");
6820  }
6821  return CompressionType::kLZ4;
6822 
6823  } else if (!boost::iequals(compression, Compress::sNONE)) {
6824  throw std::runtime_error("Compression program " + compression + " is not supported.");
6825  }
6826 
6827  return CompressionType::kNONE;
6828 }
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
std::unique_ptr<std::string> Parser::DumpRestoreTableStmtBase::table_
protected

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