【发布时间】:2020-03-07 15:52:06
【问题描述】:
我正在尝试使用来自 binance websocket 的 json 数据。
现在我的架构看起来像这样:
val schema = new StructType()
.add("e",StringType)
.add("E",StringType)
.add("s",StringType)
.add("k",StringType)
.add("t",IntegerType)
.add("T",IntegerType)
.add("s",StringType)
.add("i",StringType)
.add("f",StringType)
.add("L",StringType)
.add("o",DoubleType)
.add("c",DoubleType)
.add("h",DoubleType)
.add("l",DoubleType)
.add("v",DoubleType)
.add("n",IntegerType)
.add("x",StringType)
.add("q",DoubleType)
.add("V",DoubleType)
.add("Q",DoubleType)
.add("B",StringType)
我从我的 kafka 主题中收到这条消息:
{"e":"kline","E":1583595170076,"s":"BTCUSDT","k":{"t":1583595120000,"T":1583595179999,"s":"BTCUSDT","i":"1m","f":47069029,"L":47069101,"o":"9111.22","c":"9114.90","h":"9114.91","l":"9109.65","v":"30.297","n":73,"x":false,"q":"276055.09390","V":"11.517","Q":"104946.56519","B":"0"}}
如您所见,消息嵌套在“k”键下。
我在 spark 中的输出目前看起来像这样:
root
|-- key: binary (nullable = true)
|-- value: binary (nullable = true)
|-- topic: string (nullable = true)
|-- partition: integer (nullable = true)
|-- offset: long (nullable = true)
|-- timestamp: timestamp (nullable = true)
|-- timestampType: integer (nullable = true)
-------------------------------------------
https://imgur.com/a/9LPu9z6
数据框的图像,因为我无法在不破坏框架的情况下将其粘贴到论坛中。
【问题讨论】:
标签: scala apache-spark