You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by sn...@apache.org on 2023/08/23 18:52:40 UTC

[flink] branch release-1.16 updated: [FLINK-32296][table] Support cast of collections with row element types

This is an automated email from the ASF dual-hosted git repository.

snuyanzin pushed a commit to branch release-1.16
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.16 by this push:
     new 4d593cdb3fb [FLINK-32296][table] Support cast of collections with row element types
4d593cdb3fb is described below

commit 4d593cdb3fb0e989065437ab3ed6430a7ea2075e
Author: Sergey Nuyanzin <sn...@gmail.com>
AuthorDate: Wed Aug 23 20:52:32 2023 +0200

    [FLINK-32296][table] Support cast of collections with row element types
---
 .../table/planner/functions/casting/RowToRowCastRule.java    |  3 ++-
 .../flink/table/planner/functions/CastFunctionITCase.java    | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/RowToRowCastRule.java b/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/RowToRowCastRule.java
index 323bd7a4712..a4682529404 100644
--- a/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/RowToRowCastRule.java
+++ b/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/RowToRowCastRule.java
@@ -221,7 +221,8 @@ class RowToRowCastRule extends AbstractNullAwareCodeGeneratorCastRule<RowData, R
                                     elseBodyWriter.stmt(writeNull));
         }
 
-        writer.stmt(methodCall(writerTerm, "complete")).assignStmt(returnVariable, rowTerm);
+        writer.stmt(methodCall(writerTerm, "complete"))
+                .assignStmt(returnVariable, methodCall(rowTerm, "copy"));
         return writer.toString();
     }
 
diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java
index 82ea5c5d024..6c87e3c97b1 100644
--- a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java
+++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java
@@ -1206,6 +1206,18 @@ public class CastFunctionITCase extends BuiltInFunctionTestBase {
                 CastTestSpecBuilder.testCastTo(ARRAY(BIGINT().notNull()))
                         .fromCase(ARRAY(INT().notNull()), new Integer[] {1, 2}, new Long[] {1L, 2L})
                         .build(),
+                CastTestSpecBuilder.testCastTo(ARRAY(ROW(INT(), STRING()).notNull()))
+                        .fromCase(
+                                ARRAY(ROW(INT(), VARCHAR(4)).notNull()),
+                                new Row[] {Row.of(1, "two"), Row.of(3, "four")},
+                                new Row[] {Row.of(1, "two"), Row.of(3, "four")})
+                        .build(),
+                CastTestSpecBuilder.testCastTo(MAP(ROW(INT()), STRING()))
+                        .fromCase(
+                                MAP(ROW(INT()), VARCHAR(4)),
+                                map(entry(Row.of(1), "two"), entry(Row.of(3), "four")),
+                                map(entry(Row.of(1), "two"), entry(Row.of(3), "four")))
+                        .build(),
                 CastTestSpecBuilder.testCastTo(ROW(BIGINT(), BIGINT(), STRING(), ARRAY(STRING())))
                         .fromCase(
                                 ROW(INT(), INT(), TIME(), ARRAY(CHAR(1))),