This is an automated email from the ASF dual-hosted git repository.
twalthr 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 5e4ae60590d [FLINK-38553][table-planner] CastRuleProvider should treat
identity casts with highest precedence
5e4ae60590d is described below
commit 5e4ae60590df83df8c35d5fbc0a3584dd1623372
Author: Timo Walther <[email protected]>
AuthorDate: Thu Oct 23 23:43:14 2025 +0200
[FLINK-38553][table-planner] CastRuleProvider should treat identity casts
with highest precedence
This closes #27142.
---
.../table/planner/functions/casting/CastRuleProvider.java | 5 +++--
.../planner/functions/casting/CastRuleProviderTest.java | 13 +++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git
a/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CastRuleProvider.java
b/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CastRuleProvider.java
index b3f879a8aaf..b1a050cd744 100644
---
a/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CastRuleProvider.java
+++
b/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CastRuleProvider.java
@@ -48,6 +48,8 @@ public class CastRuleProvider {
static {
INSTANCE
+ // Highest precedence rule
+ .addRule(IdentityCastRule.INSTANCE)
// Numeric rules
.addRule(DecimalToDecimalCastRule.INSTANCE)
.addRule(NumericPrimitiveToDecimalCastRule.INSTANCE)
@@ -96,8 +98,7 @@ public class CastRuleProvider {
.addRule(VariantToStringCastRule.INSTANCE)
// Special rules
.addRule(CharVarCharTrimPadCastRule.INSTANCE)
- .addRule(NullToStringCastRule.INSTANCE)
- .addRule(IdentityCastRule.INSTANCE);
+ .addRule(NullToStringCastRule.INSTANCE);
}
/* ------- Entrypoint ------- */
diff --git
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRuleProviderTest.java
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRuleProviderTest.java
index af4b63d9ce6..4e230667111 100644
---
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRuleProviderTest.java
+++
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRuleProviderTest.java
@@ -28,9 +28,11 @@ import org.apache.flink.table.types.logical.VarCharType;
import org.junit.jupiter.api.Test;
import static org.apache.flink.table.api.DataTypes.BIGINT;
+import static org.apache.flink.table.api.DataTypes.FIELD;
import static org.apache.flink.table.api.DataTypes.INT;
import static org.apache.flink.table.api.DataTypes.ROW;
import static org.apache.flink.table.api.DataTypes.STRING;
+import static org.apache.flink.table.api.DataTypes.STRUCTURED;
import static org.apache.flink.table.api.DataTypes.TIME;
import static org.apache.flink.table.api.DataTypes.TINYINT;
import static org.apache.flink.table.types.logical.VarCharType.STRING_TYPE;
@@ -46,6 +48,10 @@ class CastRuleProviderTest {
.build();
private static final LogicalType INT = INT().getLogicalType();
private static final LogicalType TINYINT = TINYINT().getLogicalType();
+ private static final LogicalType ROW =
+ ROW(FIELD("a", INT()), FIELD("b",
TINYINT().notNull())).getLogicalType();
+ private static final LogicalType STRUCTURED =
+ STRUCTURED("Obj", FIELD("a", INT()), FIELD("b",
TINYINT().notNull())).getLogicalType();
@Test
void testResolveDistinctTypeToIdentityCastRule() {
@@ -55,6 +61,13 @@ class CastRuleProviderTest {
.isSameAs(IdentityCastRule.INSTANCE);
}
+ @Test
+ void testResolveCompatiblesTypesToIdentityCastRule() {
+ assertThat(CastRuleProvider.resolve(INT,
INT)).isSameAs(IdentityCastRule.INSTANCE);
+ assertThat(CastRuleProvider.resolve(ROW,
ROW)).isSameAs(IdentityCastRule.INSTANCE);
+ assertThat(CastRuleProvider.resolve(ROW,
STRUCTURED)).isSameAs(IdentityCastRule.INSTANCE);
+ }
+
@Test
void testResolveIntToBigIntWithDistinct() {
assertThat(CastRuleProvider.resolve(INT, DISTINCT_BIG_INT))