OmniSciDB  c0231cc57d
 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 4469 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().

4469  {
4470  CHECK(payload.HasMember("tableName"));
4471  auto tableName = json_str(payload["tableName"]);
4472 
4473  CHECK(payload.HasMember("alterType"));
4474  auto type = json_str(payload["alterType"]);
4475 
4476  if (type == "RENAME_TABLE") {
4477  CHECK(payload.HasMember("newTableName"));
4478  auto newTableName = json_str(payload["newTableName"]);
4479  return std::unique_ptr<DDLStmt>(new Parser::RenameTableStmt(
4480  new std::string(tableName), new std::string(newTableName)));
4481 
4482  } else if (type == "RENAME_COLUMN") {
4483  CHECK(payload.HasMember("columnName"));
4484  auto columnName = json_str(payload["columnName"]);
4485  CHECK(payload.HasMember("newColumnName"));
4486  auto newColumnName = json_str(payload["newColumnName"]);
4487  return std::unique_ptr<DDLStmt>(
4488  new Parser::RenameColumnStmt(new std::string(tableName),
4489  new std::string(columnName),
4490  new std::string(newColumnName)));
4491 
4492  } else if (type == "ADD_COLUMN") {
4493  CHECK(payload.HasMember("columnData"));
4494  CHECK(payload["columnData"].IsArray());
4495 
4496  // New Columns go into this list
4497  std::list<ColumnDef*>* table_element_list_ = new std::list<ColumnDef*>;
4498 
4499  const auto elements = payload["columnData"].GetArray();
4500  for (const auto& element : elements) {
4501  CHECK(element.IsObject());
4502  CHECK(element.HasMember("type"));
4503  if (json_str(element["type"]) == "SQL_COLUMN_DECLARATION") {
4504  auto col_def = column_from_json(element);
4505  table_element_list_->emplace_back(col_def.release());
4506  } else {
4507  LOG(FATAL) << "Unsupported element type for ALTER TABLE: "
4508  << element["type"].GetString();
4509  }
4510  }
4511 
4512  return std::unique_ptr<DDLStmt>(
4513  new Parser::AddColumnStmt(new std::string(tableName), table_element_list_));
4514 
4515  } else if (type == "DROP_COLUMN") {
4516  CHECK(payload.HasMember("columnData"));
4517  auto columnData = json_str(payload["columnData"]);
4518  // Convert columnData to std::list<std::string*>*
4519  // allocate std::list<> as DropColumnStmt will delete it;
4520  std::list<std::string*>* cols = new std::list<std::string*>;
4521  std::vector<std::string> cols1;
4522  boost::split(cols1, columnData, boost::is_any_of(","));
4523  for (auto s : cols1) {
4524  // strip leading/trailing spaces/quotes/single quotes
4525  boost::algorithm::trim_if(s, boost::is_any_of(" \"'`"));
4526  std::string* str = new std::string(s);
4527  cols->emplace_back(str);
4528  }
4529 
4530  return std::unique_ptr<DDLStmt>(
4531  new Parser::DropColumnStmt(new std::string(tableName), cols));
4532 
4533  } else if (type == "ALTER_OPTIONS") {
4534  CHECK(payload.HasMember("options"));
4535  const auto& options = payload["options"];
4536  if (options.IsObject()) {
4537  for (auto itr = options.MemberBegin(); itr != options.MemberEnd(); ++itr) {
4538  std::string* option_name = new std::string(json_str(itr->name));
4539  Literal* literal_value;
4540  if (itr->value.IsString()) {
4541  std::string literal_string = json_str(itr->value);
4542 
4543  // iff this string can be converted to INT
4544  // ... do so because it is necessary for AlterTableParamStmt
4545  std::size_t sz;
4546  int iVal = std::stoi(literal_string, &sz);
4547  if (sz == literal_string.size()) {
4548  literal_value = new IntLiteral(iVal);
4549  } else {
4550  literal_value = new StringLiteral(&literal_string);
4551  }
4552  } else if (itr->value.IsInt() || itr->value.IsInt64()) {
4553  literal_value = new IntLiteral(json_i64(itr->value));
4554  } else if (itr->value.IsNull()) {
4555  literal_value = new NullLiteral();
4556  } else {
4557  throw std::runtime_error("Unable to handle literal for " + *option_name);
4558  }
4559  CHECK(literal_value);
4560 
4561  NameValueAssign* nv = new NameValueAssign(option_name, literal_value);
4562  return std::unique_ptr<DDLStmt>(
4563  new Parser::AlterTableParamStmt(new std::string(tableName), nv));
4564  }
4565  } else {
4566  CHECK(options.IsNull());
4567  }
4568  }
4569  return nullptr;
4570 }
#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 4466 of file ParserNode.cpp.

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

4467  {}

+ 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: