[fix](Nereids) type coercion on case-when is not correct (#12650)

When we do type coercion on CaseWhen expression, such as sql like this:
```
CASE WHEN n_nationkey > 1 THEN n_regionkey ELSE 0 END
```
The ELSE part 0 need do type coercion as CAST (0 AS INT). But we miss it in PR #11802
This commit is contained in:
minghong
2022-09-16 02:26:11 +08:00
committed by GitHub
parent a63cdc8a7c
commit 98dad6158b

View File

@ -65,7 +65,11 @@ public class CaseWhen extends Expression {
}
public List<DataType> dataTypesForCoercion() {
return whenClauses.stream().map(WhenClause::getDataType).collect(Collectors.toList());
List<DataType> result = whenClauses.stream().map(WhenClause::getDataType).collect(Collectors.toList());
if (defaultValue.isPresent()) {
result.add(defaultValue.get().getDataType());
}
return result;
}
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {