You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/05/05 04:24:36 UTC

[GitHub] [flink] rovboyko opened a new pull request, #19648: [FLINK-27438][table-planner] Fix the constructing a map array

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

   <!--
   *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
   
   This pull request fixes the ValidationException appears while trying to construct the array of maps. The bug appeared after adding explicit casting into SqlArrayConstructor in 0f51995bc156435eb9e97d2ac15e0225117877e2.
   
   
   ## Brief change log
   
     - add cast to map sql data type functionality into SqlValidatorUtils
     - add tests for plan verification inside batch and stream test sets
   
   
   ## Verifying this change
   
     - Extended unit tests for Calc exec plan verification
   
   ## 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


-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1123870692

   > I left a comment. TBH I'm not sure if [FLINK-19796](https://issues.apache.org/jira/browse/FLINK-19796) was actually the right approach to fix the issue. We could have simply adapted the runtime implementation to perform the casting during runtime instead of modifying the plan and the built-in operator. This change in Calcite's default type inference might cause downstream issues in the optimizer.
   
   Hi Timo @twalthr . Ok I've got your idea and try to adapt the runtime to different decimal precision (instead of [FLINK-19796]).
   Could you please take 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] matriv commented on a diff in pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
matriv commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r866767984


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,27 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        SqlDataTypeSpec dataTypeSpec;

Review Comment:
   ```suggestion
           final SqlDataTypeSpec dataTypeSpec;
   ```



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/CalcTest.scala:
##########
@@ -187,4 +187,13 @@ class CalcTest extends TableTestBase {
   def testDecimalMapWithDifferentPrecision(): Unit = {
     util.verifyExecPlan("SELECT MAP['a', 0.12, 'b', 0.5]")
   }
+
+  @Test
+  def testCastMapValueInsideArray(): Unit = {
+    util.verifyExecPlan(

Review Comment:
   Can we also add a test where the key or value (or both) is of some other type, like a numeric?



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/stream/sql/CalcTest.scala:
##########
@@ -181,4 +181,13 @@ class CalcTest extends TableTestBase {
   def testDecimalMapWithDifferentPrecision(): Unit = {
     util.verifyExecPlan("SELECT MAP['a', 0.12, 'b', 0.5]")
   }
+
+  @Test
+  def testCastMapValueInsideArray(): Unit = {
+    util.verifyExecPlan(

Review Comment:
   same here



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,27 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        SqlDataTypeSpec dataTypeSpec;
+        if (SqlTypeUtil.isMap(type)) {
+            dataTypeSpec = getMapSqlDataTypeSpec(type);
+        } else {
+            dataTypeSpec = SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable());
+        }
+
+        return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, dataTypeSpec);
+    }
+
+    private static SqlDataTypeSpec getMapSqlDataTypeSpec(RelDataType type) {
+        SqlDataTypeSpec dataTypeSpec;

Review Comment:
   ```suggestion
           final RelDataType keyType = type.getKeyType();
           final RelDataType valueType = type.getValueType();
           final SqlTypeNameSpec sqlTypeNameSpec =
                   new SqlMapTypeNameSpec(
                           SqlTypeUtil.convertTypeToSpec(keyType).withNullable(keyType.isNullable()),
                           SqlTypeUtil.convertTypeToSpec(valueType)
                                   .withNullable(valueType.isNullable()),
                           SqlParserPos.ZERO);
           return new SqlDataTypeSpec(sqlTypeNameSpec, SqlParserPos.ZERO);
   ```



-- 
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 #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1118149300

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4663578db1897a588c35e45d2cc0d5f03eb5d1cf",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "4663578db1897a588c35e45d2cc0d5f03eb5d1cf",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4663578db1897a588c35e45d2cc0d5f03eb5d1cf 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] MartijnVisser commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
MartijnVisser commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1141195843

   @rovboyko You'll need to rebase on master to get the latest fixes in that are currently blocking a successful CI run


-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1119210213

   @flinkbot run azure
   


-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1140982244

   @flinkbot run azure


-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1127778962

   ping @twalthr 


-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1138154479

   Hi Timo @twalthr  !
   I've rewritten the solution according to your idea to use the `generateCast` method.
   I had to change the `CodeGeneratorCastRule` to it be able to declare not only variables but the class fields too.
   Could you please take 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] twalthr commented on a diff in pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
twalthr commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r867997689


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,25 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        final SqlDataTypeSpec dataTypeSpec;
+        if (SqlTypeUtil.isMap(type)) {

Review Comment:
   Btw in `org.apache.flink.table.planner.functions.inference.TypeInferenceOperandChecker#castTo` we would have a similar issue, correct?



-- 
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] rovboyko commented on a diff in pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r866791321


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,27 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        SqlDataTypeSpec dataTypeSpec;

Review Comment:
   fixed



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,27 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        SqlDataTypeSpec dataTypeSpec;
+        if (SqlTypeUtil.isMap(type)) {
+            dataTypeSpec = getMapSqlDataTypeSpec(type);
+        } else {
+            dataTypeSpec = SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable());
+        }
+
+        return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, dataTypeSpec);
+    }
+
+    private static SqlDataTypeSpec getMapSqlDataTypeSpec(RelDataType type) {
+        SqlDataTypeSpec dataTypeSpec;

Review Comment:
   fixed



-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1119581469

   @matriv Thank you for such thorough review!
   I've fixed all and resolved all discussions.
   Could you please take a look once again?


-- 
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] rovboyko commented on a diff in pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r866791617


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/batch/sql/CalcTest.scala:
##########
@@ -187,4 +187,13 @@ class CalcTest extends TableTestBase {
   def testDecimalMapWithDifferentPrecision(): Unit = {
     util.verifyExecPlan("SELECT MAP['a', 0.12, 'b', 0.5]")
   }
+
+  @Test
+  def testCastMapValueInsideArray(): Unit = {
+    util.verifyExecPlan(

Review Comment:
   added



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/stream/sql/CalcTest.scala:
##########
@@ -181,4 +181,13 @@ class CalcTest extends TableTestBase {
   def testDecimalMapWithDifferentPrecision(): Unit = {
     util.verifyExecPlan("SELECT MAP['a', 0.12, 'b', 0.5]")
   }
+
+  @Test
+  def testCastMapValueInsideArray(): Unit = {
+    util.verifyExecPlan(

Review Comment:
   added



-- 
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] twalthr commented on a diff in pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
twalthr commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r876722784


##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/CodeGenUtils.scala:
##########
@@ -342,6 +342,14 @@ object CodeGenUtils {
         throw new IllegalArgumentException("Illegal type: " + t)
     }
 
+  def castToPrecisionAndScale(fieldValTerm: String, to: LogicalType, from: LogicalType): String = {
+    (to, from) match {
+      case (toDec: DecimalType, _: DecimalType) =>

Review Comment:
   This is a bit too specific. We should simply cast all arguments to `arrayType.getElementType` using the `generateCast` method.



-- 
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] MartijnVisser commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
MartijnVisser commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1174913135

   > Could you please take a look?
   
   @twalthr Can you have one more final 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] twalthr commented on a diff in pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
twalthr commented on code in PR #19648:
URL: https://github.com/apache/flink/pull/19648#discussion_r867995052


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/utils/SqlValidatorUtils.java:
##########
@@ -76,9 +80,25 @@ private static void adjustTypeForMultisetConstructor(
     }
 
     private static SqlNode castTo(SqlNode node, RelDataType type) {
-        return SqlStdOperatorTable.CAST.createCall(
-                SqlParserPos.ZERO,
-                node,
-                SqlTypeUtil.convertTypeToSpec(type).withNullable(type.isNullable()));
+        final SqlDataTypeSpec dataTypeSpec;
+        if (SqlTypeUtil.isMap(type)) {

Review Comment:
   Isn't this only fixing the top-level problem but not nested problems such as `ARRAY[ARRAY[MAP]]` or even more complex `ARRAY[MAP[ARRAY[MAP]]]`?



-- 
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] rovboyko commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
rovboyko commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1119639236

   > @MartijnVisser Would be great to backport it to 1.15 and I guess 1.14 as well.
   
   Yes, we discussed it, 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] matriv commented on pull request #19648: [FLINK-27438][table-planner] Fix the constructing a map array

Posted by GitBox <gi...@apache.org>.
matriv commented on PR #19648:
URL: https://github.com/apache/flink/pull/19648#issuecomment-1119593074

   @MartijnVisser Would be great to backport it to 1.15 and I guess 1.14 as well.


-- 
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