尝试从 JSON 文件创建 StructType 以用作创建数据帧的模式。
JSON 结构:
{
"type" : "struct",
"fields" : [
{
"name" : "LocationID",
"type" : "int",
"nullable" : false,
"metadata" : { }
}, {
"name" : "Boroght",
"type" : "string",
"nullable" : true,
"metadata" : { }
}, {
"name" : "zone",
"type" : "string",
"nullable" : true,
"metadata" : { }
}, {
"name" : "serviceZone",
"type" : "string",
"nullable" : true,
"metadata" : { }
} ]
}
读取 JSON 文件并创建 StructType:
val schemaSource = Source.fromFile(url.getFile).mkString
val schemaFromJson = DataType.fromJson(schemaSource).asInstanceOf[StructType]
我不断收到错误:
java.lang.IllegalArgumentException: Failed to convert the JSON string 'int' to a data type.
不确定它是 JSON 结构还是在那里更改了什么。
类型的LocationID
应该integer
不是int
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句