Merge pull request #17438 from spongedu/add_ttl_option_for_syslog

Support configure System log table`s ttl in config.xml
This commit is contained in:
Alexander Kuzmenkov 2020-12-01 16:03:06 +03:00 committed by GitHub
commit 12d1fa6456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -581,7 +581,7 @@
<database>system</database>
<table>query_log</table>
<!--
PARTITION BY expr https://clickhouse.yandex/docs/en/table_engines/custom_partitioning_key/
PARTITION BY expr: https://clickhouse.yandex/docs/en/table_engines/custom_partitioning_key/
Example:
event_date
toMonday(event_date)
@ -589,6 +589,15 @@
toStartOfHour(event_time)
-->
<partition_by>toYYYYMM(event_date)</partition_by>
<!--
Table TTL specification: https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/mergetree/#mergetree-table-ttl
Example:
event_date + INTERVAL 1 WEEK
event_date + INTERVAL 7 DAY DELETE
event_date + INTERVAL 2 WEEK TO DISK 'bbb'
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
-->
<!-- Instead of partition_by, you can provide full engine expression (starting with ENGINE = ) with parameters,
Example: <engine>ENGINE = MergeTree PARTITION BY toYYYYMM(event_date) ORDER BY (event_date, event_time) SETTINGS index_granularity = 1024</engine>

View File

@ -57,6 +57,10 @@ std::shared_ptr<TSystemLog> createSystemLog(
throw Exception("If 'engine' is specified for system table, "
"PARTITION BY parameters should be specified directly inside 'engine' and 'partition_by' setting doesn't make sense",
ErrorCodes::BAD_ARGUMENTS);
if (config.has(config_prefix + ".ttl"))
throw Exception("If 'engine' is specified for system table, "
"TTL parameters should be specified directly inside 'engine' and 'ttl' setting doesn't make sense",
ErrorCodes::BAD_ARGUMENTS);
engine = config.getString(config_prefix + ".engine");
}
else
@ -65,6 +69,9 @@ std::shared_ptr<TSystemLog> createSystemLog(
engine = "ENGINE = MergeTree";
if (!partition_by.empty())
engine += " PARTITION BY (" + partition_by + ")";
String ttl = config.getString(config_prefix + ".ttl", "");
if (!ttl.empty())
engine += " TTL " + ttl;
engine += " ORDER BY (event_date, event_time)";
}