This is an automated email from the ASF dual-hosted git repository.
gustavodemorais 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 8540dcb1b49 [FLINK-40410][table-planner] Exclude VARIANT from constant
folding
8540dcb1b49 is described below
commit 8540dcb1b492bbe895a4d2360bae137495a7d659
Author: Moritz Manner <[email protected]>
AuthorDate: Wed Aug 19 15:09:21 2026 +0200
[FLINK-40410][table-planner] Exclude VARIANT from constant folding
This closes #28991
---
.../table/planner/codegen/ExpressionReducer.scala | 2 +-
.../planner/functions/JsonFunctionsITCase.java | 37 +++++++++++++++++++++-
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git
a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExpressionReducer.scala
b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExpressionReducer.scala
index d41331309c3..3dc12b93000 100644
---
a/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExpressionReducer.scala
+++
b/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExpressionReducer.scala
@@ -274,7 +274,7 @@ class ExpressionReducer(
// we don't support object literals yet, we skip those constant
expressions
case (SqlTypeName.ANY, _) | (SqlTypeName.OTHER, _) | (SqlTypeName.ROW,
_) |
(SqlTypeName.STRUCTURED, _) | (SqlTypeName.ARRAY, _) |
(SqlTypeName.MAP, _) |
- (SqlTypeName.MULTISET, _) =>
+ (SqlTypeName.MULTISET, _) | (SqlTypeName.VARIANT, _) =>
None
case (_, call: RexCall) => {
diff --git
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java
index 65ffef63b2d..1301a73254f 100644
---
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java
+++
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/JsonFunctionsITCase.java
@@ -31,6 +31,8 @@ import org.apache.flink.table.data.StringData;
import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
import org.apache.flink.table.functions.ScalarFunction;
import org.apache.flink.types.Row;
+import org.apache.flink.types.variant.BinaryVariantInternalBuilder;
+import org.apache.flink.types.variant.Variant;
import org.apache.commons.io.IOUtils;
@@ -62,6 +64,7 @@ import static org.apache.flink.table.api.DataTypes.STRING;
import static org.apache.flink.table.api.DataTypes.TIMESTAMP;
import static
org.apache.flink.table.api.DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE;
import static org.apache.flink.table.api.DataTypes.VARBINARY;
+import static org.apache.flink.table.api.DataTypes.VARIANT;
import static org.apache.flink.table.api.Expressions.$;
import static org.apache.flink.table.api.Expressions.call;
import static org.apache.flink.table.api.Expressions.json;
@@ -1034,7 +1037,31 @@ class JsonFunctionsITCase extends
BuiltInFunctionTestBase {
jsonString(call("TRY_PARSE_JSON", $("f1"))),
"JSON_STRING(TRY_PARSE_JSON(f1))",
null,
- STRING()));
+ STRING()),
+ TestSetSpec.forFunction(
+ BuiltInFunctionDefinitions.PARSE_JSON,
+ "VARIANT expression preceding another
expression in a"
+ + " constant-folded projection")
+ .onFieldsWithData("{\"a\": 1}")
+ .andDataTypes(STRING().notNull())
+ .withConstantFoldingEnabled()
+ .testResult(
+ resultSpec(
+ call("PARSE_JSON", $("f0")),
+ "PARSE_JSON(f0)",
+ getVariantForJson("{\"a\": 1}"),
+ VARIANT().notNull(),
+ VARIANT().notNull()),
+ resultSpec(
+ jsonString(call("PARSE_JSON",
$("f0"))),
+ "JSON_STRING(PARSE_JSON(f0))",
+ "{\"a\":1}",
+ STRING().notNull(),
+ STRING().notNull()))
+ .testSqlResult(
+ "PARSE_JSON(f0), JSON_STRING(PARSE_JSON(f0))",
+ List.of(getVariantForJson("{\"a\": 1}"),
"{\"a\":1}"),
+ List.of(VARIANT().notNull(),
STRING().notNull())));
}
private static List<TestSetSpec> jsonSpec() {
@@ -2242,4 +2269,12 @@ class JsonFunctionsITCase extends
BuiltInFunctionTestBase {
throw new RuntimeException(e);
}
}
+
+ private static Variant getVariantForJson(String json) {
+ try {
+ return BinaryVariantInternalBuilder.parseJson(json, false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}