From d24946f47573032486e0d382aaf958ed75e40651 Mon Sep 17 00:00:00 2001 From: hexiaoting Date: Thu, 22 Apr 2021 14:48:57 +0800 Subject: [PATCH] Fix bug when modify column without type --- src/Storages/MergeTree/MergeTreeData.cpp | 3 ++- .../01846_alter_column_without_type_bugfix.reference | 1 + .../0_stateless/01846_alter_column_without_type_bugfix.sql | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/01846_alter_column_without_type_bugfix.reference create mode 100644 tests/queries/0_stateless/01846_alter_column_without_type_bugfix.sql diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index f28d87bb9be..3649065e3c2 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -1578,7 +1578,8 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context const IDataType * new_type = command.data_type.get(); const IDataType * old_type = old_types[command.column_name]; - checkVersionColumnTypesConversion(old_type, new_type, command.column_name); + if (new_type) + checkVersionColumnTypesConversion(old_type, new_type, command.column_name); /// No other checks required continue; diff --git a/tests/queries/0_stateless/01846_alter_column_without_type_bugfix.reference b/tests/queries/0_stateless/01846_alter_column_without_type_bugfix.reference new file mode 100644 index 00000000000..849ac80b365 --- /dev/null +++ b/tests/queries/0_stateless/01846_alter_column_without_type_bugfix.reference @@ -0,0 +1 @@ +CREATE TABLE default.alter_test\n(\n `a` Int32,\n `b` DateTime DEFAULT now() + 1\n)\nENGINE = ReplacingMergeTree(b)\nORDER BY a\nSETTINGS index_granularity = 8192 diff --git a/tests/queries/0_stateless/01846_alter_column_without_type_bugfix.sql b/tests/queries/0_stateless/01846_alter_column_without_type_bugfix.sql new file mode 100644 index 00000000000..5df8daedbe6 --- /dev/null +++ b/tests/queries/0_stateless/01846_alter_column_without_type_bugfix.sql @@ -0,0 +1,6 @@ +DROP TABLE IF EXISTS alter_test; +CREATE TABLE alter_test (a Int32, b DateTime) ENGINE = ReplacingMergeTree(b) ORDER BY a; +ALTER TABLE alter_test MODIFY COLUMN `b` DateTime DEFAULT now(); +ALTER TABLE alter_test MODIFY COLUMN `b` DEFAULT now() + 1; +SHOW CREATE TABLE alter_test; +DROP TABLE alter_test;