jose-torres commented on a change in pull request #23747: [SPARK-26848][SQL]
Introduce new option to Kafka source: offset by timestamp (starting/ending)
URL: https://github.com/apache/spark/pull/23747#discussion_r266589989
##########
File path:
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaOffsetReader.scala
##########
@@ -179,6 +179,56 @@ private[kafka010] class KafkaOffsetReader(
KafkaSourceOffset(fetched)
}
+ def fetchSpecificTimestampBasedOffsets(topicTimestamps: Map[String, Long]):
KafkaSourceOffset = {
+ val fetched = runUninterruptibly {
+ withRetriesWithoutInterrupt {
+ // Poll to get the latest assigned partitions
+ consumer.poll(0)
+ val partitions = consumer.assignment()
+
+ // Call `position` to wait until the potential offset request
triggered by `poll(0)` is
+ // done. This is a workaround for KAFKA-7703, which an async
`seekToBeginning` triggered by
+ // `poll(0)` may reset offsets that should have been set by another
request.
+ partitions.asScala.map(p => p -> consumer.position(p)).foreach(_ => {})
+
+ consumer.pause(partitions)
+
+ val assignedTopics = partitions.asScala.map(_.topic())
+ assert(assignedTopics == topicTimestamps.keySet,
+ "If starting/endingOffsetsByTimestamp contains specific offsets, you
must specify all " +
+ s"topics. Specified: ${topicTimestamps.keySet} Assigned:
$assignedTopics")
Review comment:
I'm never opposed to more tests :)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]