gustavodemorais commented on code in PR #27603:
URL: https://github.com/apache/flink/pull/27603#discussion_r2816073876


##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeCastsTest.java:
##########
@@ -273,4 +279,140 @@ void test(
                 .as("Supports explicit casting")
                 .isEqualTo(supportsExplicit);
     }
+
+    /**
+     * Test data for injective cast tests. Each argument contains: 
(sourceType, targetType,
+     * expectedInjective).
+     */
+    private static Stream<Arguments> injectiveCastTestData() {
+        return Stream.of(
+                // Integer widenings are injective
+                Arguments.of(new SmallIntType(), new BigIntType(), true),
+                Arguments.of(new IntType(), new BigIntType(), true),
+                Arguments.of(new TinyIntType(), new IntType(), true),
+                Arguments.of(new TinyIntType(), new SmallIntType(), true),
+
+                // Explicit casts to STRING from integer types are injective
+                Arguments.of(new TinyIntType(), VarCharType.STRING_TYPE, true),
+                Arguments.of(new SmallIntType(), VarCharType.STRING_TYPE, 
true),
+                Arguments.of(new IntType(), VarCharType.STRING_TYPE, true),
+                Arguments.of(new BigIntType(), VarCharType.STRING_TYPE, true),
+
+                // FLOAT/DOUBLE to STRING are injective
+                Arguments.of(new FloatType(), VarCharType.STRING_TYPE, true),
+                Arguments.of(new DoubleType(), VarCharType.STRING_TYPE, true),
+
+                // Explicit casts to STRING from boolean are injective
+                Arguments.of(new BooleanType(), VarCharType.STRING_TYPE, true),
+
+                // Explicit casts to STRING from date/time types are injective
+                Arguments.of(new DateType(), VarCharType.STRING_TYPE, true),
+                Arguments.of(new TimestampType(3), VarCharType.STRING_TYPE, 
true),
+                Arguments.of(new TimestampType(9), VarCharType.STRING_TYPE, 
true),
+                Arguments.of(new LocalZonedTimestampType(3), 
VarCharType.STRING_TYPE, true),
+                Arguments.of(new ZonedTimestampType(3), 
VarCharType.STRING_TYPE, true),
+
+                // Explicit casts to CHAR are also injective for the same 
source types
+                Arguments.of(new IntType(), new CharType(100), true),
+                Arguments.of(new BigIntType(), new CharType(100), true),
+
+                // CHAR → VARCHAR widening is injective
+                Arguments.of(new CharType(10), VarCharType.STRING_TYPE, true),
+
+                // BINARY → VARBINARY widening is injective
+                Arguments.of(new BinaryType(10), new VarBinaryType(100), true),
+
+                // Integer → DECIMAL is injective (exact representation)
+                Arguments.of(new TinyIntType(), new DecimalType(10, 0), true),
+                Arguments.of(new SmallIntType(), new DecimalType(10, 0), true),
+                Arguments.of(new IntType(), new DecimalType(10, 0), true),
+                Arguments.of(new BigIntType(), new DecimalType(20, 0), true),
+
+                // DECIMAL → DECIMAL identity is injective
+                Arguments.of(new DecimalType(10, 2), new DecimalType(10, 2), 
true),
+
+                // FLOAT → DOUBLE widening is injective
+                Arguments.of(new FloatType(), new DoubleType(), true),
+
+                // Narrowing casts are NOT injective (lossy)
+                Arguments.of(VarCharType.STRING_TYPE, new IntType(), false),
+                Arguments.of(new BigIntType(), new IntType(), false),
+                Arguments.of(new DoubleType(), new FloatType(), false),
+
+                // TIMESTAMP → DATE is NOT injective (loses time-of-day 
information)
+                // even though it is an implicit cast
+                Arguments.of(new TimestampType(3), new DateType(), false),
+
+                // DECIMAL to STRING is NOT considered injective
+                Arguments.of(new DecimalType(10, 2), VarCharType.STRING_TYPE, 
false),
+
+                // BYTES to STRING is NOT injective (invalid UTF-8 sequences 
collapse)
+                Arguments.of(new VarBinaryType(100), VarCharType.STRING_TYPE, 
false),
+                Arguments.of(new BinaryType(100), VarCharType.STRING_TYPE, 
false),
+
+                // TIME to STRING is NOT injective (not in the whitelist)
+                Arguments.of(new TimeType(3), VarCharType.STRING_TYPE, false),
+
+                // INT → FLOAT/DOUBLE are NOT injective (even though implicit)
+                // because floating point is not in the injective rules
+                Arguments.of(new IntType(), new FloatType(), false),
+                Arguments.of(new IntType(), new DoubleType(), false),

Review Comment:
   But I'll update the comment to communicate that



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to