DataType.fromJson() 错误:java.lang.IllegalArgumentException:无法将 JSON 字符串“int”转换为数据类型

2024-01-08

尝试从 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 结构或需要更改什么。


Type of LocationID应该integer not int.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DataType.fromJson() 错误:java.lang.IllegalArgumentException:无法将 JSON 字符串“int”转换为数据类型 的相关文章

随机推荐