mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Merge pull request #70464 from Algunenano/fix_analyzer
Fix crash in WHERE with lambda functions
This commit is contained in:
commit
46824d0434
@ -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 {}",
|
||||
|
@ -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 '---';
|
||||
|
||||
|
1
tests/queries/0_stateless/03248_invalid_where.sql
Normal file
1
tests/queries/0_stateless/03248_invalid_where.sql
Normal file
@ -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 }
|
Loading…
Reference in New Issue
Block a user