Skip to content

Commit

Permalink
Ignore per-column TTL in CREATE TABLE AS if new table engine does not…
Browse files Browse the repository at this point in the history
… support it

Follow-up for: ClickHouse#6968
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
  • Loading branch information
azat authored and liangjiabiao committed Mar 1, 2022
1 parent 537dca6 commit b5201d9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Interpreters/InterpreterCreateQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ InterpreterCreateQuery::TableProperties InterpreterCreateQuery::getTableProperti
properties.indices = as_storage_metadata->getSecondaryIndices();
properties.projections = as_storage_metadata->getProjections().clone();
}
else
{
/// Only MergeTree support TTL
properties.columns.resetColumnTTLs();
}

properties.constraints = as_storage_metadata->getConstraints();
}
Expand Down
16 changes: 16 additions & 0 deletions src/Storages/ColumnsDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,22 @@ ColumnsDescription::ColumnTTLs ColumnsDescription::getColumnTTLs() const
return ret;
}

void ColumnsDescription::resetColumnTTLs()
{
std::vector<ColumnDescription> old_columns;
old_columns.reserve(columns.size());
for (const auto & col : columns)
old_columns.emplace_back(col);

columns.clear();

for (auto & col : old_columns)
{
col.ttl.reset();
add(col);
}
}


String ColumnsDescription::toString() const
{
Expand Down
1 change: 1 addition & 0 deletions src/Storages/ColumnsDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class ColumnsDescription

using ColumnTTLs = std::unordered_map<String, ASTPtr>;
ColumnTTLs getColumnTTLs() const;
void resetColumnTTLs();

bool has(const String & column_name) const;
bool hasNested(const String & column_name) const;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CREATE TABLE default.data_02230_ttl
(
`date` Date,
`key` Int32
)
ENGINE = MergeTree
ORDER BY key
TTL date + 14
SETTINGS index_granularity = 8192
CREATE TABLE default.null_02230_ttl
(
`date` Date,
`key` Int32
)
ENGINE = Null
CREATE TABLE default.data_02230_column_ttl
(
`date` Date,
`value` Int32 TTL date + 7,
`key` Int32
)
ENGINE = MergeTree
ORDER BY key
TTL date + 14
SETTINGS index_granularity = 8192
CREATE TABLE default.null_02230_column_ttl
(
`date` Date,
`value` Int32,
`key` Int32
)
ENGINE = Null
18 changes: 18 additions & 0 deletions tests/queries/0_stateless/02230_create_table_as_ignore_ttl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
drop table if exists data_02230_ttl;
drop table if exists null_02230_ttl;
create table data_02230_ttl (date Date, key Int) Engine=MergeTree() order by key TTL date + 14;
show create data_02230_ttl format TSVRaw;
create table null_02230_ttl engine=Null() as data_02230_ttl;
show create null_02230_ttl format TSVRaw;
drop table data_02230_ttl;
drop table null_02230_ttl;

drop table if exists data_02230_column_ttl;
drop table if exists null_02230_column_ttl;
create table data_02230_column_ttl (date Date, value Int TTL date + 7, key Int) Engine=MergeTree() order by key TTL date + 14;
show create data_02230_column_ttl format TSVRaw;
create table null_02230_column_ttl engine=Null() as data_02230_column_ttl;
-- check that order of columns is the same
show create null_02230_column_ttl format TSVRaw;
drop table data_02230_column_ttl;
drop table null_02230_column_ttl;

0 comments on commit b5201d9

Please sign in to comment.