【发布时间】:2019-04-18 06:45:29
【问题描述】:
我得到了以下格式的带有嵌套结构的 JSON 文档
{
"id": "p-1234-2132321-213213213-12312",
"name": "athena to the rescue",
"groups": [
{
"strategy_group": "anyOf",
"conditions": [
{
"strategy_conditions": "anyOf",
"entries": [
{
"c_key": "service",
"C_operation": "isOneOf",
"C_value": "mambo,bambo,jumbo"
},
{
"c_key": "hostname",
"C_operation": "is",
"C_value": "lols"
}
]
}
]
}
],
"tags": [
"aaa",
"bbb",
"ccc"
]
}
我在 Athena 中创建了表来支持它使用以下
CREATE EXTERNAL TABLE IF NOT EXISTS filters ( id string, name string, tags array<string>, groups array<struct<
strategy_group:string,
conditions:array<struct<
strategy_conditions:string,
entries: array<struct<
c_key:string,
c_operation:string,
c_value:string
>>
>>
>> ) row format serde 'org.openx.data.jsonserde.JsonSerDe' location 's3://filterios/policies/';
我目前的目标是也根据条件条目列进行查询。我尝试了一些查询,但是 sql 语言不是我最大的交易;)
我现在得到了这个查询,它给了我条目
select cnds.entries from
filters,
UNNEST(filters.groups) AS t(grps),
UNNEST(grps.conditions) AS t(cnds)
但是,由于这是一个复杂的数组,它让我有些头疼,什么是正确的查询方式。
任何提示表示赞赏!
谢谢 回复
【问题讨论】:
标签: amazon-athena presto