You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "shuiqiangchen (via GitHub)" <gi...@apache.org> on 2023/02/14 09:14:55 UTC

[GitHub] [flink] shuiqiangchen opened a new pull request, #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

shuiqiangchen opened a new pull request, #21927:
URL: https://github.com/apache/flink/pull/21927

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Optimize type inference for Character type and fix result type casting in IfCallGen.
   
   
   ## Brief change log
   
   - *Get the leastRestrictive type among numeric and character type in NumericOrDefaultReturnTypeInference*
   - *Adjust the result term casting code block.*
   
   
   ## Verifying this change
   
   This change has test case covered by testIfFunctionWithNestedInput in CalcITCase.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (not documented)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1217441125


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,24 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunction(): Unit = {
+
+    implicit val typeInfo: TypeInformation[Row] =

Review Comment:
   The test will fail, 
   ```
   org.apache.flink.table.api.ValidationException: SQL validation failed. At line 1, column 11: Column 'a' not found in any table
   	at org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:187)
   	at org.apache.flink.table.planner.calcite.FlinkPlannerImpl.validate(FlinkPlannerImpl.scala:113)
   ```
   how about using 
   ```
       val testDataId = TestValuesTableFactory.registerData(TestData.data1)
       val ddl =
         s"""
            |CREATE TABLE t (
            |  a int,
            |  b varchar,
            |  c int
            |) WITH (
            |  'connector' = 'values',
            |  'data-id' = '$testDataId',
            |  'bounded' = 'true'
            |)
          """.stripMargin
       tEnv.executeSql(ddl)
       val expected = List("false,1", "false,2", "false,3", "true,4", "true,5", "true,6")
       val actual = tEnv
         .executeSql("SELECT IF(a > 3, 'true', 'false'), a from t")
         .collect()
         .map(r => r.toString)
         .toList
       assertEquals(expected.sorted, actual.sorted)
   ```?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #21927:
URL: https://github.com/apache/flink/pull/21927#issuecomment-1569451106

   @shuiqiangchen Hi, are you still working on this? I do hope we can get it merged asap as it has been reported by users many times.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] shuiqiangchen commented on pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "shuiqiangchen (via GitHub)" <gi...@apache.org>.
shuiqiangchen commented on PR #21927:
URL: https://github.com/apache/flink/pull/21927#issuecomment-1576393478

   @luoyuxia Thank you for your review with patience. The CI  tests have passed, please help review the PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] shuiqiangchen commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "shuiqiangchen (via GitHub)" <gi...@apache.org>.
shuiqiangchen commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1217473915


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,24 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunction(): Unit = {
+
+    implicit val typeInfo: TypeInformation[Row] =

Review Comment:
   Ok, It would be more intuitive with DDL.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1199899162


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/IfCallGen.scala:
##########
@@ -52,19 +52,19 @@ class IfCallGen() extends CallGenerator {
     val resultCode =
       s"""
          |// --- Start code generated by ${className[IfCallGen]}
-         |${castedResultTerm1.getCode}
-         |${castedResultTerm2.getCode}
          |${operands.head.code}
          |$resultTerm = $resultDefault;
          |if (${operands.head.resultTerm}) {
          |  ${operands(1).code}
          |  if (!${operands(1).nullTerm}) {
+         |    ${castedResultTerm1.getCode}

Review Comment:
   But I'm fine with this change for seems it can reduce unneccessay code path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] shuiqiangchen commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "shuiqiangchen (via GitHub)" <gi...@apache.org>.
shuiqiangchen commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1212754824


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/NumericOrDefaultReturnTypeInference.java:
##########
@@ -56,7 +56,7 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
         List<RelDataType> types = new ArrayList<>();
         for (int i = startTypeIdx; i < nOperands; i++) {
             RelDataType type = opBinding.getOperandType(i);
-            if (SqlTypeUtil.isNumeric(type)) {
+            if (SqlTypeUtil.isNumeric(type) || SqlTypeUtil.isCharacter(type)) {

Review Comment:
   Yes, I would like to rename the class name to LeastRestrictiveOrDefaultReturnTypeInference since numeric and character both are types that have least restrictive. What do you think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] shuiqiangchen commented on pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "shuiqiangchen (via GitHub)" <gi...@apache.org>.
shuiqiangchen commented on PR #21927:
URL: https://github.com/apache/flink/pull/21927#issuecomment-1571556517

   @luoyuxia Sorry for the late update and thank you for your reviewing with good suggestions. I have updated the PR accordingly, please have a look.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] shuiqiangchen commented on pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "shuiqiangchen (via GitHub)" <gi...@apache.org>.
shuiqiangchen commented on PR #21927:
URL: https://github.com/apache/flink/pull/21927#issuecomment-1576485296

   @luoyuxia I'll do it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on PR #21927:
URL: https://github.com/apache/flink/pull/21927#issuecomment-1576478717

   @shuiqiangchen Could you please backport to 1.17 & 1.16? Thanks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia merged pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia merged PR #21927:
URL: https://github.com/apache/flink/pull/21927


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1106550718


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/NumericOrDefaultReturnTypeInference.java:
##########
@@ -56,7 +56,7 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
         List<RelDataType> types = new ArrayList<>();
         for (int i = startTypeIdx; i < nOperands; i++) {
             RelDataType type = opBinding.getOperandType(i);
-            if (SqlTypeUtil.isNumeric(type)) {
+            if (SqlTypeUtil.isNumeric(type) || SqlTypeUtil.isCharacter(type)) {

Review Comment:
   May be we need to update the class name and java doc for the class



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1213012657


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/LeastRestrictiveOrDefaultReturnTypeInference.java:
##########
@@ -56,7 +57,7 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
         List<RelDataType> types = new ArrayList<>();
         for (int i = startTypeIdx; i < nOperands; i++) {
             RelDataType type = opBinding.getOperandType(i);
-            if (SqlTypeUtil.isNumeric(type)) {
+            if (SqlTypeUtil.isNumeric(type) || SqlTypeUtil.isCharacter(type)) {

Review Comment:
   My gut feeling is if the type is `BINARY`, the cast will also fail, right?
   For example, some thing like IF(false, binary(10), binary(20)). 
   Seem then it will also cast to binary(10) which cause precision loss.
    If that's the case, we'll need to enumerate all the types that will be affected in here.



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,50 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunctionWithNestedInput(): Unit = {
+    implicit val typeInfo: TypeInformation[Row] =
+      Types.ROW(
+        Array("words", "c"),
+        Array(
+          Types.ROW(
+            Array("a", "b"),
+            Array(Types.STRING, Types.STRING).asInstanceOf[Array[TypeInformation[_]]]),
+          Types.INT).asInstanceOf[Array[TypeInformation[_]]]
+      )
+    val t = env.fromCollection(TestData.nullableNestedRow).toTable(tEnv)
+    tEnv.createTemporaryView("t", t)
+    val cmp = (l: Row, r: Row) => l.getField(1).asInstanceOf[Int] > r.getField(1).asInstanceOf[Int]
+    var result = tEnv
+      .executeSql("SELECT IF(c > 3, words.a, words.b), c, words.a, words.b from t")
+      .collect()
+      .toList
+      .sortWith(cmp)
+    var expected = List(
+      Row.of("Worlds", Int.box(1), "Hello", "Worlds"),
+      Row.of("Hello", Int.box(5), "Hello", "Hidden"),
+      Row.of(null, Int.box(2), "Hello again", null),
+      Row.of("World", Int.box(0), null, "World"),
+      Row.of("Hello again", Int.box(6), "Hello again", "Hide")
+    ).sortWith(cmp)
+    assertEquals(expected, result)
+
+    // IF with constant values
+    result = tEnv

Review Comment:
   How about simplying the test with the following code?
   ```  
    val expected = List("true, 6", "xxx")
    val actual = CollectionUtil.iteratorToList(tEnv
         .executeSql("SELECT IF(c > 3, 'true', 'false'), c from t").collect()).map(r => r.toString)
    assertEquals(expected.sorted, actual.sorted)
   ```



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,50 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunctionWithNestedInput(): Unit = {

Review Comment:
   Also, is it really related to`nested input`?
   Can we just simply the test like [here](https://github.com/apache/flink/pull/21657/files#diff-117387d9452230d1d66c1899d51ec1692abd437b03b4359d4794768121504fcdR1843)



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,50 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunctionWithNestedInput(): Unit = {

Review Comment:
   How about renaming to `testIfFunction`?



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/LeastRestrictiveOrDefaultReturnTypeInference.java:
##########
@@ -27,25 +27,26 @@
 import java.util.List;
 
 /**
- * Determine the return type of functions with numeric arguments. The return type is the type of the
- * argument with the largest range. We start to consider the arguments from the `startTypeIdx`-th
- * one. If one of the arguments is not of numeric type, we return the type of the
+ * Determine the return type of functions with arguments that has the least restrictive (eg:
+ * numeric, character). The return type is the type of the argument with the largest range. We start
+ * to consider the arguments from the `startTypeIdx`-th one. If one of the arguments is not of the
+ * type that has the least restrictive (eg: numeric, character), we return the type of the
  * `defaultTypeIdx`-th argument instead.
  */
-public class NumericOrDefaultReturnTypeInference implements SqlReturnTypeInference {
+public class LeastRestrictiveOrDefaultReturnTypeInference implements SqlReturnTypeInference {

Review Comment:
   I found the name if hard to understand to me. Since we only use it in `IF` sql function, how about rename it to `IF_NULLABLE` like `STR_MAP_NULLABLE`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1213054174


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,50 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunctionWithNestedInput(): Unit = {

Review Comment:
   Also, is it really related to`nested input`?
   Can we just simply the test like [here](https://github.com/apache/flink/pull/21663/files#diff-117387d9452230d1d66c1899d51ec1692abd437b03b4359d4794768121504fcdR1842)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #21927:
URL: https://github.com/apache/flink/pull/21927#issuecomment-1429393177

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "223d0bb0a6f2015b4c4f6b559efcc8f9b6d992e8",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "223d0bb0a6f2015b4c4f6b559efcc8f9b6d992e8",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 223d0bb0a6f2015b4c4f6b559efcc8f9b6d992e8 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1106550718


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/NumericOrDefaultReturnTypeInference.java:
##########
@@ -56,7 +56,7 @@ public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
         List<RelDataType> types = new ArrayList<>();
         for (int i = startTypeIdx; i < nOperands; i++) {
             RelDataType type = opBinding.getOperandType(i);
-            if (SqlTypeUtil.isNumeric(type)) {
+            if (SqlTypeUtil.isNumeric(type) || SqlTypeUtil.isCharacter(type)) {

Review Comment:
   May be we need to update the class name and java doc for the class since it won't be number or default return type any more.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #21927: [FLINK-30966][table-planner] Optimize type inference for Character type and fix result type casting in IfCallGen

Posted by "luoyuxia (via GitHub)" <gi...@apache.org>.
luoyuxia commented on code in PR #21927:
URL: https://github.com/apache/flink/pull/21927#discussion_r1199884283


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/IfCallGen.scala:
##########
@@ -52,19 +52,19 @@ class IfCallGen() extends CallGenerator {
     val resultCode =
       s"""
          |// --- Start code generated by ${className[IfCallGen]}
-         |${castedResultTerm1.getCode}
-         |${castedResultTerm2.getCode}
          |${operands.head.code}
          |$resultTerm = $resultDefault;
          |if (${operands.head.resultTerm}) {
          |  ${operands(1).code}
          |  if (!${operands(1).nullTerm}) {
+         |    ${castedResultTerm1.getCode}

Review Comment:
   Since we have changed the type inference in [here](https://github.com/apache/flink/pull/21927/files#diff-2c7dc9ff08ba0e7271dd3f739dcd9ccce11f0d074054074f488e6d1f27df7bf3R59),  we don't need to modify int here, right?



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/CalcITCase.scala:
##########
@@ -366,6 +366,59 @@ class CalcITCase extends StreamingTestBase {
     sink.getAppendResults.foreach(result => assertEquals(expected, result))
   }
 
+  @Test
+  def testIfFunctionWithNestedInput(): Unit = {
+    val data = List(
+      Row.of(Row.of("Hello", "Worlds"), Int.box(1)),
+      Row.of(Row.of("Hello", "Hidden"), Int.box(5)),
+      Row.of(Row.of("Hello again", null), Int.box(2)),
+      Row.of(Row.of(null, "World"), Int.box(0)),
+      Row.of(Row.of("Hello again", "Hide"), Int.box(6))
+    )
+    val dataId = TestValuesTableFactory.registerData(data)
+    val ddl =

Review Comment:
   Following the style of this test, use the way like
   `   val t = env
         .fromCollection(TestData.tupleData3)
         .toTable(tEnv, 'a, 'b, 'c)
       tEnv.createTemporaryView("MyTable", t)
   ` 
   to create a table ? Then the code will look much clear.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org