mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Merge pull request #51964 from ClickHouse/allow-parametric-udfs
Allow parametric UDFs
This commit is contained in:
commit
58ee566278
@ -116,7 +116,6 @@ namespace ErrorCodes
|
|||||||
extern const int UNKNOWN_TABLE;
|
extern const int UNKNOWN_TABLE;
|
||||||
extern const int ILLEGAL_COLUMN;
|
extern const int ILLEGAL_COLUMN;
|
||||||
extern const int NUMBER_OF_COLUMNS_DOESNT_MATCH;
|
extern const int NUMBER_OF_COLUMNS_DOESNT_MATCH;
|
||||||
extern const int FUNCTION_CANNOT_HAVE_PARAMETERS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Query analyzer implementation overview. Please check documentation in QueryAnalysisPass.h first.
|
/** Query analyzer implementation overview. Please check documentation in QueryAnalysisPass.h first.
|
||||||
@ -4897,11 +4896,6 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
|
|||||||
lambda_expression_untyped->formatASTForErrorMessage(),
|
lambda_expression_untyped->formatASTForErrorMessage(),
|
||||||
scope.scope_node->formatASTForErrorMessage());
|
scope.scope_node->formatASTForErrorMessage());
|
||||||
|
|
||||||
if (!parameters.empty())
|
|
||||||
{
|
|
||||||
throw Exception(ErrorCodes::FUNCTION_CANNOT_HAVE_PARAMETERS, "Function {} is not parametric", function_node.formatASTForErrorMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto lambda_expression_clone = lambda_expression_untyped->clone();
|
auto lambda_expression_clone = lambda_expression_untyped->clone();
|
||||||
|
|
||||||
IdentifierResolveScope lambda_scope(lambda_expression_clone, &scope /*parent_scope*/);
|
IdentifierResolveScope lambda_scope(lambda_expression_clone, &scope /*parent_scope*/);
|
||||||
@ -5018,12 +5012,9 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
|
|||||||
}
|
}
|
||||||
|
|
||||||
FunctionOverloadResolverPtr function = UserDefinedExecutableFunctionFactory::instance().tryGet(function_name, scope.context, parameters);
|
FunctionOverloadResolverPtr function = UserDefinedExecutableFunctionFactory::instance().tryGet(function_name, scope.context, parameters);
|
||||||
bool is_executable_udf = false;
|
|
||||||
|
|
||||||
if (!function)
|
if (!function)
|
||||||
function = FunctionFactory::instance().tryGet(function_name, scope.context);
|
function = FunctionFactory::instance().tryGet(function_name, scope.context);
|
||||||
else
|
|
||||||
is_executable_udf = true;
|
|
||||||
|
|
||||||
if (!function)
|
if (!function)
|
||||||
{
|
{
|
||||||
@ -5074,12 +5065,6 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
|
|||||||
return result_projection_names;
|
return result_projection_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executable UDFs may have parameters. They are checked in UserDefinedExecutableFunctionFactory.
|
|
||||||
if (!parameters.empty() && !is_executable_udf)
|
|
||||||
{
|
|
||||||
throw Exception(ErrorCodes::FUNCTION_CANNOT_HAVE_PARAMETERS, "Function {} is not parametric", function_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** For lambda arguments we need to initialize lambda argument types DataTypeFunction using `getLambdaArgumentTypes` function.
|
/** For lambda arguments we need to initialize lambda argument types DataTypeFunction using `getLambdaArgumentTypes` function.
|
||||||
* Then each lambda arguments are initialized with columns, where column source is lambda.
|
* Then each lambda arguments are initialized with columns, where column source is lambda.
|
||||||
* This information is important for later steps of query processing.
|
* This information is important for later steps of query processing.
|
||||||
|
@ -20,7 +20,6 @@ namespace DB
|
|||||||
namespace ErrorCodes
|
namespace ErrorCodes
|
||||||
{
|
{
|
||||||
extern const int UNSUPPORTED_METHOD;
|
extern const int UNSUPPORTED_METHOD;
|
||||||
extern const int FUNCTION_CANNOT_HAVE_PARAMETERS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast)
|
void UserDefinedSQLFunctionVisitor::visit(ASTPtr & ast)
|
||||||
@ -139,12 +138,6 @@ ASTPtr UserDefinedSQLFunctionVisitor::tryToReplaceFunction(const ASTFunction & f
|
|||||||
if (!user_defined_function)
|
if (!user_defined_function)
|
||||||
return nullptr;
|
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>();
|
const auto & function_arguments_list = function.children.at(0)->as<ASTExpressionList>();
|
||||||
auto & function_arguments = function_arguments_list->children;
|
auto & function_arguments = function_arguments_list->children;
|
||||||
|
|
||||||
|
@ -78,7 +78,6 @@ namespace ErrorCodes
|
|||||||
extern const int LOGICAL_ERROR;
|
extern const int LOGICAL_ERROR;
|
||||||
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
|
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
|
||||||
extern const int TOO_MANY_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)
|
static NamesAndTypesList::iterator findColumn(const String & name, NamesAndTypesList & cols)
|
||||||
@ -1106,12 +1105,6 @@ 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;
|
Names argument_names;
|
||||||
DataTypes argument_types;
|
DataTypes argument_types;
|
||||||
bool arguments_present = true;
|
bool arguments_present = true;
|
||||||
|
@ -111,6 +111,7 @@
|
|||||||
00917_multiple_joins_denny_crane
|
00917_multiple_joins_denny_crane
|
||||||
00725_join_on_bug_1
|
00725_join_on_bug_1
|
||||||
00636_partition_key_parts_pruning
|
00636_partition_key_parts_pruning
|
||||||
|
00261_storage_aliases_and_array_join
|
||||||
01825_type_json_multiple_files
|
01825_type_json_multiple_files
|
||||||
01281_group_by_limit_memory_tracking
|
01281_group_by_limit_memory_tracking
|
||||||
02723_zookeeper_name
|
02723_zookeeper_name
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
-- 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;
|
|
Loading…
Reference in New Issue
Block a user