Handle syntax error for ARRAY JOIN with no args

This commit is contained in:
vdimir 2021-02-09 11:21:26 +03:00
parent c12f2d460e
commit 241769ee7c
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
2 changed files with 11 additions and 6 deletions

View File

@ -40,13 +40,14 @@ namespace DB
namespace ErrorCodes
{
extern const int EMPTY_NESTED_TABLE;
extern const int LOGICAL_ERROR;
extern const int INVALID_JOIN_ON_EXPRESSION;
extern const int EMPTY_LIST_OF_COLUMNS_QUERIED;
extern const int NOT_IMPLEMENTED;
extern const int UNKNOWN_IDENTIFIER;
extern const int EMPTY_NESTED_TABLE;
extern const int EXPECTED_ALL_OR_ANY;
extern const int INVALID_JOIN_ON_EXPRESSION;
extern const int LOGICAL_ERROR;
extern const int NOT_IMPLEMENTED;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int UNKNOWN_IDENTIFIER;
}
namespace
@ -327,6 +328,9 @@ void getArrayJoinedColumns(ASTPtr & query, TreeRewriterResult & result, const AS
/// to get the correct number of rows.
if (result.array_join_result_to_source.empty())
{
if (select_query->arrayJoinExpressionList()->children.empty())
throw DB::Exception("ARRAY JOIN requires an argument", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
ASTPtr expr = select_query->arrayJoinExpressionList()->children.at(0);
String source_name = expr->getColumnName();
String result_name = expr->getAliasOrColumnName();

View File

@ -1 +1,2 @@
SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN arr AS a
SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN; -- { serverError 42 }
SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN arr AS a;