pratyakshsharma commented on a change in pull request #2438:
URL: https://github.com/apache/hudi/pull/2438#discussion_r830768428
##########
File path:
hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java
##########
@@ -283,6 +323,41 @@ private Long delayOffsetCalculation(Option<String>
lastCheckpointStr, Set<TopicP
return delayCount;
}
+ /**
+ * Get the checkpoint by timestamp.
+ * This method returns the checkpoint format based on the timestamp.
+ * example:
+ * 1. input: timestamp, etc.
+ * 2. output:
topicName,partition_num_0:100,partition_num_1:101,partition_num_2:102.
+ *
+ * @param consumer
+ * @param topicName
+ * @param timestamp
+ * @return
+ */
+ private Option<String> getOffsetsByTimestamp(KafkaConsumer consumer,
List<PartitionInfo> partitionInfoList, Set<TopicPartition> topicPartitions,
+ String topicName, Long
timestamp) {
+
+ Map<TopicPartition, Long> topicPartitionsTimestamp =
partitionInfoList.stream()
+ .map(x -> new
TopicPartition(x.topic(), x.partition()))
+
.collect(Collectors.toMap(Function.identity(), x -> timestamp));
+
+ Map<TopicPartition, Long> earliestOffsets =
consumer.beginningOffsets(topicPartitions);
+ Map<TopicPartition, OffsetAndTimestamp> offsetAndTimestamp =
consumer.offsetsForTimes(topicPartitionsTimestamp);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(topicName + ",");
+ for (Map.Entry<TopicPartition, OffsetAndTimestamp> map :
offsetAndTimestamp.entrySet()) {
+ if (map.getValue() != null) {
+
sb.append(map.getKey().partition()).append(":").append(map.getValue().offset()).append(",");
+ } else {
+
sb.append(map.getKey().partition()).append(":").append(earliestOffsets.get(map.getKey())).append(",");
Review comment:
created a jira for this - https://issues.apache.org/jira/browse/HUDI-3671
--
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]