拥有Dataset<Row>
单列 json 字符串:
+--------------------+
| value|
+--------------------+
|{"Context":"00AA0...|
+--------------------+
json示例:
{"Context":"00AA00AA","MessageType":"1010","Module":"1200"}
我怎样才能最有效地得到Dataset<Row>
这样的:
+--------+-----------+------+
| Context|MessageType|Module|
+--------+-----------+------+
|00AA00AA| 1010| 1200|
+--------+-----------+------+
我正在流中处理这些数据,我知道当我从文件中读取数据时,spark 可以自己执行此操作:
spark
.readStream()
.schema(MyPojo.getSchema())
.json("src/myinput")
但现在我正在从 kafka 读取数据,它以另一种形式为我提供数据。我知道我可以使用像 Gson 这样的解析器,但我想让 spark 为我做这件事。