parse and interpret query

This commit is contained in:
Alexander Tokmakov 2019-07-22 14:23:11 +03:00
parent 6f96102fe9
commit 3c2172b750
9 changed files with 55 additions and 3 deletions

View File

@ -336,7 +336,8 @@ struct Settings : public SettingsCollection<Settings>
\
/** Obsolete settings that do nothing but left for compatibility reasons. Remove each one after half a year of obsolescence. */ \
\
M(SettingBool, allow_experimental_low_cardinality_type, true, "Obsolete setting, does nothing. Will be removed after 2019-08-13")
M(SettingBool, allow_experimental_low_cardinality_type, true, "Obsolete setting, does nothing. Will be removed after 2019-08-13") \
M(SettingBool, allow_drop_detached_part, false, "Allow ALTER TABLE ... DROP DETACHED PART ... queries")
DECLARE_SETTINGS_COLLECTION(LIST_OF_SETTINGS)

View File

@ -20,6 +20,7 @@ namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int ILLEGAL_COLUMN;
extern const int SUPPORT_IS_DISABLED;
}
@ -53,7 +54,13 @@ BlockIO InterpreterAlterQuery::execute()
if (auto alter_command = AlterCommand::parse(command_ast))
alter_commands.emplace_back(std::move(*alter_command));
else if (auto partition_command = PartitionCommand::parse(command_ast))
{
if (partition_command->type == PartitionCommand::DROP_DETACHED_PARTITION
&& !context.getSettingsRef().allow_drop_detached_part)
throw DB::Exception("Cannot execute query: DROP DETACHED PART is disabled "
"(see allow_drop_detached setting)", ErrorCodes::SUPPORT_IS_DISABLED);
partition_commands.emplace_back(std::move(*partition_command));
}
else if (auto mut_command = MutationCommand::parse(command_ast))
mutation_commands.emplace_back(std::move(*mut_command));
else

View File

@ -118,6 +118,12 @@ void ASTAlterCommand::formatImpl(
<< (settings.hilite ? hilite_none : "");
partition->formatImpl(settings, state, frame);
}
else if (type == ASTAlterCommand::DROP_DETACHED_PARTITION)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "DROP DETACHED" << (part ? " PART " : " PARTITION ")
<< (settings.hilite ? hilite_none : "");
partition->formatImpl(settings, state, frame);
}
else if (type == ASTAlterCommand::ATTACH_PARTITION)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "ATTACH "

View File

@ -33,6 +33,7 @@ public:
DROP_INDEX,
DROP_PARTITION,
DROP_DETACHED_PARTITION,
ATTACH_PARTITION,
REPLACE_PARTITION,
FETCH_PARTITION,
@ -90,7 +91,7 @@ public:
bool detach = false; /// true for DETACH PARTITION
bool part = false; /// true for ATTACH PART
bool part = false; /// true for ATTACH PART and DROP DETACHED PART
bool clear_column = false; /// for CLEAR COLUMN (do not drop column from metadata)

View File

@ -35,6 +35,8 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
ParserKeyword s_attach_partition("ATTACH PARTITION");
ParserKeyword s_detach_partition("DETACH PARTITION");
ParserKeyword s_drop_partition("DROP PARTITION");
ParserKeyword s_drop_detached_partition("DROP DETACHED PARTITION");
ParserKeyword s_drop_detached_part("DROP DETACHED PART");
ParserKeyword s_attach_part("ATTACH PART");
ParserKeyword s_fetch_partition("FETCH PARTITION");
ParserKeyword s_replace_partition("REPLACE PARTITION");
@ -87,6 +89,21 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
command->type = ASTAlterCommand::DROP_PARTITION;
}
else if (s_drop_detached_partition.ignore(pos, expected))
{
if (!parser_partition.parse(pos, command->partition, expected))
return false;
command->type = ASTAlterCommand::DROP_DETACHED_PARTITION;
}
else if (s_drop_detached_part.ignore(pos, expected))
{
if (!parser_string_literal.parse(pos, command->partition, expected))
return false;
command->type = ASTAlterCommand::DROP_DETACHED_PARTITION;
command->part = true;
}
else if (s_drop_column.ignore(pos, expected))
{
if (s_if_exists.ignore(pos, expected))

View File

@ -23,6 +23,17 @@ std::optional<PartitionCommand> PartitionCommand::parse(const ASTAlterCommand *
res.detach = command_ast->detach;
return res;
}
else if (command_ast->type == ASTAlterCommand::DROP_DETACHED_PARTITION)
{
if (!command_ast->part) // TODO
throw DB::Exception("Not implemented yet", ErrorCodes::NOT_IMPLEMENTED);
PartitionCommand res;
res.type = DROP_DETACHED_PARTITION;
res.partition = command_ast->partition;
res.part = command_ast->part;
return res;
}
else if (command_ast->type == ASTAlterCommand::ATTACH_PARTITION)
{
PartitionCommand res;

View File

@ -21,6 +21,7 @@ struct PartitionCommand
ATTACH_PARTITION,
CLEAR_COLUMN,
DROP_PARTITION,
DROP_DETACHED_PARTITION,
FETCH_PARTITION,
FREEZE_ALL_PARTITIONS,
FREEZE_PARTITION,
@ -35,7 +36,7 @@ struct PartitionCommand
/// true for DETACH PARTITION.
bool detach = false;
/// true for ATTACH PART (and false for PARTITION)
/// true for ATTACH PART and DROP DETACHED PART (and false for PARTITION)
bool part = false;
/// For ATTACH PARTITION partition FROM db.table

View File

@ -920,6 +920,10 @@ void StorageMergeTree::alterPartition(const ASTPtr & query, const PartitionComma
dropPartition(command.partition, command.detach, context);
break;
case PartitionCommand::DROP_DETACHED_PARTITION:
// TODO
throw DB::Exception("Not implemented yet", ErrorCodes::NOT_IMPLEMENTED);
case PartitionCommand::ATTACH_PARTITION:
attachPartition(command.partition, command.part, context);
break;

View File

@ -3348,6 +3348,10 @@ void StorageReplicatedMergeTree::alterPartition(const ASTPtr & query, const Part
dropPartition(query, command.partition, command.detach, query_context);
break;
case PartitionCommand::DROP_DETACHED_PARTITION:
// TODO
throw DB::Exception("Not implemented yet", ErrorCodes::NOT_IMPLEMENTED);
case PartitionCommand::ATTACH_PARTITION:
attachPartition(command.partition, command.part, query_context);
break;