yijiacui-db commented on a change in pull request #31944:
URL: https://github.com/apache/spark/pull/31944#discussion_r612926596
##########
File path:
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaMicroBatchStream.scala
##########
@@ -218,3 +226,37 @@ private[kafka010] class KafkaMicroBatchStream(
}
}
}
+
+object KafkaMicroBatchStream extends Logging {
+
+ /**
+ * Compute the difference of offset per partition between
latestAvailablePartitionOffsets
+ * and latestConsumedPartitionOffsets.
+ * Because of rate limit, latest consumed offset per partition can be
smaller than
+ * the latest available offset per partition.
+ * @param latestConsumedOffset latest consumed offset
+ * @param latestAvailablePartitionOffsets latest available offset per
partition
+ * @return the generated metrics map
+ */
+ def metrics(
+ latestConsumedOffset: Optional[Offset],
+ latestAvailablePartitionOffsets: PartitionOffsetMap): ju.Map[String,
String] = {
+ val offset = Option(latestConsumedOffset.orElse(null))
+
+ if (offset.nonEmpty) {
+ val consumedPartitionOffsets =
offset.map(KafkaSourceOffset(_)).get.partitionToOffsets
Review comment:
Yes. LatestConsumedOffset can be None, and it will skip the case. This
is checked by offset.nonEmpty.
Also this is the test for checking latestConsumedOffset to be none case:
https://github.com/apache/spark/pull/31944/files#diff-4ddf27dccbb57c9b29179090d9430bbbd3d1bc8d57ab8100901fb45971d23810R1395
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]