Better message on error

This commit is contained in:
alesapin 2020-09-29 15:07:01 +03:00
parent 4f79310f00
commit 65a05a970d
5 changed files with 144 additions and 0 deletions

View File

@ -1458,6 +1458,16 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
} }
else if (command.isRequireMutationStage(getInMemoryMetadata())) else if (command.isRequireMutationStage(getInMemoryMetadata()))
{ {
/// Type change for version column is allowed despite it's a part of sorting key
if (command.type == AlterCommand::MODIFY_COLUMN && command.column_name == merging_params.version_column)
{
if (!command.data_type->canBeUsedAsVersion())
throw Exception("Cannot alter version column " + backQuoteIfNeed(command.column_name) +
" to type " + command.data_type->getName() +
" because version column must be of an integer type or of type Date or DateTime"
, ErrorCodes::ALTER_OF_COLUMN_IS_FORBIDDEN);
continue;
}
/// This alter will override data on disk. Let's check that it doesn't /// This alter will override data on disk. Let's check that it doesn't
/// modify immutable column. /// modify immutable column.
if (columns_alter_type_forbidden.count(command.column_name)) if (columns_alter_type_forbidden.count(command.column_name))

View File

@ -0,0 +1,13 @@
1 1 1 -1
2 2 2 -1
CREATE TABLE default.table_with_version\n(\n `key` UInt64,\n `value` String,\n `version` UInt8,\n `sign` Int8\n)\nENGINE = VersionedCollapsingMergeTree(sign, version)\nORDER BY key\nSETTINGS index_granularity = 8192
1 1 1 -1
2 2 2 -1
CREATE TABLE default.table_with_version\n(\n `key` UInt64,\n `value` String,\n `version` UInt32,\n `sign` Int8\n)\nENGINE = VersionedCollapsingMergeTree(sign, version)\nORDER BY key\nSETTINGS index_granularity = 8192
1 1 2 1
2 2 2 -1
1 1 2 1
2 2 2 -1
3 3 65555 1
1 1 2 1
2 2 2 -1

View File

@ -0,0 +1,41 @@
DROP TABLE IF EXISTS table_with_version;
CREATE TABLE table_with_version
(
key UInt64,
value String,
version UInt8,
sign Int8
)
ENGINE VersionedCollapsingMergeTree(sign, version)
ORDER BY key;
INSERT INTO table_with_version VALUES (1, '1', 1, -1);
INSERT INTO table_with_version VALUES (2, '2', 2, -1);
SELECT * FROM table_with_version ORDER BY key;
SHOW CREATE TABLE table_with_version;
ALTER TABLE table_with_version MODIFY COLUMN version UInt32;
SELECT * FROM table_with_version ORDER BY key;
SHOW CREATE TABLE table_with_version;
INSERT INTO TABLE table_with_version VALUES(1, '1', 1, 1);
INSERT INTO TABLE table_with_version VALUES(1, '1', 2, 1);
SELECT * FROM table_with_version FINAL ORDER BY key;
INSERT INTO TABLE table_with_version VALUES(3, '3', 65555, 1);
SELECT * FROM table_with_version FINAL ORDER BY key;
INSERT INTO TABLE table_with_version VALUES(3, '3', 65555, -1);
SELECT * FROM table_with_version FINAL ORDER BY key;
ALTER TABLE table_with_version MODIFY COLUMN version String; --{serverError 524}
DROP TABLE IF EXISTS table_with_version;

View File

@ -0,0 +1,16 @@
1 1 1 -1
2 2 2 -1
CREATE TABLE default.table_with_version_replicated_1\n(\n `key` UInt64,\n `value` String,\n `version` UInt8,\n `sign` Int8\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/test_01511/t\', \'1\', sign, version)\nORDER BY key\nSETTINGS index_granularity = 8192
1 1 1 -1
2 2 2 -1
CREATE TABLE default.table_with_version_replicated_1\n(\n `key` UInt64,\n `value` String,\n `version` UInt32,\n `sign` Int8\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/test_01511/t\', \'1\', sign, version)\nORDER BY key\nSETTINGS index_granularity = 8192
1 1 2 1
2 2 2 -1
1 1 2 1
2 2 2 -1
3 3 65555 1
1 1 2 1
2 2 2 -1
CREATE TABLE default.table_with_version_replicated_2\n(\n `key` UInt64,\n `value` String,\n `version` UInt32,\n `sign` Int8\n)\nENGINE = ReplicatedVersionedCollapsingMergeTree(\'/clickhouse/test_01511/t\', \'2\', sign, version)\nORDER BY key\nSETTINGS index_granularity = 8192
1 1 2 1
2 2 2 -1

View File

@ -0,0 +1,64 @@
DROP TABLE IF EXISTS table_with_version_replicated_1;
DROP TABLE IF EXISTS table_with_version_replicated_2;
CREATE TABLE table_with_version_replicated_1
(
key UInt64,
value String,
version UInt8,
sign Int8
)
ENGINE ReplicatedVersionedCollapsingMergeTree('/clickhouse/test_01511/t', '1', sign, version)
ORDER BY key;
CREATE TABLE table_with_version_replicated_2
(
key UInt64,
value String,
version UInt8,
sign Int8
)
ENGINE ReplicatedVersionedCollapsingMergeTree('/clickhouse/test_01511/t', '2', sign, version)
ORDER BY key;
INSERT INTO table_with_version_replicated_1 VALUES (1, '1', 1, -1);
INSERT INTO table_with_version_replicated_1 VALUES (2, '2', 2, -1);
SELECT * FROM table_with_version_replicated_1 ORDER BY key;
SHOW CREATE TABLE table_with_version_replicated_1;
ALTER TABLE table_with_version_replicated_1 MODIFY COLUMN version UInt32 SETTINGS replication_alter_partitions_sync=2;
SELECT * FROM table_with_version_replicated_1 ORDER BY key;
SHOW CREATE TABLE table_with_version_replicated_1;
INSERT INTO TABLE table_with_version_replicated_1 VALUES(1, '1', 1, 1);
INSERT INTO TABLE table_with_version_replicated_1 VALUES(1, '1', 2, 1);
SELECT * FROM table_with_version_replicated_1 FINAL ORDER BY key;
INSERT INTO TABLE table_with_version_replicated_1 VALUES(3, '3', 65555, 1);
SELECT * FROM table_with_version_replicated_1 FINAL ORDER BY key;
INSERT INTO TABLE table_with_version_replicated_1 VALUES(3, '3', 65555, -1);
SYSTEM SYNC REPLICA table_with_version_replicated_2;
DETACH TABLE table_with_version_replicated_1;
DETACH TABLE table_with_version_replicated_2;
ATTACH TABLE table_with_version_replicated_2;
ATTACH TABLE table_with_version_replicated_1;
SELECT * FROM table_with_version_replicated_1 FINAL ORDER BY key;
SYSTEM SYNC REPLICA table_with_version_replicated_2;
SHOW CREATE TABLE table_with_version_replicated_2;
SELECT * FROM table_with_version_replicated_2 FINAL ORDER BY key;
DROP TABLE IF EXISTS table_with_version_replicated_1;
DROP TABLE IF EXISTS table_with_version_replicated_2;