raminqaf commented on code in PR #29311:
URL: https://github.com/apache/flink/pull/29311#discussion_r4152654448
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java:
##########
@@ -432,6 +435,201 @@ private static List<TestSetSpec> variantPrimitiveCasts() {
TINYINT()));
}
+ private static List<TestSetSpec> primitiveToVariantCasts() {
+ final VariantBuilder builder = Variant.newBuilder();
+ final LocalDateTime nanos =
LocalDateTime.parse("2026-09-25T10:15:30.123456789");
+ final Instant instant = Instant.parse("2026-09-25T10:15:30.123Z");
+ return List.of(
+ // A value keeps the kind of its SQL type, so an integer keeps
its width, and a
+ // string is wrapped rather than parsed.
+ CastTestSpecBuilder.testCastTo(VARIANT())
+ .fromCase(BOOLEAN(), true, builder.of(true))
+ .fromCase(INT(), 42, builder.of(42))
+ .fromCase(BIGINT(), 1L, builder.of(1L))
+ .fromCase(BIGINT(), 10000000000L,
builder.of(10000000000L))
+ .fromCase(DOUBLE(), 1.5d, builder.of(1.5d))
+ .fromCase(
+ DECIMAL(4, 2),
+ new BigDecimal("12.50"),
+ builder.of(new BigDecimal("12.50")))
+ .fromCase(STRING(), "{\"a\":1}",
builder.of("{\"a\":1}"))
+ .fromCase(
+ DATE(),
+ LocalDate.parse("2026-09-25"),
+ builder.of(LocalDate.parse("2026-09-25")))
+ .fromCase(TIMESTAMP(9), nanos, builder.of(nanos))
+ .fromCase(TIMESTAMP_LTZ(3), instant,
builder.of(instant))
+ .fromCase(UUID(), DEFAULT_UUID,
builder.of(DEFAULT_UUID))
+ .fromCase(INT(), null, null)
+ // a type without a VARIANT kind is rejected at
validation
+ .failValidation(INTERVAL(MONTH()), Period.ofMonths(2))
+ .build(),
+ TestSetSpec.forExpression("Cast a primitive to VARIANT and
back")
Review Comment:
Added round trips for TINYINT, SMALLINT, `CHAR(4)`, and `BINARY(4)`.
`CHAR(n)` keeps its trailing spaces, since the padded value is what gets
stored: `'ab'` as `CHAR(4)` comes back as `'ab '`, both as STRING and as
`CHAR(4)`. `BINARY(4)` keeps its zero padding.
--
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]