Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw exception while non-parametric functions having parameters #48115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace DB
namespace ErrorCodes
{
extern const int UNSUPPORTED_METHOD;
extern const int FUNCTION_CANNOT_HAVE_PARAMETERS;
}

void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast)
Expand Down Expand Up @@ -132,6 +133,12 @@ ASTPtr UserDefinedSQLFunctionVisitor::tryToReplaceFunction(const ASTFunction & f
if (!user_defined_function)
return nullptr;

/// All UDFs are not parametric for now.
if (function.parameters)
{
throw Exception(ErrorCodes::FUNCTION_CANNOT_HAVE_PARAMETERS, "Function {} is not parametric", function.name);
}

const auto & function_arguments_list = function.children.at(0)->as<ASTExpressionList>();
auto & function_arguments = function_arguments_list->children;

Expand Down
7 changes: 7 additions & 0 deletions src/Interpreters/ActionsVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR;
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
extern const int TOO_MANY_ARGUMENTS_FOR_FUNCTION;
extern const int FUNCTION_CANNOT_HAVE_PARAMETERS;
}

static NamesAndTypesList::iterator findColumn(const String & name, NamesAndTypesList & cols)
Expand Down Expand Up @@ -1109,6 +1110,12 @@ void ActionsMatcher::visit(const ASTFunction & node, const ASTPtr & ast, Data &
}
}

/// Normal functions are not parametric for now.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if is not correct because executable UDF can have parameters. See #38142, #37929 and #30957.

if (node.parameters)
{
throw Exception(ErrorCodes::FUNCTION_CANNOT_HAVE_PARAMETERS, "Function {} is not parametric", node.name);
}

Names argument_names;
DataTypes argument_types;
bool arguments_present = true;
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions tests/queries/0_stateless/02701_non_parametric_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Tags: no-parallel

SELECT * FROM system.numbers WHERE number > toUInt64(10)(number) LIMIT 10; -- { serverError 309 }

CREATE FUNCTION IF NOT EXISTS sum_udf as (x, y) -> (x + y);

SELECT sum_udf(1)(1, 2); -- { serverError 309 }

DROP FUNCTION IF EXISTS sum_udf;