【问题标题】:How to flatten two json arrays using apache drill如何使用 apache Drill 展平两个 json 数组
【发布时间】:2017-12-19 07:55:29
【问题描述】:
{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55,
    "batters":
        {
            "batter":
                [
                    { "id": "1001", "type": "Regular" },
                    { "id": "1002", "type": "Chocolate" },
                    { "id": "1003", "type": "Blueberry" },
                    { "id": "1004", "type": "Devil's Food" }
                ]
        },
    "topping":
        [
            { "id": "5001", "type": "None" },
            { "id": "5002", "type": "Glazed" },
            { "id": "5005", "type": "Sugar" },
            { "id": "5007", "type": "Powdered Sugar" },
            { "id": "5006", "type": "Chocolate with Sprinkles" },
            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
}

我有上面的 json,我想同时展平 battertopping 数组。

所以我试着做:

SELECT flatten(topping) as toping,flatten(batters.batter) as bat  FROM json.jsonfiles.`batter.json`;

这给了我

org.apache.drill.common.exceptions.UserRemoteException:验证 错误:从第 1 行第 43 列到第 1 行第 49 列:表“击球手” 未找到 SQL 查询 null [错误 ID: 33cf80f2-f283-4401-90ce-c262474e0778 on acer:31010]

我该如何解决这个问题?我们可以在一个查询中展平两个数组吗?

【问题讨论】:

    标签: apache-drill


    【解决方案1】:

    您需要添加表别名并在列中引用它。以下查询适用于您提供的示例数据。

    SELECT flatten(a.topping) as toping,flatten(a.batters.batter) as bat  FROM  dfs.tmp.`batter.json` a;
    

    【讨论】:

      猜你喜欢
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多