Merge pull request #12304 from CurtizJ/fix-ttl-rename

Fix TTL after renaming column.
This commit is contained in:
alesapin 2020-07-09 13:06:27 +03:00 committed by GitHub
commit 47f05dcadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 0 deletions

View File

@ -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,

View File

@ -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);
};

View File

@ -0,0 +1,3 @@
9
9
0

View File

@ -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;