【发布时间】:2019-07-19 01:02:57
【问题描述】:
来自 Kafka-console-producer 的 JSON 字节数据流 PySpark - 有一个解析器 json 数据到数据帧。
我试图通过使用给定的模式来解析这个 json。但是它给了我一个关于“AssertionError:keyType 应该是 DataType”的错误 使用自定义模式解析 json 需要做什么?
schema = StructType()\
.add("contact_id", LongType())\
.add("first_name", StringType())\
.add("last_name", StringType())\
.add("contact_number", MapType(StringType,
StructType()
.add("home", LongType())
.add("contry_code", StringType())))
期待这种格式的 JSON 数据: {"contact_id":"23","first_name":"John","last_name":"Doe","contact_number":{"home":4564564567,"country_code":"+1"}}
【问题讨论】:
标签: json pyspark pyspark-sql