Skip to content

Commit c3426f2

Browse files
committed
[FLINK-38841][table] Enforce expected nullability in FamilyArgumentStrategy
1 parent 4690f27 commit c3426f2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/FamilyArgumentTypeStrategy.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,16 @@ public Optional<DataType> inferArgumentType(
8686
if (Objects.equals(expectedNullability, Boolean.FALSE) && actualType.isNullable()) {
8787
return callContext.fail(
8888
throwOnFailure,
89-
"Unsupported argument type. Expected nullable type of family '%s' but actual type was '%s'.",
89+
"Unsupported argument type. Expected NOT NULL type of family '%s' but actual type was '%s'.",
9090
expectedFamily,
9191
actualType);
9292
}
9393

9494
// type is part of the family
9595
if (actualType.getTypeRoot().getFamilies().contains(expectedFamily)) {
96+
if (Objects.equals(expectedNullability, Boolean.TRUE) && !actualType.isNullable()) {
97+
return Optional.of(actualDataType.nullable());
98+
}
9699
return Optional.of(actualDataType);
97100
}
98101

flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/inference/InputTypeStrategiesTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,23 +549,33 @@ ANY, explicit(DataTypes.INT())
549549
sequence(
550550
logical(LogicalTypeFamily.CHARACTER_STRING, true),
551551
logical(LogicalTypeFamily.EXACT_NUMERIC),
552+
logical(LogicalTypeFamily.EXACT_NUMERIC, true),
552553
logical(LogicalTypeFamily.APPROXIMATE_NUMERIC),
553554
logical(LogicalTypeFamily.APPROXIMATE_NUMERIC),
554555
logical(LogicalTypeFamily.APPROXIMATE_NUMERIC, false)))
555556
.calledWithArgumentTypes(
556557
DataTypes.NULL(),
557558
DataTypes.TINYINT(),
559+
DataTypes.SMALLINT().notNull(),
558560
DataTypes.INT(),
559561
DataTypes.BIGINT().notNull(),
560562
DataTypes.DECIMAL(10, 2).notNull())
561563
.expectSignature(
562-
"f(<CHARACTER_STRING NULL>, <EXACT_NUMERIC>, <APPROXIMATE_NUMERIC>, <APPROXIMATE_NUMERIC>, <APPROXIMATE_NUMERIC NOT NULL>)")
564+
"f(<CHARACTER_STRING NULL>, <EXACT_NUMERIC>, <EXACT_NUMERIC NULL>, <APPROXIMATE_NUMERIC>, <APPROXIMATE_NUMERIC>, <APPROXIMATE_NUMERIC NOT NULL>)")
563565
.expectArgumentTypes(
564566
DataTypes.VARCHAR(1),
565567
DataTypes.TINYINT(),
568+
DataTypes.SMALLINT(),
566569
DataTypes.DOUBLE(), // widening with preserved nullability
567570
DataTypes.DOUBLE().notNull(), // widening with preserved nullability
568571
DataTypes.DOUBLE().notNull()),
572+
TestSpec.forStrategy(
573+
"Logical type family with invalid nullability",
574+
sequence(logical(LogicalTypeFamily.EXACT_NUMERIC, false)))
575+
.calledWithArgumentTypes(DataTypes.INT())
576+
.expectSignature("f(<EXACT_NUMERIC NOT NULL>)")
577+
.expectErrorMessage(
578+
"Unsupported argument type. Expected NOT NULL type of family 'EXACT_NUMERIC' but actual type was 'INT'."),
569579
TestSpec.forStrategy(
570580
"Logical type family with invalid type",
571581
sequence(logical(LogicalTypeFamily.EXACT_NUMERIC)))

0 commit comments

Comments
 (0)