OmniSciDB  cde582ebc3
 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, bool read_only_mode) 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 1204 of file ParserNode.h.

Member Function Documentation

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

Definition at line 4417 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_stmt_for_json(), and DdlCommandExecutor::execute().

4417  {
4418  CHECK(payload.HasMember("tableName"));
4419  auto tableName = json_str(payload["tableName"]);
4420 
4421  CHECK(payload.HasMember("alterType"));
4422  auto type = json_str(payload["alterType"]);
4423 
4424  if (type == "RENAME_TABLE") {
4425  CHECK(payload.HasMember("newTableName"));
4426  auto newTableName = json_str(payload["newTableName"]);
4427  return std::unique_ptr<DDLStmt>(new Parser::RenameTableStmt(
4428  new std::string(tableName), new std::string(newTableName)));
4429 
4430  } else if (type == "RENAME_COLUMN") {
4431  CHECK(payload.HasMember("columnName"));
4432  auto columnName = json_str(payload["columnName"]);
4433  CHECK(payload.HasMember("newColumnName"));
4434  auto newColumnName = json_str(payload["newColumnName"]);
4435  return std::unique_ptr<DDLStmt>(
4436  new Parser::RenameColumnStmt(new std::string(tableName),
4437  new std::string(columnName),
4438  new std::string(newColumnName)));
4439 
4440  } else if (type == "ADD_COLUMN") {
4441  CHECK(payload.HasMember("columnData"));
4442  CHECK(payload["columnData"].IsArray());
4443 
4444  // New Columns go into this list
4445  std::list<ColumnDef*>* table_element_list_ = new std::list<ColumnDef*>;
4446 
4447  const auto elements = payload["columnData"].GetArray();
4448  for (const auto& element : elements) {
4449  CHECK(element.IsObject());
4450  CHECK(element.HasMember("type"));
4451  if (json_str(element["type"]) == "SQL_COLUMN_DECLARATION") {
4452  auto col_def = column_from_json(element);
4453  table_element_list_->emplace_back(col_def.release());
4454  } else {
4455  LOG(FATAL) << "Unsupported element type for ALTER TABLE: "
4456  << element["type"].GetString();
4457  }
4458  }
4459 
4460  return std::unique_ptr<DDLStmt>(
4461  new Parser::AddColumnStmt(new std::string(tableName), table_element_list_));
4462 
4463  } else if (type == "DROP_COLUMN") {
4464  CHECK(payload.HasMember("columnData"));
4465  auto columnData = json_str(payload["columnData"]);
4466  // Convert columnData to std::list<std::string*>*
4467  // allocate std::list<> as DropColumnStmt will delete it;
4468  std::list<std::string*>* cols = new std::list<std::string*>;
4469  std::vector<std::string> cols1;
4470  boost::split(cols1, columnData, boost::is_any_of(","));
4471  for (auto s : cols1) {
4472  // strip leading/trailing spaces/quotes/single quotes
4473  boost::algorithm::trim_if(s, boost::is_any_of(" \"'`"));
4474  std::string* str = new std::string(s);
4475  cols->emplace_back(str);
4476  }
4477 
4478  return std::unique_ptr<DDLStmt>(
4479  new Parser::DropColumnStmt(new std::string(tableName), cols));
4480 
4481  } else if (type == "ALTER_OPTIONS") {
4482  CHECK(payload.HasMember("options"));
4483 
4484  if (payload["options"].IsObject()) {
4485  for (const auto& option : payload["options"].GetObject()) {
4486  std::string* option_name = new std::string(json_str(option.name));
4487  Literal* literal_value;
4488  if (option.value.IsString()) {
4489  std::string literal_string = json_str(option.value);
4490 
4491  // iff this string can be converted to INT
4492  // ... do so because it is necessary for AlterTableParamStmt
4493  std::size_t sz;
4494  int iVal = std::stoi(literal_string, &sz);
4495  if (sz == literal_string.size()) {
4496  literal_value = new IntLiteral(iVal);
4497  } else {
4498  literal_value = new StringLiteral(&literal_string);
4499  }
4500  } else if (option.value.IsInt() || option.value.IsInt64()) {
4501  literal_value = new IntLiteral(json_i64(option.value));
4502  } else if (option.value.IsNull()) {
4503  literal_value = new NullLiteral();
4504  } else {
4505  throw std::runtime_error("Unable to handle literal for " + *option_name);
4506  }
4507  CHECK(literal_value);
4508 
4509  NameValueAssign* nv = new NameValueAssign(option_name, literal_value);
4510  return std::unique_ptr<DDLStmt>(
4511  new Parser::AlterTableParamStmt(new std::string(tableName), nv));
4512  }
4513 
4514  } else {
4515  CHECK(payload["options"].IsNull());
4516  }
4517  }
4518  return nullptr;
4519 }
#define LOG(tag)
Definition: Logger.h:216
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:222

+ 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,
bool  read_only_mode 
)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 4414 of file ParserNode.cpp.

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

4415  {}

+ Here is the caller graph for this function:

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

Definition at line 1208 of file ParserNode.h.

References table_.

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

Member Data Documentation

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

Definition at line 1215 of file ParserNode.h.

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

Definition at line 1214 of file ParserNode.h.

Referenced by get_table().


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