Skip to content

Commit

Permalink
Fix case expression (#2819)
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango authored Sep 10, 2021
1 parent c334437 commit b0908fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/expression/CaseExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ const Value& CaseExpression::eval(ExpressionContext& ctx) {
return result_;
}
} else {
if (!when.isBool()) {
if (!when.isBool() && !when.isNull()) {
return Value::kNullBadType;
}
if (when.getBool()) {
if (when.isBool() && when.getBool()) {
result_ = whenThen.then->eval(ctx);
return result_;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/aggregate/Agg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Feature: Basic Aggregate and GroupBy
Then the result should be, in any order, with relax comparison:
| COUNT(*) | (1+1) |
| 1 | 2 |
When executing query:
"""
YIELD COUNT(CASE WHEN null THEN null ELSE 1 END) AS nulls
"""
Then the result should be, in any order, with relax comparison:
| nulls |
| 1 |
When executing query:
"""
YIELD COUNT(*)+1 ,1+2 ,(INT)abs(count(2))
Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/expression/Case.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ Feature: Case Expression
Then the result should be, in any order:
| r |
| 1 |
When executing query:
"""
YIELD CASE WHEN null THEN 0 ELSE 1 END AS r
"""
Then the result should be, in any order:
| r |
| 1 |

Scenario: yield conditional case
When executing query:
Expand Down

0 comments on commit b0908fc

Please sign in to comment.