MartijnVisser commented on code in PR #348:
URL: 
https://github.com/apache/flink-connector-kafka/pull/348#discussion_r4770293875


##########
flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicSource.java:
##########
@@ -534,12 +534,14 @@ private KafkaRecordDeserializationSchema<RowData> 
createKafkaDeserializationSche
         final int adjustedPhysicalArity =
                 DataType.getFieldDataTypes(producedDataType).size() - 
metadataKeys.size();
 
-        // adjust value format projection to include value format's metadata 
columns at the end
+        // adjust value format projection to include value format's metadata 
columns at the end;
+        // they follow the physical columns, which key and value projections 
may share when
+        // 'value.fields-include' is ALL
         final int[] adjustedValueProjection =
                 IntStream.concat(
                                 IntStream.of(valueProjection),
                                 IntStream.range(
-                                        keyProjection.length + 
valueProjection.length,
+                                        
DataType.getFieldCount(physicalDataType),

Review Comment:
   On main this is worse than NULL: same-typed metadata shift right by the 
number of key fields (`value.source.table` returns the database name), and 
mixed types throw a ClassCastException, which your ALL case hits. Could you say 
so in the commit message?



##########
flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaTableITCase.java:
##########
@@ -1113,6 +1113,68 @@ void testKafkaSourceSinkWithKeyAndFullValue(final String 
format) throws Exceptio
         cleanupTopic(topic);
     }
 
+    @ParameterizedTest(name = "value.fields-include: {0}")
+    @ValueSource(strings = {"ALL", "EXCEPT_KEY"})
+    void testValueFormatMetadataWithKeyFields(final String valueFieldsInclude) 
throws Exception {
+        tEnv.getConfig().set(TableConfigOptions.LOCAL_TIME_ZONE, "UTC");
+        final String topic = "value_format_metadata_topic_" + 
UUID.randomUUID();
+        createTestTopic(topic, 1, 1);
+        final String bootstraps = getBootstrapServers();
+        final String groupId = getStandardProps().getProperty("group.id");
+
+        // write the key and the Debezium value as raw bytes
+        tEnv.executeSql(
+                String.format(
+                        "CREATE TABLE raw_writer (\n"
+                                + "  `k` STRING,\n"
+                                + "  `v` STRING\n"
+                                + ") WITH (\n"
+                                + "  'connector' = 'kafka',\n"
+                                + "  'topic' = '%s',\n"
+                                + "  'properties.bootstrap.servers' = '%s',\n"
+                                + "  'key.format' = 'raw',\n"
+                                + "  'key.fields' = 'k',\n"
+                                + "  'value.format' = 'raw',\n"
+                                + "  'value.fields-include' = 'EXCEPT_KEY'\n"
+                                + ")",
+                        topic, bootstraps));
+        tEnv.executeSql(
+                        "INSERT INTO raw_writer VALUES ('{\"id\":1}', "
+                                + 
"'{\"before\":null,\"after\":{\"id\":1,\"name\":\"a\"},"
+                                + 
"\"source\":{\"ts_ms\":1700000000000,\"db\":\"inventory\"},"
+                                + "\"op\":\"c\"}')")
+                .await();
+
+        tEnv.executeSql(
+                String.format(
+                        "CREATE TABLE kafka (\n"
+                                + "  `id` INT,\n"
+                                + "  `name` STRING,\n"
+                                + "  `src_ts` TIMESTAMP_LTZ(3) METADATA FROM 
'value.source.timestamp' VIRTUAL,\n"
+                                + "  `src_db` STRING METADATA FROM 
'value.source.database' VIRTUAL\n"

Review Comment:
   Might make sense to add a connector metadata column such as `offset` here 
and in the dynamic test, to cover the boundary with connector metadata too.



-- 
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