Merge pull request #44159 from ClickHouse/prevent-delete-nested-if-empty-part

Prevent dropping nested column if it creates empty part
This commit is contained in:
Anton Popov 2022-12-14 15:04:15 +01:00 committed by GitHub
commit 3593377f23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 1 deletions

View File

@ -2600,8 +2600,18 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
} }
} }
if (old_metadata.columns.has(command.column_name))
{
dropped_columns.emplace(command.column_name); dropped_columns.emplace(command.column_name);
} }
else
{
const auto & nested = old_metadata.columns.getNested(command.column_name);
for (const auto & nested_column : nested)
dropped_columns.emplace(nested_column.name);
}
}
else if (command.type == AlterCommand::RESET_SETTING) else if (command.type == AlterCommand::RESET_SETTING)
{ {
for (const auto & reset_setting : command.settings_resets) for (const auto & reset_setting : command.settings_resets)

View File

@ -0,0 +1,49 @@
DROP TABLE IF EXISTS 02500_nested;
SET flatten_nested = 1;
CREATE TABLE 02500_nested(arr Array(Tuple(a Int32, b Int32))) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(arr.a, arr.b) VALUES ([1], [2]);
ALTER TABLE 02500_nested ADD COLUMN z Int32;
ALTER TABLE 02500_nested DROP COLUMN arr; -- { serverError BAD_ARGUMENTS }
DROP TABLE 02500_nested;
CREATE TABLE 02500_nested(arr Array(Tuple(a Int32, b Int32)), z Int32) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(arr.a, arr.b, z) VALUES ([1], [2], 2);
ALTER TABLE 02500_nested DROP COLUMN arr;
DROP TABLE 02500_nested;
CREATE TABLE 02500_nested(nes Nested(a Int32, b Int32)) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(nes.a, nes.b) VALUES ([1], [2]);
ALTER TABLE 02500_nested ADD COLUMN z Int32;
ALTER TABLE 02500_nested DROP COLUMN nes; -- { serverError BAD_ARGUMENTS }
DROP TABLE 02500_nested;
CREATE TABLE 02500_nested(nes Array(Tuple(a Int32, b Int32)), z Int32) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(nes.a, nes.b, z) VALUES ([1], [2], 2);
ALTER TABLE 02500_nested DROP COLUMN nes;
DROP TABLE 02500_nested;
SET flatten_nested = 0;
CREATE TABLE 02500_nested(arr Array(Tuple(a Int32, b Int32))) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(arr) VALUES ([(1, 2)]);
ALTER TABLE 02500_nested ADD COLUMN z Int32;
ALTER TABLE 02500_nested DROP COLUMN arr; -- { serverError BAD_ARGUMENTS }
DROP TABLE 02500_nested;
CREATE TABLE 02500_nested(arr Array(Tuple(a Int32, b Int32)), z Int32) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(arr, z) VALUES ([(1, 2)], 2);
ALTER TABLE 02500_nested DROP COLUMN arr;
DROP TABLE 02500_nested;
CREATE TABLE 02500_nested(nes Nested(a Int32, b Int32)) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(nes) VALUES ([(1, 2)]);
ALTER TABLE 02500_nested ADD COLUMN z Int32;
ALTER TABLE 02500_nested DROP COLUMN nes; -- { serverError BAD_ARGUMENTS }
DROP TABLE 02500_nested;
CREATE TABLE 02500_nested(nes Array(Tuple(a Int32, b Int32)), z Int32) Engine=MergeTree ORDER BY tuple();
INSERT INTO 02500_nested(nes, z) VALUES ([(1, 2)], 2);
ALTER TABLE 02500_nested DROP COLUMN nes;
DROP TABLE 02500_nested;