【发布时间】:2017-02-10 00:51:09
【问题描述】:
我正在研究 DataBricks (Spark 2.0.1-db1 (Scala 2.11)),我正在尝试使用 Spark Streaming 函数。我正在使用这些库:
- spark-sql-streaming-mqtt_2.11-2.1.0-SNAPSHOT.jar(见这里:http://bahir.apache.org/docs/spark/current/spark-sql-streaming-mqtt/)
以下命令给了我一个数据集:
val lines = spark.readStream
.format("org.apache.bahir.sql.streaming.mqtt.MQTTStreamSourceProvider")
.option("clientId", "sparkTest")
.option("brokerUrl", "tcp://xxx.xxx.xxx.xxx:xxx")
.option("topic", "/Name/data")
.option("localStorage", "dbfs:/models/mqttPersist")
.option("cleanSession", "true")
.load().as[(String, Timestamp)]
使用此 printSchema:
root
|-- value : string (nullable : true)
|-- timestamp : timestamp (nullable : true)
我想在我的数据集的“值”列上应用一个模式。你可以看到我的 json 架构如下。
root
|-- id : string (nullable = true)
|-- DateTime : timestamp (nullable = true)
|-- label : double (nullable = true)
是否可以直接在流中解析我的 json 以获得类似的东西:
root
|-- value : struct (nullable : true)
|-- id : string (nullable = true)
|-- DateTime : timestamp (nullable = true)
|-- label : double (nullable = true)
|-- timestamp : timestamp (nullable : true)
目前,我没有看到任何从 mqtt 解析 json 的方法,任何帮助都会非常好。
提前致谢。
【问题讨论】:
标签: json apache-spark streaming mqtt