This is an automated email from the ASF dual-hosted git repository. twalthr pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push: new fcbbcf9bf91 [FLINK-27247][table-planner] ScalarOperatorGens.numericCasting is not compatible with legacy behavior fcbbcf9bf91 is described below commit fcbbcf9bf91dc15ac5fc6d37a0b1445aa897f0d4 Author: xuyang <xyzhong...@163.com> AuthorDate: Thu Apr 14 16:20:01 2022 +0800 [FLINK-27247][table-planner] ScalarOperatorGens.numericCasting is not compatible with legacy behavior This closes #19470. --- .../planner/codegen/calls/ScalarOperatorGens.scala | 30 ++++++++++++---------- .../planner/expressions/ScalarFunctionsTest.scala | 13 ++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala index 6ed3fc0807b..37f8e4a97b9 100644 --- a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala +++ b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala @@ -1719,19 +1719,23 @@ object ScalarOperatorGens { operandType: LogicalType, resultType: LogicalType): String => String = { - // All numeric rules are assumed to be instance of AbstractExpressionCodeGeneratorCastRule - val rule = CastRuleProvider.resolve(operandType, resultType) - rule match { - case codeGeneratorCastRule: ExpressionCodeGeneratorCastRule[_, _] => - operandTerm => - codeGeneratorCastRule.generateExpression( - toCodegenCastContext(ctx), - operandTerm, - operandType, - resultType - ) - case _ => - throw new CodeGenException(s"Unsupported casting from $operandType to $resultType.") + // no casting necessary + if (isInteroperable(operandType, resultType)) { operandTerm => s"$operandTerm" } + else { + // All numeric rules are assumed to be instance of AbstractExpressionCodeGeneratorCastRule + val rule = CastRuleProvider.resolve(operandType, resultType) + rule match { + case codeGeneratorCastRule: ExpressionCodeGeneratorCastRule[_, _] => + operandTerm => + codeGeneratorCastRule.generateExpression( + toCodegenCastContext(ctx), + operandTerm, + operandType, + resultType + ) + case _ => + throw new CodeGenException(s"Unsupported casting from $operandType to $resultType.") + } } } diff --git a/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/expressions/ScalarFunctionsTest.scala b/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/expressions/ScalarFunctionsTest.scala index e74aab040c5..6070b3152fe 100644 --- a/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/expressions/ScalarFunctionsTest.scala +++ b/flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/expressions/ScalarFunctionsTest.scala @@ -1515,6 +1515,19 @@ class ScalarFunctionsTest extends ScalarTypesTestBase { randInteger('f7, 'f4.cast(DataTypes.INT)), "RAND_INTEGER(f7, CAST(f4 AS INT))", random4.nextInt(44).toString) + + val random5 = new java.util.Random(1) + testAllApis(rand(1).plus(1), "RAND(1) + 1", (random5.nextDouble() + 1).toString) + + val random6 = new java.util.Random(1) + val random7 = new java.util.Random(2) + testAllApis( + rand(1).plus(rand(2)), + "RAND(1) + RAND(2)", + (random6.nextDouble() + random7.nextDouble()).toString) + + // the f21 is null + testAllApis(rand('f21.cast(DataTypes.INT())).plus(1), "rand(cast(null as int)) + 1", "NULL") } @Test