PatrickRen commented on code in PR #20370: URL: https://github.com/apache/flink/pull/20370#discussion_r1031176628
########## flink-connectors/flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/enumerator/KafkaSourceEnumerator.java: ########## @@ -612,6 +612,10 @@ public Map<TopicPartition, OffsetAndTimestamp> offsetsForTimes( OffsetSpec.forTimestamp( entry.getValue())))) .entrySet().stream() + // OffsetAndTimestamp cannot be initialized with a negative offset, which is + // possible if the timestamp does not correspond to an offset and the topic + // partition is empty + .filter(entry -> entry.getValue().offset() != -1) Review Comment: nit: What about `entry.getValue().offset() >= 0`? ########## flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/source/enumerator/initializer/OffsetsInitializerTest.java: ########## @@ -107,7 +111,19 @@ public void testTimestampOffsetsInitializer() { long expectedOffset = tp.partition() > 2 ? tp.partition() : 3L; assertThat((long) offset).isEqualTo(expectedOffset); }); - assertThat(initializer.getAutoOffsetResetStrategy()).isEqualTo(OffsetResetStrategy.NONE); + assertThat(initializer.getAutoOffsetResetStrategy()).isEqualTo(OffsetResetStrategy.LATEST); + } + + @Test + public void testTimestampOffsetsInitializerForEmptyPartitions() { + OffsetsInitializer initializer = OffsetsInitializer.timestamp(2001); + List<TopicPartition> partitions = KafkaSourceTestEnv.getPartitionsForTopic(EMPTY_TOPIC3); + Map<TopicPartition, Long> expectedOffsets = + partitions.stream().collect(Collectors.toMap(tp -> tp, tp -> 0L)); + assertThat(initializer.getPartitionOffsets(partitions, retriever)) + .as("offsets are equal equal to 0 since the timestamp is out of range.") Review Comment: typo: "are equal ~~equal~~ to" -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org