Merged DROP_(COLUMN|INDEX|CONSTRAINT) AST parsing into one block

This commit is contained in:
Gleb Novikov 2019-06-30 12:09:58 +02:00
parent bb78012cf9
commit ea4d42c3ac

View File

@ -74,17 +74,6 @@ std::optional<AlterCommand> AlterCommand::parse(const ASTAlterCommand * command_
return command; return command;
} }
else if (command_ast->type == ASTAlterCommand::DROP_COLUMN && !command_ast->partition)
{
if (command_ast->clear_column)
throw Exception("\"ALTER TABLE table CLEAR COLUMN column\" queries are not supported yet. Use \"CLEAR COLUMN column IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED);
AlterCommand command;
command.type = AlterCommand::DROP_COLUMN;
command.column_name = *getIdentifierName(command_ast->column);
command.if_exists = command_ast->if_exists;
return command;
}
else if (command_ast->type == ASTAlterCommand::MODIFY_COLUMN) else if (command_ast->type == ASTAlterCommand::MODIFY_COLUMN)
{ {
AlterCommand command; AlterCommand command;
@ -154,18 +143,6 @@ std::optional<AlterCommand> AlterCommand::parse(const ASTAlterCommand * command_
return command; return command;
} }
else if (command_ast->type == ASTAlterCommand::DROP_INDEX)
{
if (command_ast->clear_column)
throw Exception("\"ALTER TABLE table CLEAR COLUMN column\" queries are not supported yet. Use \"CLEAR COLUMN column IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED);
AlterCommand command;
command.type = AlterCommand::DROP_INDEX;
command.index_name = command_ast->index->as<ASTIdentifier &>().name;
command.if_exists = command_ast->if_exists;
return command;
}
else if (command_ast->type == ASTAlterCommand::ADD_CONSTRAINT) else if (command_ast->type == ASTAlterCommand::ADD_CONSTRAINT)
{ {
AlterCommand command; AlterCommand command;
@ -180,15 +157,25 @@ std::optional<AlterCommand> AlterCommand::parse(const ASTAlterCommand * command_
return command; return command;
} }
else if (command_ast->type == ASTAlterCommand::DROP_CONSTRAINT) else if (command_ast->type == ASTAlterCommand::DROP_CONSTRAINT
|| command_ast->type == ASTAlterCommand::DROP_INDEX
|| (command_ast->type == ASTAlterCommand::DROP_COLUMN && !command_ast->partition))
{ {
if (command_ast->clear_column) if (command_ast->clear_column)
throw Exception("\"ALTER TABLE table CLEAR COLUMN column\" queries are not supported yet. Use \"CLEAR COLUMN column IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED); throw Exception("\"ALTER TABLE table CLEAR COLUMN column\" queries are not supported yet. Use \"CLEAR COLUMN column IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED);
AlterCommand command; AlterCommand command;
command.type = AlterCommand::DROP_CONSTRAINT;
command.constraint_name = command_ast->constraint->as<ASTIdentifier &>().name;
command.if_exists = command_ast->if_exists; command.if_exists = command_ast->if_exists;
if (command_ast->type == ASTAlterCommand::DROP_INDEX) {
command.type = AlterCommand::DROP_INDEX;
command.index_name = command_ast->index->as<ASTIdentifier &>().name;
} else if (command_ast->type == ASTAlterCommand::DROP_CONSTRAINT) {
command.type = AlterCommand::DROP_CONSTRAINT;
command.constraint_name = command_ast->constraint->as<ASTIdentifier &>().name;
} else if (command_ast->type == ASTAlterCommand::DROP_COLUMN) {
command.type = AlterCommand::DROP_COLUMN;
command.column_name = *getIdentifierName(command_ast->column);
}
return command; return command;
} }