OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::AlterTableStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::AlterTableStmt:
+ Collaboration diagram for Parser::AlterTableStmt:

Public Member Functions

const std::string * get_table () const
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Static Public Member Functions

static std::unique_ptr
< Parser::DDLStmt
delegate (const rapidjson::Value &payload)
 

Private Attributes

std::unique_ptr< std::string > table_
 
const rapidjson::Value payload_
 

Detailed Description

Definition at line 1186 of file ParserNode.h.

Member Function Documentation

std::unique_ptr< DDLStmt > Parser::AlterTableStmt::delegate ( const rapidjson::Value &  payload)
static

Definition at line 3762 of file ParserNode.cpp.

References CHECK, Parser::anonymous_namespace{ParserNode.cpp}::column_from_json(), logger::FATAL, json_i64(), json_str(), LOG, split(), and run_benchmark_import::type.

Referenced by Parser::create_ddl_from_calcite(), and DdlCommandExecutor::execute().

3762  {
3763  CHECK(payload.HasMember("tableName"));
3764  auto tableName = json_str(payload["tableName"]);
3765 
3766  CHECK(payload.HasMember("alterType"));
3767  auto type = json_str(payload["alterType"]);
3768 
3769  if (type == "RENAME_TABLE") {
3770  CHECK(payload.HasMember("newTableName"));
3771  auto newTableName = json_str(payload["newTableName"]);
3772  return std::unique_ptr<DDLStmt>(new Parser::RenameTableStmt(
3773  new std::string(tableName), new std::string(newTableName)));
3774 
3775  } else if (type == "RENAME_COLUMN") {
3776  CHECK(payload.HasMember("columnName"));
3777  auto columnName = json_str(payload["columnName"]);
3778  CHECK(payload.HasMember("newColumnName"));
3779  auto newColumnName = json_str(payload["newColumnName"]);
3780  return std::unique_ptr<DDLStmt>(
3781  new Parser::RenameColumnStmt(new std::string(tableName),
3782  new std::string(columnName),
3783  new std::string(newColumnName)));
3784 
3785  } else if (type == "ADD_COLUMN") {
3786  CHECK(payload.HasMember("columnData"));
3787  CHECK(payload["columnData"].IsArray());
3788 
3789  // New Columns go into this list
3790  std::list<ColumnDef*>* table_element_list_ = new std::list<ColumnDef*>;
3791 
3792  const auto elements = payload["columnData"].GetArray();
3793  for (const auto& element : elements) {
3794  CHECK(element.IsObject());
3795  CHECK(element.HasMember("type"));
3796  if (json_str(element["type"]) == "SQL_COLUMN_DECLARATION") {
3797  auto col_def = column_from_json(element);
3798  table_element_list_->emplace_back(col_def.release());
3799  } else {
3800  LOG(FATAL) << "Unsupported element type for ALTER TABLE: "
3801  << element["type"].GetString();
3802  }
3803  }
3804 
3805  return std::unique_ptr<DDLStmt>(
3806  new Parser::AddColumnStmt(new std::string(tableName), table_element_list_));
3807 
3808  } else if (type == "DROP_COLUMN") {
3809  CHECK(payload.HasMember("columnData"));
3810  auto columnData = json_str(payload["columnData"]);
3811  // Convert columnData to std::list<std::string*>*
3812  // allocate std::list<> as DropColumnStmt will delete it;
3813  std::list<std::string*>* cols = new std::list<std::string*>;
3814  std::vector<std::string> cols1;
3815  boost::split(cols1, columnData, boost::is_any_of(","));
3816  for (auto s : cols1) {
3817  // strip leading/trailing spaces/quotes/single quotes
3818  boost::algorithm::trim_if(s, boost::is_any_of(" \"'`"));
3819  std::string* str = new std::string(s);
3820  cols->emplace_back(str);
3821  }
3822 
3823  return std::unique_ptr<DDLStmt>(
3824  new Parser::DropColumnStmt(new std::string(tableName), cols));
3825 
3826  } else if (type == "ALTER_OPTIONS") {
3827  CHECK(payload.HasMember("options"));
3828 
3829  if (payload["options"].IsObject()) {
3830  for (const auto& option : payload["options"].GetObject()) {
3831  std::string* option_name = new std::string(json_str(option.name));
3832  Literal* literal_value;
3833  if (option.value.IsString()) {
3834  std::string literal_string = json_str(option.value);
3835 
3836  // iff this string can be converted to INT
3837  // ... do so because it is necessary for AlterTableParamStmt
3838  std::size_t sz;
3839  int iVal = std::stoi(literal_string, &sz);
3840  if (sz == literal_string.size()) {
3841  literal_value = new IntLiteral(iVal);
3842  } else {
3843  literal_value = new StringLiteral(&literal_string);
3844  }
3845  } else if (option.value.IsInt() || option.value.IsInt64()) {
3846  literal_value = new IntLiteral(json_i64(option.value));
3847  } else if (option.value.IsNull()) {
3848  literal_value = new NullLiteral();
3849  } else {
3850  throw std::runtime_error("Unable to handle literal for " + *option_name);
3851  }
3852  CHECK(literal_value);
3853 
3854  NameValueAssign* nv = new NameValueAssign(option_name, literal_value);
3855  return std::unique_ptr<DDLStmt>(
3856  new Parser::AlterTableParamStmt(new std::string(tableName), nv));
3857  }
3858 
3859  } else {
3860  CHECK(payload["options"].IsNull());
3861  }
3862  }
3863  return nullptr;
3864 }
#define LOG(tag)
Definition: Logger.h:203
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
const int64_t json_i64(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:39
std::unique_ptr< ColumnDef > column_from_json(const rapidjson::Value &element)
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Parser::AlterTableStmt::execute ( const Catalog_Namespace::SessionInfo session)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 3760 of file ParserNode.cpp.

Referenced by omnisci.cursor.Cursor::executemany().

3760 {}

+ Here is the caller graph for this function:

const std::string* Parser::AlterTableStmt::get_table ( ) const
inline

Definition at line 1190 of file ParserNode.h.

References table_.

1190 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1195

Member Data Documentation

const rapidjson::Value Parser::AlterTableStmt::payload_
private

Definition at line 1196 of file ParserNode.h.

std::unique_ptr<std::string> Parser::AlterTableStmt::table_
private

Definition at line 1195 of file ParserNode.h.

Referenced by get_table().


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