Merge pull request #65110 from ClickHouse/analyzer-fix-agg-name-rewriting

Analyzer: Fix aggregate function name rewriting
This commit is contained in:
Dmitry Novik 2024-06-18 07:14:00 +00:00 committed by GitHub
commit 2d051f20b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -985,15 +985,15 @@ std::string QueryAnalyzer::rewriteAggregateFunctionNameIfNeeded(
{ {
result_aggregate_function_name = settings.count_distinct_implementation; result_aggregate_function_name = settings.count_distinct_implementation;
} }
else if (aggregate_function_name_lowercase == "countdistinctif" || aggregate_function_name_lowercase == "countifdistinct") else if (aggregate_function_name_lowercase == "countifdistinct" ||
(settings.rewrite_count_distinct_if_with_count_distinct_implementation && aggregate_function_name_lowercase == "countdistinctif"))
{ {
result_aggregate_function_name = settings.count_distinct_implementation; result_aggregate_function_name = settings.count_distinct_implementation;
result_aggregate_function_name += "If"; result_aggregate_function_name += "If";
} }
else if (aggregate_function_name_lowercase.ends_with("ifdistinct"))
/// Replace aggregateFunctionIfDistinct into aggregateFunctionDistinctIf to make execution more optimal
if (result_aggregate_function_name.ends_with("ifdistinct"))
{ {
/// Replace aggregateFunctionIfDistinct into aggregateFunctionDistinctIf to make execution more optimal
size_t prefix_length = result_aggregate_function_name.size() - strlen("ifdistinct"); size_t prefix_length = result_aggregate_function_name.size() - strlen("ifdistinct");
result_aggregate_function_name = result_aggregate_function_name.substr(0, prefix_length) + "DistinctIf"; result_aggregate_function_name = result_aggregate_function_name.substr(0, prefix_length) + "DistinctIf";
} }