mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Fix alter table drop projection if exists
This commit is contained in:
parent
9edfc1641a
commit
edd23d06ad
@ -542,7 +542,7 @@ void AlterCommand::apply(StorageInMemoryMetadata & metadata, ContextPtr context)
|
|||||||
else if (type == DROP_PROJECTION)
|
else if (type == DROP_PROJECTION)
|
||||||
{
|
{
|
||||||
if (!partition && !clear)
|
if (!partition && !clear)
|
||||||
metadata.projections.remove(projection_name);
|
metadata.projections.remove(projection_name, if_exists);
|
||||||
}
|
}
|
||||||
else if (type == MODIFY_TTL)
|
else if (type == MODIFY_TTL)
|
||||||
{
|
{
|
||||||
|
@ -265,11 +265,15 @@ void ProjectionsDescription::add(ProjectionDescription && projection, const Stri
|
|||||||
map[it->name] = it;
|
map[it->name] = it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectionsDescription::remove(const String & projection_name)
|
void ProjectionsDescription::remove(const String & projection_name, bool if_exists)
|
||||||
{
|
{
|
||||||
auto it = map.find(projection_name);
|
auto it = map.find(projection_name);
|
||||||
if (it == map.end())
|
if (it == map.end())
|
||||||
|
{
|
||||||
|
if (if_exists)
|
||||||
|
return;
|
||||||
throw Exception("There is no projection " + projection_name + " in table.", ErrorCodes::NO_SUCH_PROJECTION_IN_TABLE);
|
throw Exception("There is no projection " + projection_name + " in table.", ErrorCodes::NO_SUCH_PROJECTION_IN_TABLE);
|
||||||
|
}
|
||||||
|
|
||||||
projections.erase(it->second);
|
projections.erase(it->second);
|
||||||
map.erase(it);
|
map.erase(it);
|
||||||
|
@ -118,7 +118,7 @@ struct ProjectionsDescription
|
|||||||
|
|
||||||
void
|
void
|
||||||
add(ProjectionDescription && projection, const String & after_projection = String(), bool first = false, bool if_not_exists = false);
|
add(ProjectionDescription && projection, const String & after_projection = String(), bool first = false, bool if_not_exists = false);
|
||||||
void remove(const String & projection_name);
|
void remove(const String & projection_name, bool if_exists);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Keep the sequence of columns and allow to lookup by name.
|
/// Keep the sequence of columns and allow to lookup by name.
|
||||||
|
@ -4873,7 +4873,7 @@ void StorageReplicatedMergeTree::alter(
|
|||||||
zookeeper->get(mutations_path, &mutations_stat);
|
zookeeper->get(mutations_path, &mutations_stat);
|
||||||
|
|
||||||
partition_block_numbers_holder =
|
partition_block_numbers_holder =
|
||||||
allocateBlockNumbersInAffectedPartitions(mutation_entry.commands, query_context, zookeeper);
|
allocateBlockNumbersInAffectedPartitions(mutation_entry.commands, query_context, zookeeper);
|
||||||
|
|
||||||
mutation_entry.block_numbers = partition_block_numbers_holder.getBlockNumbers();
|
mutation_entry.block_numbers = partition_block_numbers_holder.getBlockNumbers();
|
||||||
mutation_entry.create_time = time(nullptr);
|
mutation_entry.create_time = time(nullptr);
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
drop table if exists tp;
|
||||||
|
|
||||||
|
create table tp (x Int32, y Int32, projection p (select x, y order by x)) engine = MergeTree order by y;
|
||||||
|
|
||||||
|
alter table tp drop projection pp; -- { serverError 582 }
|
||||||
|
alter table tp drop projection if exists pp;
|
||||||
|
alter table tp drop projection if exists p;
|
||||||
|
alter table tp drop projection p; -- { serverError 582 }
|
||||||
|
alter table tp drop projection if exists p;
|
||||||
|
|
||||||
|
drop table tp;
|
Loading…
Reference in New Issue
Block a user