OmniSciDB  cde582ebc3
 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 6704 of file ParserNode.cpp.

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

6705  {
6706  CHECK(payload.HasMember("tableName"));
6707  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
6708 
6709  CHECK(payload.HasMember("filePath"));
6710  path_ = std::make_unique<std::string>(json_str(payload["filePath"]));
6711 
6712  compression_ = defaultCompression(is_restore);
6713 
6714  std::list<std::unique_ptr<NameValueAssign>> options;
6715  parse_options(payload, options);
6716 
6717  if (!options.empty()) {
6718  for (auto& p : options) {
6719  if (boost::iequals(*p->get_name(), "compression")) {
6720  checkStringLiteral("compression", p);
6721  const auto str_literal = static_cast<const StringLiteral*>(p->get_value());
6722  compression_ = validateCompression(*str_literal->get_stringval(), is_restore);
6723  }
6724  }
6725  }
6726 
6727  for (const auto& program : {"tar", "rm", "mkdir", "mv", "cat"}) {
6728  if (boost::process::search_path(program).empty()) {
6729  throw std::runtime_error{"Required program \"" + std::string{program} +
6730  "\" was not found."};
6731  }
6732  }
6733 }
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 6736 of file ParserNode.cpp.

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

Referenced by DumpRestoreTableStmtBase().

6737  {
6738  if (boost::process::search_path(is_restore ? Compress::sUNGZIP : Compress::sGZIP)
6739  .string()
6740  .size()) {
6741  return CompressionType::kGZIP;
6742  } else if (boost::process::search_path(is_restore ? Compress::sUNLZ4 : Compress::sLZ4)
6743  .string()
6744  .size()) {
6745  return CompressionType::kLZ4;
6746  }
6747  return CompressionType::kNONE;
6748 }
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 6781 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().

6782  {
6783  if (compression_type == CompressionType::kGZIP) {
6784  return "--use-compress-program=" + (is_restore ? Compress::sUNGZIP : Compress::sGZIP);
6785  } else if (compression_type == CompressionType::kLZ4) {
6786  return "--use-compress-program=" + (is_restore ? Compress::sUNLZ4 : Compress::sLZ4);
6787  }
6788  // kNONE uses "none' as a user input, but an empty string "" for tar
6789  return "";
6790 }
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 6750 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().

6752  {
6753  // only allow ('gzip', 'lz4', 'none') compression types
6754  const std::string compression = boost::algorithm::to_lower_copy(compression_type);
6755 
6756  // verify correct compression executable is available
6757  if (boost::iequals(compression, Compress::sGZIP)) {
6758  const auto prog_name = is_restore ? Compress::sUNGZIP : Compress::sGZIP;
6759  const auto prog_path = boost::process::search_path(prog_name);
6760  if (prog_path.string().empty()) {
6761  throw std::runtime_error("Compression program " + prog_name + " is not found.");
6762  }
6763  return CompressionType::kGZIP;
6764 
6765  } else if (boost::iequals(compression, Compress::sLZ4)) {
6766  const auto prog_name = is_restore ? Compress::sUNLZ4 : Compress::sLZ4;
6767  const auto prog_path = boost::process::search_path(prog_name);
6768  if (prog_path.string().empty()) {
6769  throw std::runtime_error("Compression program " + prog_name + " is not found.");
6770  }
6771  return CompressionType::kLZ4;
6772 
6773  } else if (!boost::iequals(compression, Compress::sNONE)) {
6774  throw std::runtime_error("Compression program " + compression + " is not supported.");
6775  }
6776 
6777  return CompressionType::kNONE;
6778 }
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: