mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fix remove TTL for column
This commit is contained in:
parent
37363ae89d
commit
2a4a6b22b1
@ -793,6 +793,7 @@ void AlterCommands::apply(StorageInMemoryMetadata & metadata, const Context & co
|
||||
throw DB::Exception("Alter commands is not prepared. Cannot apply. It's a bug", ErrorCodes::LOGICAL_ERROR);
|
||||
|
||||
auto metadata_copy = metadata;
|
||||
|
||||
for (const AlterCommand & command : *this)
|
||||
if (!command.ignore)
|
||||
command.apply(metadata_copy, context);
|
||||
@ -823,6 +824,7 @@ void AlterCommands::apply(StorageInMemoryMetadata & metadata, const Context & co
|
||||
|
||||
/// Changes in columns may lead to changes in TTL expressions.
|
||||
auto column_ttl_asts = metadata_copy.columns.getColumnTTLs();
|
||||
metadata_copy.column_ttls_by_name.clear();
|
||||
for (const auto & [name, ast] : column_ttl_asts)
|
||||
{
|
||||
auto new_ttl_entry = TTLDescription::getTTLFromAST(ast, metadata_copy.columns, context, metadata_copy.primary_key);
|
||||
@ -830,7 +832,7 @@ void AlterCommands::apply(StorageInMemoryMetadata & metadata, const Context & co
|
||||
}
|
||||
|
||||
if (metadata_copy.table_ttl.definition_ast != nullptr)
|
||||
metadata.table_ttl = TTLTableDescription::getTTLForTableFromAST(
|
||||
metadata_copy.table_ttl = TTLTableDescription::getTTLForTableFromAST(
|
||||
metadata_copy.table_ttl.definition_ast, metadata_copy.columns, context, metadata_copy.primary_key);
|
||||
|
||||
metadata = std::move(metadata_copy);
|
||||
|
@ -0,0 +1,6 @@
|
||||
1 32
|
||||
2 0
|
||||
CREATE TABLE default.table_with_column_ttl\n(\n `EventTime` DateTime,\n `UserID` UInt64,\n `Age` UInt8\n)\nENGINE = MergeTree\nORDER BY tuple()\nSETTINGS index_granularity = 8192
|
||||
1 32
|
||||
2 0
|
||||
3 27
|
29
tests/queries/0_stateless/01603_remove_column_ttl.sql
Normal file
29
tests/queries/0_stateless/01603_remove_column_ttl.sql
Normal file
@ -0,0 +1,29 @@
|
||||
DROP TABLE IF EXISTS table_with_column_ttl;
|
||||
CREATE TABLE table_with_column_ttl
|
||||
(
|
||||
EventTime DateTime,
|
||||
UserID UInt64,
|
||||
Age UInt8 TTL EventTime + INTERVAL 3 MONTH
|
||||
)
|
||||
ENGINE MergeTree()
|
||||
ORDER BY tuple();
|
||||
|
||||
INSERT INTO table_with_column_ttl VALUES (now(), 1, 32);
|
||||
|
||||
INSERT INTO table_with_column_ttl VALUES (now() - INTERVAL 4 MONTH, 2, 45);
|
||||
|
||||
OPTIMIZE TABLE table_with_column_ttl FINAL;
|
||||
|
||||
SELECT UserID, Age FROM table_with_column_ttl ORDER BY UserID;
|
||||
|
||||
ALTER TABLE table_with_column_ttl MODIFY COLUMN Age REMOVE TTL;
|
||||
|
||||
SHOW CREATE TABLE table_with_column_ttl;
|
||||
|
||||
INSERT INTO table_with_column_ttl VALUES (now() - INTERVAL 10 MONTH, 3, 27);
|
||||
|
||||
OPTIMIZE TABLE table_with_column_ttl FINAL;
|
||||
|
||||
SELECT UserID, Age FROM table_with_column_ttl ORDER BY UserID;
|
||||
|
||||
DROP TABLE table_with_column_ttl;
|
Loading…
Reference in New Issue
Block a user