Skip to content

Commit

Permalink
Merge pull request #48115 from save-my-heart/throw_non_parametric_fun…
Browse files Browse the repository at this point in the history
…ction

throw exception while non-parametric functions having parameters
  • Loading branch information
Avogar committed Apr 4, 2023
2 parents 3557232 + f4b884a commit 5f930ae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Functions/UserDefined/UserDefinedSQLFunctionVisitor.cpp
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
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.
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
@@ -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;

0 comments on commit 5f930ae

Please sign in to comment.