This is an automated email from the ASF dual-hosted git repository. lzljs3620320 pushed a commit to branch release-1.13 in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.13 by this push: new 447452d [FLINK-23184][table-runtime] Fix compile error in code generation of unary plus and minus 447452d is described below commit 447452d0cdbec9a6d97e96dcb89977e52c27750e Author: TsReaper <tsreape...@gmail.com> AuthorDate: Thu Jul 8 10:23:59 2021 +0800 [FLINK-23184][table-runtime] Fix compile error in code generation of unary plus and minus This closes #16411 --- .../planner/codegen/calls/ScalarOperatorGens.scala | 6 ++++-- .../planner/expressions/ScalarOperatorsTest.scala | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala index 301b4ec..4f1a39b 100644 --- a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala +++ b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala @@ -154,12 +154,14 @@ object ScalarOperatorGens { } else if (isDecimal(operand.resultType) && operator == "+") { s"$operandTerm" } else { - s"$operator($operandTerm)" + // no need to check if result type might be null, + // because if this line of code is called, `operatorTerm` must not be null + val typeTerm = primitiveTypeTermForType(resultType) + s"($typeTerm) $operator($operandTerm)" } } } - def generateTemporalPlusMinus( ctx: CodeGeneratorContext, plus: Boolean, diff --git a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/ScalarOperatorsTest.scala b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/ScalarOperatorsTest.scala index 0bfff12..9f8968d 100644 --- a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/ScalarOperatorsTest.scala +++ b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/ScalarOperatorsTest.scala @@ -180,4 +180,22 @@ class ScalarOperatorsTest extends ScalarOperatorsTestBase { testSqlApi("CASE WHEN f2 = 1 THEN CAST ('' as INT) ELSE 0 END", "null") testSqlApi("IF(true, CAST ('non-numeric' AS BIGINT), 0)", "null") } + + @Test + def testUnaryPlusMinus(): Unit = { + testSqlApi("-f0", "-1") + testSqlApi("+f0", "1") + testSqlApi("-f1", "-1") + testSqlApi("+f1", "1") + testSqlApi("-f2", "-1") + testSqlApi("+f2", "1") + testSqlApi("-f3", "-1") + testSqlApi("+f3", "1") + testSqlApi("-f4", "-1.0") + testSqlApi("+f4", "1.0") + testSqlApi("-f5", "-1.0") + testSqlApi("+f5", "1.0") + testSqlApi("-f17", "-10.0") + testSqlApi("+f17", "10.0") + } }