Fabian Paul created FLINK-39201:
-----------------------------------

             Summary: Length constraints cannot handle null values
                 Key: FLINK-39201
                 URL: https://issues.apache.org/jira/browse/FLINK-39201
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.1.1
            Reporter: Fabian Paul


When dealing with nullable columns that have a length constraint writing fails 
with a NPE because the constraint enforcer cannot be applied to null values.

As basic reproduction is
{code:java}
    @Test
    void testCharLengthEnforcerNpeOnNullableColumn()
            throws ExecutionException, InterruptedException {
        final StreamTableEnvironment tableEnv = 
StreamTableEnvironment.create(env);
        // Row 2 has null values in the nullable CHAR(8), CHAR(6), and 
VARCHAR(6) columns
        final List<Row> rows =
                Arrays.asList(
                        Row.of(1, "Apache Flink", "SQL RuleZ", 11, 111, "SQL"),
                        Row.of(2, null, null, 22, 222, null));        final 
SharedReference<List<RowData>> results = sharedObjects.add(new ArrayList<>());
        tableEnv.createTable(
                "T1",
                TableFactoryHarness.newBuilder()
                        .schema(schemaForCharLengthEnforcer())
                        .source(new TestSource(rows))
                        .sink(buildRuntimeSinkProvider(new 
RecordWriter(results)))
                        .build());        tableEnv.getConfig()
                .set(
                        TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER.key(),
                        
ExecutionConfigOptions.TypeLengthEnforcer.TRIM_PAD.name());        
assertThatThrownBy(
                        () ->
                                tableEnv.executeSql("INSERT INTO T1 SELECT * 
FROM T1")
                                        .await())
                .isInstanceOf(ExecutionException.class)
                .satisfies(anyCauseMatches(NullPointerException.class));
    }
 {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to