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

snuyanzin 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 a356421ded6 [FLINK-38069][table] Fix return type nullability diffs of 
function ENCODE & DECODE in SQL and Table API
a356421ded6 is described below

commit a356421ded64dc95a7c274e25663e977c9af9dfa
Author: dylanhz <53137516+dyla...@users.noreply.github.com>
AuthorDate: Sat Aug 2 23:00:38 2025 +0800

    [FLINK-38069][table] Fix return type nullability diffs of function ENCODE & 
DECODE in SQL and Table API
---
 .../planner/functions/sql/FlinkSqlOperatorTable.java     |  6 ++++--
 .../table/planner/functions/MiscFunctionsITCase.java     | 16 ++++++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git 
a/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/FlinkSqlOperatorTable.java
 
b/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/FlinkSqlOperatorTable.java
index c897000b3d2..bae972abaeb 100644
--- 
a/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/FlinkSqlOperatorTable.java
+++ 
b/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/FlinkSqlOperatorTable.java
@@ -888,7 +888,7 @@ public class FlinkSqlOperatorTable extends 
ReflectiveSqlOperatorTable {
                     SqlKind.OTHER_FUNCTION,
                     ReturnTypes.cascade(
                             ReturnTypes.explicit(SqlTypeName.VARBINARY),
-                            SqlTypeTransforms.FORCE_NULLABLE),
+                            SqlTypeTransforms.TO_NULLABLE),
                     null,
                     OperandTypes.family(SqlTypeFamily.CHARACTER, 
SqlTypeFamily.CHARACTER),
                     SqlFunctionCategory.STRING);
@@ -897,7 +897,9 @@ public class FlinkSqlOperatorTable extends 
ReflectiveSqlOperatorTable {
             new SqlFunction(
                     "DECODE",
                     SqlKind.OTHER_FUNCTION,
-                    VARCHAR_FORCE_NULLABLE,
+                    ReturnTypes.cascade(
+                            ReturnTypes.explicit(SqlTypeName.VARCHAR),
+                            SqlTypeTransforms.TO_NULLABLE),
                     null,
                     OperandTypes.family(SqlTypeFamily.BINARY, 
SqlTypeFamily.CHARACTER),
                     SqlFunctionCategory.STRING);
diff --git 
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MiscFunctionsITCase.java
 
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MiscFunctionsITCase.java
index 67baf4dc96c..b347f8d158c 100644
--- 
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MiscFunctionsITCase.java
+++ 
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MiscFunctionsITCase.java
@@ -229,7 +229,13 @@ class MiscFunctionsITCase extends BuiltInFunctionTestBase {
                                 lit("Hello world").encode($("f2")),
                                 "ENCODE('Hello world', f2)",
                                 "Hello world".getBytes(StandardCharsets.UTF_8),
-                                DataTypes.BYTES().nullable()),
+                                DataTypes.BYTES().nullable())
+                        .testResult(
+                                // test for nullability of return type
+                                lit("Hello world").encode("utf-8"),
+                                "ENCODE('Hello world', 'utf-8')",
+                                "Hello world".getBytes(StandardCharsets.UTF_8),
+                                DataTypes.BYTES().notNull()),
                 TestSetSpec.forFunction(BuiltInFunctionDefinitions.DECODE)
                         .onFieldsWithData(
                                 null, "Hello 
world".getBytes(StandardCharsets.UTF_8), "utf-8")
@@ -250,7 +256,13 @@ class MiscFunctionsITCase extends BuiltInFunctionTestBase {
                                 lit("Hello 
world".getBytes(StandardCharsets.UTF_8)).decode($("f2")),
                                 "DECODE(x'" + EncodingUtils.hex("Hello world") 
+ "', f2)",
                                 "Hello world",
-                                DataTypes.STRING().nullable()));
+                                DataTypes.STRING().nullable())
+                        .testResult(
+                                // test for nullability of return type
+                                lit("Hello 
world".getBytes(StandardCharsets.UTF_8)).decode("utf-8"),
+                                "DECODE(x'" + EncodingUtils.hex("Hello world") 
+ "', 'utf-8')",
+                                "Hello world",
+                                DataTypes.STRING().notNull()));
     }
 
     // 
--------------------------------------------------------------------------------------------

Reply via email to