diff --git a/src/Analyzer/ValidationUtils.cpp b/src/Analyzer/ValidationUtils.cpp index 1070c92d8ad..d1ff3c916f8 100644 --- a/src/Analyzer/ValidationUtils.cpp +++ b/src/Analyzer/ValidationUtils.cpp @@ -19,6 +19,8 @@ namespace ErrorCodes extern const int BAD_ARGUMENTS; extern const int ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER; extern const int ILLEGAL_PREWHERE; + extern const int UNSUPPORTED_METHOD; + extern const int UNEXPECTED_EXPRESSION; } namespace @@ -26,11 +28,24 @@ namespace void validateFilter(const QueryTreeNodePtr & filter_node, std::string_view exception_place_message, const QueryTreeNodePtr & query_node) { - if (filter_node->getNodeType() == QueryTreeNodeType::LIST) - throw Exception(ErrorCodes::BAD_ARGUMENTS, - "Unsupported expression '{}' in filter", filter_node->formatASTForErrorMessage()); + DataTypePtr filter_node_result_type; + try + { + filter_node_result_type = filter_node->getResultType(); + } + catch (const DB::Exception &e) + { + if (e.code() != ErrorCodes::UNSUPPORTED_METHOD) + e.rethrow(); + } + + if (!filter_node_result_type) + throw Exception(ErrorCodes::UNEXPECTED_EXPRESSION, + "Unexpected expression '{}' in filter in {}. In query {}", + filter_node->formatASTForErrorMessage(), + exception_place_message, + query_node->formatASTForErrorMessage()); - auto filter_node_result_type = filter_node->getResultType(); if (!filter_node_result_type->canBeUsedInBooleanContext()) throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER, "Invalid type for filter in {}: {}. In query {}", diff --git a/tests/queries/0_stateless/03101_analyzer_identifiers_3.sql b/tests/queries/0_stateless/03101_analyzer_identifiers_3.sql index 997fee91930..f113b8bc9e6 100644 --- a/tests/queries/0_stateless/03101_analyzer_identifiers_3.sql +++ b/tests/queries/0_stateless/03101_analyzer_identifiers_3.sql @@ -39,7 +39,7 @@ SELECT * GROUP BY *; -- not ok as every component of ORDER BY may contain ASC/DESC and COLLATE; though can be supported in some sense -- but it works SELECT * ORDER BY *; -SELECT * WHERE *; -- { serverError BAD_ARGUMENTS } +SELECT * WHERE *; -- { serverError UNEXPECTED_EXPRESSION } SELECT '---'; diff --git a/tests/queries/0_stateless/03248_invalid_where.reference b/tests/queries/0_stateless/03248_invalid_where.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03248_invalid_where.sql b/tests/queries/0_stateless/03248_invalid_where.sql new file mode 100644 index 00000000000..0b1183a382a --- /dev/null +++ b/tests/queries/0_stateless/03248_invalid_where.sql @@ -0,0 +1 @@ +WITH x -> toString(x) AS lambda_1 SELECT arrayMap(lambda_1 AS lambda_2, [1, 2, 3]), arrayMap(lambda_2, ['1', '2', '3']) WHERE lambda_2; -- { serverError UNEXPECTED_EXPRESSION } \ No newline at end of file