[英]How get nested json value from the following table in aws athena
Here is our code这是我们的代码
SELECT "count"(*) "count"
, "httprequest"."country"
, "httprequest"."headers"
FROM waf_logs_17
WHERE ("httprequest"."uri" LIKE '/login')
GROUP BY "httprequest"."clientip", "httprequest"."country","httprequest"."headers"
ORDER BY "count" limit 5
Result is as follow结果如下
count数数 | Country国家 | headers标题 |
---|---|---|
1 1 | US我们 | [{name=Host, value=app.onlinecheckwriter.com}, {name=X-Forwarded-For, value=75.113.195.00}, {name=X-Forwarded-Proto, value=https}] [{name=Host, value=app.onlinecheckwriter.com}, {name=X-Forwarded-For, value=75.113.195.00}, {name=X-Forwarded-Proto, value=https}] |
Now question is how we can select the value of X-Forwarded-For under "httprequest"."headers"现在的问题是我们如何才能 select 在“httprequest”.“headers”下的 X-Forwarded-For 的值
Your data is not json, but array of rows, so you can process it using array functions :您的数据不是 json,而是行数组,因此您可以使用数组函数对其进行处理:
-- sample data
WITH dataset (headers) AS (
values (array[cast(row('X-Forwarded-For', '75.113.195.00') as ROW(name varchar, value varchar))] )
)
-- query
select
reduce(headers, NULL, (v, curr) -> if(curr.name = 'X-Forwarded-For', curr.value, v), v -> v)
from dataset
Output: Output:
_col0 _col0 |
---|
75.113.195.00 75.113.195.00 |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.