Github user zsxwing commented on a diff in the pull request:
https://github.com/apache/spark/pull/4229#discussion_r34662049
--- Diff:
external/mqtt/src/main/scala/org/apache/spark/streaming/mqtt/MQTTUtils.scala ---
@@ -74,3 +75,24 @@ object MQTTUtils {
createStream(jssc.ssc, brokerUrl, topic, storageLevel)
}
}
+
+/**
+ * This is a helper class that wraps the methods in MQTTUtils into more
Python-friendly class and
+ * function so that it can be easily instantiated and called from Python's
MQTTUtils.
+ */
+private class MQTTUtilsPythonHelper {
+
+ def createStream(
+ jssc: JavaStreamingContext,
+ brokerUrl: String,
+ topic: String,
+ storageLevel: StorageLevel
+ ): JavaDStream[Array[Byte]] = {
+ val dstream = MQTTUtils.createStream(jssc, brokerUrl, topic,
storageLevel)
+ dstream.map(new Function[String, Array[Byte]] {
+ override def call(data: String): Array[Byte] = {
+ data.getBytes("UTF-8")
--- End diff --
You don't need to convert to bytes. PythonRDD will do it. You can pass a
Sting DStream and use `UTF8Deserializer` in Python directly.
---
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]