diff --git a/src/Storages/System/StorageSystemPartsColumns.cpp b/src/Storages/System/StorageSystemPartsColumns.cpp index f34b0e0cfda..08cde25584b 100644 --- a/src/Storages/System/StorageSystemPartsColumns.cpp +++ b/src/Storages/System/StorageSystemPartsColumns.cpp @@ -65,6 +65,8 @@ StorageSystemPartsColumns::StorageSystemPartsColumns(const StorageID & table_id_ {"column_data_uncompressed_bytes", std::make_shared(), "Total size of the decompressed data in the column, in bytes."}, {"column_marks_bytes", std::make_shared(), "The size of the marks for column, in bytes."}, {"column_modification_time", std::make_shared(std::make_shared()), "The last time the column was modified."}, + {"column_ttl_min", std::make_shared(std::make_shared()), "The minimum value of the calculated TTL expression of the column."}, + {"column_ttl_max", std::make_shared(std::make_shared()), "The maximum value of the calculated TTL expression of the column."}, {"serialization_kind", std::make_shared(), "Kind of serialization of a column"}, {"substreams", std::make_shared(std::make_shared()), "Names of substreams to which column is serialized"}, @@ -250,6 +252,21 @@ void StorageSystemPartsColumns::processNextStorage( else columns[res_index++]->insertDefault(); } + bool column_has_ttl = part->ttl_infos.columns_ttl.contains(column.name); + if (columns_mask[src_index++]) + { + if (column_has_ttl) + columns[res_index++]->insert(static_cast(part->ttl_infos.columns_ttl[column.name].min)); + else + columns[res_index++]->insertDefault(); + } + if (columns_mask[src_index++]) + { + if (column_has_ttl) + columns[res_index++]->insert(static_cast(part->ttl_infos.columns_ttl[column.name].max)); + else + columns[res_index++]->insertDefault(); + } auto serialization = part->getSerialization(column.name); if (columns_mask[src_index++]) diff --git a/tests/queries/0_stateless/02117_show_create_table_system.reference b/tests/queries/0_stateless/02117_show_create_table_system.reference index bdd0da7d166..d625feb94d3 100644 --- a/tests/queries/0_stateless/02117_show_create_table_system.reference +++ b/tests/queries/0_stateless/02117_show_create_table_system.reference @@ -565,6 +565,8 @@ CREATE TABLE system.parts_columns `column_data_uncompressed_bytes` UInt64, `column_marks_bytes` UInt64, `column_modification_time` Nullable(DateTime), + `column_ttl_min` Nullable(DateTime), + `column_ttl_max` Nullable(DateTime), `serialization_kind` String, `substreams` Array(String), `filenames` Array(String), diff --git a/tests/queries/0_stateless/03143_ttl_in_system_parts_columns_table.reference b/tests/queries/0_stateless/03143_ttl_in_system_parts_columns_table.reference new file mode 100644 index 00000000000..f358d128f8a --- /dev/null +++ b/tests/queries/0_stateless/03143_ttl_in_system_parts_columns_table.reference @@ -0,0 +1,4 @@ +all_1_1_0 timestamp DateTime \N \N +all_1_1_0 x UInt32 2100-02-01 00:00:00 2100-02-01 00:00:00 +all_1_1_0 y String 2100-01-02 00:00:00 2100-01-02 00:00:00 +all_1_1_0 z String \N \N diff --git a/tests/queries/0_stateless/03143_ttl_in_system_parts_columns_table.sql b/tests/queries/0_stateless/03143_ttl_in_system_parts_columns_table.sql new file mode 100644 index 00000000000..50adab2e9b0 --- /dev/null +++ b/tests/queries/0_stateless/03143_ttl_in_system_parts_columns_table.sql @@ -0,0 +1,25 @@ +DROP TABLE IF EXISTS test_03143; + +CREATE TABLE test_03143 ( + timestamp DateTime, + x UInt32 TTL timestamp + INTERVAL 1 MONTH, + y String TTL timestamp + INTERVAL 1 DAY, + z String +) +ENGINE = MergeTree +ORDER BY tuple(); + + +INSERT INTO test_03143 VALUES ('2100-01-01', 123, 'Hello, world!', 'xxx yyy'); + +SELECT + name, + column, + type, + column_ttl_min, + column_ttl_max +FROM system.parts_columns +WHERE table = 'test_03143' and database = currentDatabase() +ORDER BY name, column; + +DROP TABLE IF EXISTS test_03143;