Skip to content

Commit

Permalink
[fix](planner) fix targetTypeDef NPE when value is null (apache#18072)
Browse files Browse the repository at this point in the history
sql like:
select * from (select *, null as top from v1)t where top = 5;
select * from (select *, null as top from v1)t where top is not null;
will cause NPE because targetTypeDef is null when value is null. Now we use cast target type to the targetTypeDef.
  • Loading branch information
sohardforaname authored and morningman committed Mar 28, 2023
1 parent ae6ca5b commit d918886
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ public Expr getResultValue(boolean inView) throws AnalysisException {

private Expr castTo(LiteralExpr value) throws AnalysisException {
if (value instanceof NullLiteral) {
return NullLiteral.create(targetTypeDef.getType());
if (targetTypeDef != null) {
return NullLiteral.create(targetTypeDef.getType());
} else {
return NullLiteral.create(type);
}
} else if (type.isIntegerType()) {
return new IntLiteral(value.getLongValue(), type);
} else if (type.isLargeIntType()) {
Expand Down
15 changes: 15 additions & 0 deletions regression-test/suites/query_p0/literal_view/lietral_test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,19 @@ suite("literal_view_test") {
) a
where name != '1234';
"""

test {
sql "select * from (select null as top) t where top is not null"
result ([])
}

test {
sql "select * from (select null as top) t where top is null"
result ([[null]])
}

test {
sql "select * from (select null as top) t where top = 5"
result ([])
}
}

0 comments on commit d918886

Please sign in to comment.