Spark Scala-更新/添加Json对象中的新列并使用新的数据框值更新 [英] Spark scala - update/add new column in Json object and update with new dataframe value

查看:982
本文介绍了Spark Scala-更新/添加Json对象中的新列并使用新的数据框值更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用另一个json对象的内容更新现有json对象中的对象数组.

I want to update an array of objects within an existing json object with the content from another json object.

初始对象:

{
    "user": "gT35Hhhre9m",
    "date": "2016-01-29",
    "status": "OK",
    "reason": "some reason",
    "content": [
        {
            "foo": 123,
            "bar": "val1"
        }
    ]
}

补充对象:

{
    "id": "gT35Hhhre9m"
}

合并后对象结构:

{
    "user": "gT35Hhhre9m",
    "date": "2016-01-29",
    "status": "OK",
    "reason": "some reason",
    "content": [{
        "foo": 123,
        "bar": "val1"
        "id": "gT35Hhhre9m"
    }]
}

推荐答案

  1. 展开初始对象",并将Spark数据帧视为柱状 数据类似于SQL表.
  2. 完成转换
  3. 转换为JSON作为Spark数据框.
  1. Flatten the "Initial object" and treat Spark dataframes as columnar data similar to a SQL table.
  2. Complete transformations
  3. Convert back to Spark dataframes as JSON.

不要将数据帧视为JSON是窍门.

Not thinking dataframe as JSON is the trick.

这篇关于Spark Scala-更新/添加Json对象中的新列并使用新的数据框值更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆