-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26848][SQL][SS] Introduce new option to Kafka source: offset by timestamp (starting/ending) #23747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-26848][SQL][SS] Introduce new option to Kafka source: offset by timestamp (starting/ending) #23747
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,20 +68,35 @@ private object JsonUtils { | |
| partOffsets.map { case (part, offset) => | ||
| new TopicPartition(topic, part) -> offset | ||
| } | ||
| }.toMap | ||
| } | ||
| } catch { | ||
| case NonFatal(x) => | ||
| throw new IllegalArgumentException( | ||
| s"""Expected e.g. {"topicA":{"0":23,"1":-1},"topicB":{"0":-2}}, got $str""") | ||
| } | ||
| } | ||
|
|
||
| def partitionTimestamps(str: String): Map[TopicPartition, Long] = { | ||
| try { | ||
| Serialization.read[Map[String, Map[Int, Long]]](str).flatMap { case (topic, partTimestamps) => | ||
| partTimestamps.map { case (part, timestamp) => | ||
| new TopicPartition(topic, part) -> timestamp | ||
| } | ||
| } | ||
| } catch { | ||
| case NonFatal(x) => | ||
| throw new IllegalArgumentException( | ||
| s"""Expected e.g. {"topicA": {"0": 123456789, "1": 123456789}, | ||
| |"topicB": {"0": 123456789, "1": 123456789}}, got $str""".stripMargin) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Write per-TopicPartition offsets as json string | ||
| */ | ||
| def partitionOffsets(partitionOffsets: Map[TopicPartition, Long]): String = { | ||
| val result = new HashMap[String, HashMap[Int, Long]]() | ||
| implicit val ordering = new Ordering[TopicPartition] { | ||
| implicit val order = new Ordering[TopicPartition] { | ||
| override def compare(x: TopicPartition, y: TopicPartition): Int = { | ||
| Ordering.Tuple2[String, Int].compare((x.topic, x.partition), (y.topic, y.partition)) | ||
| } | ||
|
|
@@ -95,4 +110,9 @@ private object JsonUtils { | |
| } | ||
| Serialization.write(result) | ||
| } | ||
|
|
||
| def partitionTimestamps(topicTimestamps: Map[TopicPartition, Long]): String = { | ||
|
||
| // For now it's same as partitionOffsets | ||
| partitionOffsets(topicTimestamps) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.