Executes the DDL command corresponding to provided JSON payload.
3109 if (read_only_mode) {
3110 throw std::runtime_error(
"ALTER TABLE invalid in read only mode.");
3114 const auto tableName = std::string(ddl_payload[
"tableName"].GetString());
3116 CHECK(ddl_payload.HasMember(
"alterType"));
3119 if (type ==
"RENAME_TABLE") {
3120 CHECK(ddl_payload.HasMember(
"newTableName"));
3121 auto newTableName =
json_str(ddl_payload[
"newTableName"]);
3122 std::unique_ptr<Parser::DDLStmt>(
3124 new std::string(newTableName)))
3128 }
else if (type ==
"RENAME_COLUMN") {
3129 CHECK(ddl_payload.HasMember(
"columnName"));
3130 auto columnName =
json_str(ddl_payload[
"columnName"]);
3131 CHECK(ddl_payload.HasMember(
"newColumnName"));
3132 auto newColumnName =
json_str(ddl_payload[
"newColumnName"]);
3133 std::unique_ptr<Parser::DDLStmt>(
3135 new std::string(columnName),
3136 new std::string(newColumnName)))
3140 }
else if (type ==
"ALTER_COLUMN") {
3142 }
else if (type ==
"ADD_COLUMN") {
3143 CHECK(ddl_payload.HasMember(
"columnData"));
3144 CHECK(ddl_payload[
"columnData"].IsArray());
3147 std::list<Parser::ColumnDef*>* table_element_list_ =
3148 new std::list<Parser::ColumnDef*>;
3150 const auto elements = ddl_payload[
"columnData"].GetArray();
3151 for (
const auto& element : elements) {
3152 CHECK(element.IsObject());
3153 CHECK(element.HasMember(
"type"));
3154 if (
json_str(element[
"type"]) ==
"SQL_COLUMN_DECLARATION") {
3156 table_element_list_->emplace_back(col_def.release());
3158 LOG(
FATAL) <<
"Unsupported element type for ALTER TABLE: "
3159 << element[
"type"].GetString();
3163 std::unique_ptr<Parser::DDLStmt>(
3168 }
else if (type ==
"DROP_COLUMN") {
3169 CHECK(ddl_payload.HasMember(
"columnData"));
3170 auto columnData =
json_str(ddl_payload[
"columnData"]);
3173 std::list<std::string*>* cols =
new std::list<std::string*>;
3174 std::vector<std::string> cols1;
3175 boost::split(cols1, columnData, boost::is_any_of(
","));
3176 for (
auto s : cols1) {
3178 boost::algorithm::trim_if(s, boost::is_any_of(
" \"'`"));
3179 std::string* str =
new std::string(s);
3180 cols->emplace_back(str);
3183 std::unique_ptr<Parser::DDLStmt>(
3188 }
else if (type ==
"ALTER_OPTIONS") {
3189 CHECK(ddl_payload.HasMember(
"options"));
3190 const auto& options = ddl_payload[
"options"];
3191 if (options.IsObject()) {
3192 for (
auto itr = options.MemberBegin(); itr != options.MemberEnd(); ++itr) {
3193 std::string* option_name =
new std::string(
json_str(itr->name));
3195 if (itr->value.IsString()) {
3196 std::string literal_string =
json_str(itr->value);
3201 int iVal = std::stoi(literal_string, &sz);
3202 if (sz == literal_string.size()) {
3207 }
else if (itr->value.IsInt() || itr->value.IsInt64()) {
3209 }
else if (itr->value.IsNull()) {
3212 throw std::runtime_error(
"Unable to handle literal for " + *option_name);
3214 CHECK(literal_value);
3217 std::unique_ptr<Parser::DDLStmt>(
3223 CHECK(options.IsNull());
const std::string json_str(const rapidjson::Value &obj) noexcept
const DdlCommandData & ddl_data_
const int64_t json_i64(const rapidjson::Value &obj) noexcept
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
ExecutionResult execute(bool read_only_mode) override
std::unique_ptr< ColumnDef > column_from_json(const rapidjson::Value &element)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_