Merge pull request #49800 from ClickHouse/fix-adding-cast

Analyzer: apply _CAST to constants only once
This commit is contained in:
Dmitry Novik 2023-05-16 17:05:02 +02:00 committed by GitHub
commit 2287dd8633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -209,15 +209,20 @@ ASTPtr FunctionNode::toASTImpl(const ConvertToASTOptions & options) const
function_ast->kind = ASTFunction::Kind::WINDOW_FUNCTION;
}
auto new_options = options;
/// To avoid surrounding constants with several internal casts.
if (function_name == "_CAST" && (*getArguments().begin())->getNodeType() == QueryTreeNodeType::CONSTANT)
new_options.add_cast_for_constants = false;
const auto & parameters = getParameters();
if (!parameters.getNodes().empty())
{
function_ast->children.push_back(parameters.toAST(options));
function_ast->children.push_back(parameters.toAST(new_options));
function_ast->parameters = function_ast->children.back();
}
const auto & arguments = getArguments();
function_ast->children.push_back(arguments.toAST(options));
function_ast->children.push_back(arguments.toAST(new_options));
function_ast->arguments = function_ast->children.back();
auto window_node = getWindowNode();
@ -226,7 +231,7 @@ ASTPtr FunctionNode::toASTImpl(const ConvertToASTOptions & options) const
if (auto * identifier_node = window_node->as<IdentifierNode>())
function_ast->window_name = identifier_node->getIdentifier().getFullName();
else
function_ast->window_definition = window_node->toAST(options);
function_ast->window_definition = window_node->toAST(new_options);
}
return function_ast;

View File

@ -112,7 +112,6 @@
02479_race_condition_between_insert_and_droppin_mv
02493_inconsistent_hex_and_binary_number
02494_optimize_group_by_function_keys_and_alias_columns
02511_complex_literals_as_aggregate_function_parameters
02521_aggregation_by_partitions
02554_fix_grouping_sets_predicate_push_down
02575_merge_prewhere_different_default_kind