Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Return actual type if the case expr returns the same types (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Jul 12, 2021
1 parent 9467c87 commit 2fe9721
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/visitor/DeduceTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ void DeduceTypeVisitor::visit(CaseExpression *expr) {
if (!ok()) return;
}

std::unordered_set<Value::Type> types;
for (const auto &whenThen : expr->cases()) {
whenThen.when->accept(this);
if (!ok()) return;
Expand All @@ -567,10 +568,14 @@ void DeduceTypeVisitor::visit(CaseExpression *expr) {
}
whenThen.then->accept(this);
if (!ok()) return;
types.emplace(type_);
}

// Will not deduce the actual value type returned by case expression.
type_ = Value::Type::__EMPTY__;
if (types.size() == 1) {
type_ = *types.begin();
} else {
type_ = Value::Type::__EMPTY__;
}
}

void DeduceTypeVisitor::visit(PredicateExpression *expr) {
Expand Down
10 changes: 10 additions & 0 deletions tests/tck/features/expression/Case.feature
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,13 @@ Feature: Case Expression
| "Boris Diaw" | 2008 | 2012 | "old" | "Hornets" |
| "Boris Diaw" | 2012 | 2016 | "bad" | "Spurs" |
| "Boris Diaw" | 2016 | 2017 | "old" | "Jazz" |

Scenario: Using the return value of case expr as an input
When executing query:
"""
RETURN CASE WHEN true THEN "Tim Duncan" ELSE "ABC" END AS a | GO FROM $-.a OVER like;
"""
Then the result should be, in order:
| like._dst |
| "Manu Ginobili" |
| "Tony Parker" |

0 comments on commit 2fe9721

Please sign in to comment.