Skip to content

Commit

Permalink
[FLINK-15266][table-planner-blink] Fix NPE for code generated CASE WH…
Browse files Browse the repository at this point in the history
…EN operator in blink planner (#10594)
  • Loading branch information
libenchao authored and wuchong committed Dec 20, 2019
1 parent b692d10 commit 5f86f2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1279,21 +1279,26 @@ object ScalarOperatorGens {

val Seq(resultTerm, nullTerm) = newNames("result", "isNull")
val resultTypeTerm = primitiveTypeTermForType(resultType)
val defaultValue = primitiveDefaultValue(resultType)

val operatorCode = if (ctx.nullCheck) {
s"""
|${condition.code}
|$resultTypeTerm $resultTerm;
|$resultTypeTerm $resultTerm = $defaultValue;
|boolean $nullTerm;
|if (${condition.resultTerm}) {
| ${trueAction.code}
| $resultTerm = ${trueAction.resultTerm};
| $nullTerm = ${trueAction.nullTerm};
| if (!$nullTerm) {
| $resultTerm = ${trueAction.resultTerm};
| }
|}
|else {
| ${falseAction.code}
| $resultTerm = ${falseAction.resultTerm};
| $nullTerm = ${falseAction.nullTerm};
| if (!$nullTerm) {
| $resultTerm = ${falseAction.resultTerm};
| }
|}
|""".stripMargin.trim
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,7 @@ class ScalarOperatorsTest extends ScalarOperatorsTestBase {
testSqlApi("CASE f7 WHEN 1 THEN 11 WHEN 2 THEN 4 ELSE NULL END", "null")
testSqlApi("CASE 42 WHEN 1 THEN 'a' WHEN 2 THEN 'bcd' END", "null")
testSqlApi("CASE 1 WHEN 1 THEN true WHEN 2 THEN false ELSE NULL END", "true")

testSqlApi("CASE WHEN f2 = 1 THEN CAST('' as INT) ELSE 0 END", "null")
}
}

0 comments on commit 5f86f2d

Please sign in to comment.