【问题标题】:Unnesting multiple nested arrays into separate rows with AWS Glue ETL使用 AWS Glue ETL 将多个嵌套数组取消嵌套到单独的行中
【发布时间】:2018-05-23 15:02:24
【问题描述】:

我正在尝试使用 Python 在 AWS Glue 中取消嵌套 JSON 数组数组

示例数据结构如下:

{
    "country": "US",
    "states": [
        {
            "stateId": -8727116505311523857,
            "events": [
                {
                    "eventId": 9087712927864446976,
                    "name": "exampleName1",
                    "time": 1.515376892153E9,
                    "value": 0.0,
                    "parameters": {
                        "exampleparam1": "27"
                    }
                },
                {
                    "eventId": 7885892179028651008,
                    "name": "exampleName2",
                    "time": 1.515376892154E9,
                    "value": 0.0,
                    "parameters": {
                        "exampleparam1": "0",
                        "exampleparam2": "18",
                        "exampleparam3": "21303",
                        "exampleparam4": "27",
                        "exampleparam5": "2",
                        "exampleparam6": "2",
                        "exampleparam7": "3",
                        "exampleparam8": "18",
                        "exampleparam9": "1",
                        "exampleparam10": "12"
                    }
                }
            ]
        }
    ],
    "duration": 1853.938
}

我理想的结果是把每一行json拆分成多行,每一行包含所有的顶级数据,但是events数组中只有一个事件。

由于多层嵌套,unnest() 似乎不会有预期的效果。

提前感谢您的帮助。

【问题讨论】:

    标签: python arrays etl aws-glue


    【解决方案1】:

    您是否查看过this。我希望你正在寻找这样的东西来扁平化 json 文件和进程另外,请看一下这个,example for filtering data from nested JSONs

    【讨论】:

    • 我最终通过使用 explode() 解决了这个问题,然后将 states 列拆分为单独的 stateID 和 events 嵌套数组列。然后最后爆炸事件数组。感谢您的帮助!
    • @EricKeen 能分享一下代码吗,我也有类似需求,你的代码使用explode会有很大帮助
    • 抱歉,我们已经迁移到 GCP,这更容易处理。我手头没有遗留代码。
    猜你喜欢
    • 2018-07-19
    • 2015-08-22
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多