Merge pull request #57102 from ClickHouse/vdimir/analyzer_to_ast_crash

Fix FunctionNode::toASTImpl
This commit is contained in:
Alexey Milovidov 2023-11-23 23:12:30 +01:00 committed by GitHub
commit f138ddbdfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -209,15 +209,17 @@ ASTPtr FunctionNode::toASTImpl(const ConvertToASTOptions & options) const
function_ast->kind = ASTFunction::Kind::WINDOW_FUNCTION;
}
const auto & arguments = getArguments();
auto new_options = options;
const auto & argument_nodes = arguments.getNodes();
/// To avoid surrounding constants with several internal casts.
if (function_name == "_CAST" && (*getArguments().begin())->getNodeType() == QueryTreeNodeType::CONSTANT)
if (function_name == "_CAST" && !argument_nodes.empty() && argument_nodes[0]->getNodeType() == QueryTreeNodeType::CONSTANT)
new_options.add_cast_for_constants = false;
/// Avoid cast for `IN tuple(...)` expression.
/// Tuples colud be quite big, and adding a type may significantly increase query size.
/// It should be safe because set type for `column IN tuple` is deduced from `column` type.
if (isNameOfInFunction(function_name) && (*(++getArguments().begin()))->getNodeType() == QueryTreeNodeType::CONSTANT)
if (isNameOfInFunction(function_name) && argument_nodes.size() > 1 && argument_nodes[1]->getNodeType() == QueryTreeNodeType::CONSTANT)
new_options.add_cast_for_constants = false;
const auto & parameters = getParameters();
@ -227,7 +229,6 @@ ASTPtr FunctionNode::toASTImpl(const ConvertToASTOptions & options) const
function_ast->parameters = function_ast->children.back();
}
const auto & arguments = getArguments();
function_ast->children.push_back(arguments.toAST(new_options));
function_ast->arguments = function_ast->children.back();

View File

@ -0,0 +1,5 @@
WITH
x AS (SELECT in((SELECT * FROM y))),
y AS (SELECT 1)
SELECT * FROM x; -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }