【问题标题】:Writing nested JSON in spark scala在 Spark Scala 中编写嵌套 JSON
【发布时间】:2016-07-19 10:54:52
【问题描述】:

我的 Spark-SQL 正在通过连接两个具有一对多基数的表来生成查询输出。我必须将数据转换为 JSON。 这就是查询输出的样子。

Address_id_parent | Address_id_child | Country_child | city_child
1                 |      1           |     India     |    Delhi
1                 |      1           |     US        |    NewYork
1                 |      1           |     US        |    NewJersey

以上数据都要这样转成JSON。

{
    "Address": {
        "Address_id_parent": "1"
    },
    "Address-details": [{
        "Address_id_child": "1",
        "location": [{
                 "country":"India",
                 "city":"Delhi",
                },
                {
                 "country":"US",
                 "city":"NewYork",
                },
                {
                 "country":"US",
                 "city":"NewJersey",
                }
                ]
    }]
}

我怎样才能做到这一点?

【问题讨论】:

  • 在 spark scala 中实现了吗?

标签: json scala apache-spark apache-spark-sql


【解决方案1】:

用json检查Dataframe写入接口:

df.write.format("json").save(path)

【讨论】:

  • 怎么能反过来呢?并以非规范化形式将其放入表中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-09
  • 2020-12-30
  • 2019-05-29
  • 2019-03-17
  • 2014-07-12
  • 1970-01-01
相关资源
最近更新 更多