This commit is contained in:
Nikolay Degterinsky 2023-04-21 17:19:12 +00:00
parent 10362c28bf
commit 7f9ddcf2ea
2 changed files with 13 additions and 5 deletions

View File

@ -26,6 +26,7 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR; extern const int LOGICAL_ERROR;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int BAD_ARGUMENTS; extern const int BAD_ARGUMENTS;
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
} }
std::vector<size_t> TableFunctionExecutable::skipAnalysisForArguments(const QueryTreeNodePtr & query_node_table_function, ContextPtr) const std::vector<size_t> TableFunctionExecutable::skipAnalysisForArguments(const QueryTreeNodePtr & query_node_table_function, ContextPtr) const
@ -61,10 +62,17 @@ void TableFunctionExecutable::parseArguments(const ASTPtr & ast_function, Contex
"Table function '{}' requires minimum 3 arguments: script_name, format, structure, [input_query...]", "Table function '{}' requires minimum 3 arguments: script_name, format, structure, [input_query...]",
getName()); getName());
if (args[2]->as<ASTSetQuery>()) auto check_argument = [&](size_t i, const std::string & argument_name)
throw Exception(ErrorCodes::BAD_ARGUMENTS, {
"Table function '{}' requires 3 mandatory arguments: script_name, format, structure", if (!args[i]->as<ASTIdentifier>() && !args[i]->as<ASTLiteral>() && !args[i]->as<ASTQueryParameter>())
getName()); throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Illegal type of argument '{}' for table function '{}': must be an identifier or string literal",
argument_name, getName());
};
check_argument(0, "script_name");
check_argument(1, "format");
check_argument(2, "structure");
for (size_t i = 0; i <= 2; ++i) for (size_t i = 0; i <= 2; ++i)
args[i] = evaluateConstantExpressionOrIdentifierAsLiteral(args[i], context); args[i] = evaluateConstantExpressionOrIdentifierAsLiteral(args[i], context);

View File

@ -5,5 +5,5 @@ SELECT '--------------------';
EXPLAIN SYNTAX SELECT * from executable('', 'JSON', 'data String', SETTINGS max_command_execution_time=100, command_read_timeout=1); EXPLAIN SYNTAX SELECT * from executable('', 'JSON', 'data String', SETTINGS max_command_execution_time=100, command_read_timeout=1);
SELECT '--------------------'; SELECT '--------------------';
SELECT * from executable('JSON', 'data String', SETTINGS max_command_execution_time=100); -- { serverError BAD_ARGUMENTS } SELECT * from executable('JSON', 'data String', SETTINGS max_command_execution_time=100); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT * from executable('JSON', 'data String', 'TEST', 'TEST'); -- { serverError BAD_ARGUMENTS } SELECT * from executable('JSON', 'data String', 'TEST', 'TEST'); -- { serverError BAD_ARGUMENTS }