Support custom 'order by' expression for system log tables

This commit is contained in:
helifu 2023-05-11 16:02:15 +08:00
parent 0e2156c776
commit 90a6437716

View File

@ -152,20 +152,34 @@ std::shared_ptr<TSystemLog> createSystemLog(
}
else
{
String partition_by = config.getString(config_prefix + ".partition_by", "toYYYYMM(event_date)");
/// ENGINE expr is necessary.
engine = "ENGINE = MergeTree";
/// PARTITION expr is not necessary.
String partition_by = config.getString(config_prefix + ".partition_by", "toYYYYMM(event_date)");
if (!partition_by.empty())
{
engine += " PARTITION BY (" + partition_by + ")";
}
/// TTL expr is not necessary.
String ttl = config.getString(config_prefix + ".ttl", "");
if (!ttl.empty())
{
engine += " TTL " + ttl;
}
engine += " ORDER BY ";
engine += TSystemLog::getDefaultOrderBy();
/// ORDER BY expr is necessary.
String order_by = config.getString(config_prefix + ".order_by", TSystemLog::getDefaultOrderBy());
engine += " ORDER BY (" + order_by + ")";
/// STORAGE POLICY expr is not necessary.
String storage_policy = config.getString(config_prefix + ".storage_policy", "");
if (!storage_policy.empty())
{
engine += " SETTINGS storage_policy = " + quoteString(storage_policy);
}
}
/// Validate engine definition syntax to prevent some configuration errors.
ParserStorageWithComment storage_parser;