Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix case expression #2819

Merged
merged 4 commits into from
Sep 10, 2021
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
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
czpmango marked this conversation as resolved.
Show resolved Hide resolved
"""
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