Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,7 @@ protected Type visitFunctionCall(FunctionCall node, StackableAstVisitorContext<C
if (node.getFilter().isPresent()) {
Expression expression = node.getFilter().get();
Type type = process(expression, context);
if (!type.equals(BOOLEAN)) {
if (!type.equals(UNKNOWN)) {
throw semanticException(TYPE_MISMATCH, expression, "Filter expression must evaluate to a boolean: actual type %s", type);
}
}
coerceType(expression, type, BOOLEAN, "Filter expression");
}

List<TypeSignatureProvider> argumentTypes = getCallArgumentTypes(node.getArguments(), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4035,6 +4035,7 @@ public void testInValidJoinOnClause()
@Test
public void testNullAggregationFilter()
{
analyze("SELECT count(*) FILTER (WHERE NULL) FROM t1");
analyze("SELECT a, count(*) FILTER (WHERE NULL) FROM t1 GROUP BY a");
}

Expand All @@ -4052,10 +4053,10 @@ public void testInvalidAggregationFilter()
.hasMessage("line 1:8: Filter is only valid for aggregation functions");
assertFails("SELECT count(*) FILTER (WHERE 0) FROM t1")
.hasErrorCode(TYPE_MISMATCH)
.hasMessage("line 1:31: Filter expression must evaluate to a boolean: actual type integer");
.hasMessage("line 1:31: Filter expression must evaluate to a boolean (actual: integer)");
assertFails("SELECT a, count(*) FILTER (WHERE 0) FROM t1 GROUP BY a")
.hasErrorCode(TYPE_MISMATCH)
.hasMessage("line 1:34: Filter expression must evaluate to a boolean: actual type integer");
.hasMessage("line 1:34: Filter expression must evaluate to a boolean (actual: integer)");
}

@Test
Expand Down