SQLUserDefinedFunctions composition fix

This commit is contained in:
Maksim Kita 2021-10-21 10:08:08 +03:00
parent 4ad679946b
commit 650a79a907
4 changed files with 24 additions and 3 deletions

View File

@ -18,7 +18,7 @@ namespace ErrorCodes
extern const int UNSUPPORTED_METHOD;
}
void UserDefinedSQLFunctionMatcher::visit(ASTPtr & ast, Data &)
void UserDefinedSQLFunctionMatcher::visit(ASTPtr & ast, Data & data)
{
auto * function = ast->as<ASTFunction>();
if (!function)
@ -27,7 +27,10 @@ void UserDefinedSQLFunctionMatcher::visit(ASTPtr & ast, Data &)
auto result = tryToReplaceFunction(*function);
if (result)
{
ast = result;
visit(ast, data);
}
}
bool UserDefinedSQLFunctionMatcher::needChildVisit(const ASTPtr &, const ASTPtr &)

View File

@ -440,6 +440,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
if (!written && 0 == strcmp(name.c_str(), "lambda"))
{
/// Special case: zero elements tuple in lhs of lambda is printed as ().
/// Special case: one-element tuple in lhs of lambda is printed as its element.
if (frame.need_parens)
@ -449,9 +450,12 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
if (first_arg_func
&& first_arg_func->name == "tuple"
&& first_arg_func->arguments
&& first_arg_func->arguments->children.size() == 1)
&& (first_arg_func->arguments->children.size() == 1 || first_arg_func->arguments->children.size() == 0))
{
if (first_arg_func->arguments->children.size() == 1)
first_arg_func->arguments->children[0]->formatImpl(settings, state, nested_need_parens);
else
settings.ostr << "()";
}
else
arguments->children[0]->formatImpl(settings, state, nested_need_parens);

View File

@ -0,0 +1,12 @@
-- Tags: no-parallel
CREATE FUNCTION 02103_test_function AS x -> x + 1;
CREATE FUNCTION 02103_test_function_with_nested_function_empty_args AS () -> 02103_test_function(1);
CREATE FUNCTION 02103_test_function_with_nested_function_arg AS (x) -> 02103_test_function(x);
SELECT 02103_test_function_with_nested_function_empty_args();
SELECT 02103_test_function_with_nested_function_arg(1);
DROP FUNCTION 02103_test_function_with_nested_function_empty_args;
DROP FUNCTION 02103_test_function_with_nested_function_arg;
DROP FUNCTION 02103_test_function;