Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/7185#discussion_r33973761
--- Diff: python/pyspark/streaming/kafka.py ---
@@ -244,3 +263,71 @@ def __init__(self, host, port):
def _jBroker(self, helper):
return helper.createBroker(self._host, self._port)
+
+
+class KafkaRDD(RDD):
+ """
+ A Python wrapper of KafkaRDD, to provide additional information on
normal RDD.
+ """
+
+ def __init__(self, jrdd, ctx, jrdd_deserializer):
+ RDD.__init__(self, jrdd, ctx, jrdd_deserializer)
+
+ def offsetRanges(self):
+ """
+ Get the OffsetRange of specific KafkaRDD.
+ :return: A list of OffsetRange
+ """
+ try:
+ helperClass =
self.ctx._jvm.java.lang.Thread.currentThread().getContextClassLoader() \
+
.loadClass("org.apache.spark.streaming.kafka.KafkaUtilsPythonHelper")
+ helper = helperClass.newInstance()
+ joffsetRanges = helper.offsetRangesOfKafkaRDD(self._jrdd.rdd())
+ except Py4JJavaError as e:
+ if 'ClassNotFoundException' in str(e.java_exception):
+ KafkaUtils._printErrorMsg(self.ctx)
+ raise e
+
+ offsets = [OffsetRange(o.topic(), o.partition(), o.fromOffset(),
o.untilOffset())
--- End diff --
offsets --> ranges
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]