mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Merge pull request #32758 from kitaisreal/sql-user-defined-functions-support-subqueries
SQLUserDefinedFunctions support subqueries
This commit is contained in:
commit
655cc20525
@ -57,9 +57,14 @@ BlockIO InterpreterCreateFunctionQuery::execute()
|
|||||||
|
|
||||||
void InterpreterCreateFunctionQuery::validateFunction(ASTPtr function, const String & name)
|
void InterpreterCreateFunctionQuery::validateFunction(ASTPtr function, const String & name)
|
||||||
{
|
{
|
||||||
const auto * args_tuple = function->as<ASTFunction>()->arguments->children.at(0)->as<ASTFunction>();
|
auto & lambda_function = function->as<ASTFunction &>();
|
||||||
|
auto & lambda_function_expression_list = lambda_function.arguments->children;
|
||||||
|
|
||||||
|
const auto & tuple_function_arguments = lambda_function_expression_list.at(0)->as<ASTFunction &>();
|
||||||
|
|
||||||
std::unordered_set<String> arguments;
|
std::unordered_set<String> arguments;
|
||||||
for (const auto & argument : args_tuple->arguments->children)
|
|
||||||
|
for (const auto & argument : tuple_function_arguments.arguments->children)
|
||||||
{
|
{
|
||||||
const auto & argument_name = argument->as<ASTIdentifier>()->name();
|
const auto & argument_name = argument->as<ASTIdentifier>()->name();
|
||||||
auto [_, inserted] = arguments.insert(argument_name);
|
auto [_, inserted] = arguments.insert(argument_name);
|
||||||
@ -67,7 +72,7 @@ void InterpreterCreateFunctionQuery::validateFunction(ASTPtr function, const Str
|
|||||||
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Identifier {} already used as function parameter", argument_name);
|
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Identifier {} already used as function parameter", argument_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTPtr function_body = function->as<ASTFunction>()->children.at(0)->children.at(1);
|
ASTPtr function_body = lambda_function_expression_list.at(1);
|
||||||
validateFunctionRecursiveness(function_body, name);
|
validateFunctionRecursiveness(function_body, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,5 +87,4 @@ void InterpreterCreateFunctionQuery::validateFunctionRecursiveness(ASTPtr node,
|
|||||||
validateFunctionRecursiveness(child, function_to_create);
|
validateFunctionRecursiveness(child, function_to_create);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
4
|
||||||
|
(0,'Value')
|
||||||
|
Value
|
@ -0,0 +1,35 @@
|
|||||||
|
-- Tags: no-parallel
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS 02148_test_function;
|
||||||
|
CREATE FUNCTION 02148_test_function AS () -> (SELECT 1);
|
||||||
|
|
||||||
|
SELECT 02148_test_function();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION 02148_test_function AS () -> (SELECT 2);
|
||||||
|
|
||||||
|
SELECT 02148_test_function();
|
||||||
|
|
||||||
|
DROP FUNCTION 02148_test_function;
|
||||||
|
|
||||||
|
CREATE FUNCTION 02148_test_function AS (x) -> (SELECT x + 1);
|
||||||
|
SELECT 02148_test_function(1);
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS 02148_test_function_nested;
|
||||||
|
CREATE FUNCTION 02148_test_function_nested AS (x) -> 02148_test_function(x + 2);
|
||||||
|
SELECT 02148_test_function_nested(1);
|
||||||
|
|
||||||
|
DROP FUNCTION 02148_test_function;
|
||||||
|
DROP FUNCTION 02148_test_function_nested;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS 02148_test_table;
|
||||||
|
CREATE TABLE 02148_test_table (id UInt64, value String) ENGINE=TinyLog;
|
||||||
|
INSERT INTO 02148_test_table VALUES (0, 'Value');
|
||||||
|
|
||||||
|
CREATE FUNCTION 02148_test_function AS () -> (SELECT * FROM 02148_test_table LIMIT 1);
|
||||||
|
SELECT 02148_test_function();
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION 02148_test_function AS () -> (SELECT value FROM 02148_test_table LIMIT 1);
|
||||||
|
SELECT 02148_test_function();
|
||||||
|
|
||||||
|
DROP FUNCTION 02148_test_function;
|
||||||
|
DROP TABLE 02148_test_table;
|
Loading…
Reference in New Issue
Block a user