Savonitar commented on code in PR #348:
URL:
https://github.com/apache/flink-connector-kafka/pull/348#discussion_r4701775346
##########
flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/DynamicKafkaTableITCase.java:
##########
@@ -187,6 +191,73 @@ void testDynamicKafkaSource() throws Exception {
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 = "dynamic_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 dynamic_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"
+ + ") WITH (\n"
+ + " 'connector' = '%s',\n"
+ + " 'stream-ids' = '%s',\n"
+ + " 'metadata-service' = 'single-cluster',\n"
+ + " 'metadata-service.cluster-id' =
'cluster-0',\n"
+ + " 'properties.bootstrap.servers' = '%s',\n"
+ + " 'properties.group.id' = '%s',\n"
+ + " 'scan.startup.mode' =
'earliest-offset',\n"
+ + " 'key.format' = 'json',\n"
+ + " 'key.fields' = 'id',\n"
+ + " 'value.format' = 'debezium-json',\n"
+ + " 'value.fields-include' = '%s'\n"
+ + ")",
+ DynamicKafkaTableFactory.IDENTIFIER,
+ topic,
+ bootstraps,
+ groupId,
+ valueFieldsInclude));
+
+ final List<Row> result = collectRows(tEnv.sqlQuery("SELECT * FROM
dynamic_kafka"), 1);
Review Comment:
same
https://github.com/apache/flink-connector-kafka/pull/348/changes#r4701761865 ?
##########
flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaTableITCase.java:
##########
@@ -1113,6 +1113,67 @@ 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"
+ + ") WITH (\n"
+ + " 'connector' = 'kafka',\n"
+ + " 'topic' = '%s',\n"
+ + " 'properties.bootstrap.servers' = '%s',\n"
+ + " 'properties.group.id' = '%s',\n"
+ + " 'scan.startup.mode' =
'earliest-offset',\n"
+ + " 'key.format' = 'json',\n"
+ + " 'key.fields' = 'id',\n"
+ + " 'value.format' = 'debezium-json',\n"
+ + " 'value.fields-include' = '%s'\n"
+ + ")",
+ topic, bootstraps, groupId, valueFieldsInclude));
+
+ final List<Row> result = collectRows(tEnv.sqlQuery("SELECT * FROM
kafka"), 1);
Review Comment:
Both tests finish writing before the reader starts.
Consider setting 'scan.bounded.mode' = 'latest-offset' and using
collectAllRows(...) in both. With collectRows(..., 1), containsExactly misses a
second row and the test can keep waiting if decoding emits nothing.
That creates two possible outcomes:
1.If the connector emits the row twice, the test still passes because
containsExactly only sees the first copy.
2. If the connector consumes the record and emits nothing, the test can wait
until CI times out instead of reporting an empty result.
Or am I missing something?
--
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]