From 0e4871eec2edf603b5f8eb06c4e1ae1cf9083b35 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Thu, 9 Jul 2020 02:05:56 +0300 Subject: [PATCH] fix TTL after renaming column --- src/Storages/TTLDescription.cpp | 23 ++++++++++++++++ src/Storages/TTLDescription.h | 4 +++ .../01378_alter_rename_with_ttl.reference | 3 +++ .../01378_alter_rename_with_ttl.sql | 26 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 tests/queries/0_stateless/01378_alter_rename_with_ttl.reference create mode 100644 tests/queries/0_stateless/01378_alter_rename_with_ttl.sql diff --git a/src/Storages/TTLDescription.cpp b/src/Storages/TTLDescription.cpp index 6e0d323e8a..2c29958250 100644 --- a/src/Storages/TTLDescription.cpp +++ b/src/Storages/TTLDescription.cpp @@ -272,6 +272,29 @@ TTLDescription TTLDescription::getTTLFromAST( } +TTLTableDescription::TTLTableDescription(const TTLTableDescription & other) + : definition_ast(other.definition_ast ? other.definition_ast->clone() : nullptr) + , rows_ttl(other.rows_ttl) + , move_ttl(other.move_ttl) +{ +} + +TTLTableDescription & TTLTableDescription::operator=(const TTLTableDescription & other) +{ + if (&other == this) + return *this; + + if (other.definition_ast) + definition_ast = other.definition_ast->clone(); + else + definition_ast.reset(); + + rows_ttl = other.rows_ttl; + move_ttl = other.move_ttl; + + return *this; +} + TTLTableDescription TTLTableDescription::getTTLForTableFromAST( const ASTPtr & definition_ast, const ColumnsDescription & columns, diff --git a/src/Storages/TTLDescription.h b/src/Storages/TTLDescription.h index 906cfb0e67..ab93967f11 100644 --- a/src/Storages/TTLDescription.h +++ b/src/Storages/TTLDescription.h @@ -102,6 +102,10 @@ struct TTLTableDescription /// Moving data TTL (to other disks or volumes) TTLDescriptions move_ttl; + TTLTableDescription() = default; + TTLTableDescription(const TTLTableDescription & other); + TTLTableDescription & operator=(const TTLTableDescription & other); + static TTLTableDescription getTTLForTableFromAST( const ASTPtr & definition_ast, const ColumnsDescription & columns, const Context & context, const KeyDescription & primary_key); }; diff --git a/tests/queries/0_stateless/01378_alter_rename_with_ttl.reference b/tests/queries/0_stateless/01378_alter_rename_with_ttl.reference new file mode 100644 index 0000000000..bf8f7658af --- /dev/null +++ b/tests/queries/0_stateless/01378_alter_rename_with_ttl.reference @@ -0,0 +1,3 @@ +9 +9 +0 diff --git a/tests/queries/0_stateless/01378_alter_rename_with_ttl.sql b/tests/queries/0_stateless/01378_alter_rename_with_ttl.sql new file mode 100644 index 0000000000..98f2953838 --- /dev/null +++ b/tests/queries/0_stateless/01378_alter_rename_with_ttl.sql @@ -0,0 +1,26 @@ +DROP TABLE IF EXISTS table_rename_with_ttl; + +CREATE TABLE table_rename_with_ttl +( + date1 Date, + value1 String +) +ENGINE = ReplicatedMergeTree('/clickhouse/test/table_rename_with_ttl', '1') +ORDER BY tuple(); + +INSERT INTO table_rename_with_ttl SELECT toDate('2018-10-01') + number % 3, toString(number) from numbers(9); + +SELECT count() FROM table_rename_with_ttl; + +SET materialize_ttl_after_modify = 0; +ALTER TABLE table_rename_with_ttl MODIFY TTL date1 + INTERVAL 1 MONTH; + +SELECT count() FROM table_rename_with_ttl; + +ALTER TABLE table_rename_with_ttl RENAME COLUMN date1 TO renamed_date1; + +ALTER TABLE table_rename_with_ttl materialize TTL settings mutations_sync=2; + +SELECT count() FROM table_rename_with_ttl; + +DROP TABLE IF EXISTS table_rename_with_ttl; -- GitLab