如何使用 apache drill 展平两个 json 数组

How to flatten two json arrays using apache drill

{
    "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: VALIDATION ERROR: From line 1, column 43 to line 1, column 49: Table 'batters' not found SQL Query null [Error Id: 33cf80f2-f283-4401-90ce-c262474e0778 on acer:31010]

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

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

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