簡體   English   中英

如何從 aws athena 的下表中獲取嵌套的 json 值

[英]How get nested json value from the following table in aws athena

這是我們的代碼

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

結果如下

數數 國家 標題
1 我們 [{name=Host, value=app.onlinecheckwriter.com}, {name=X-Forwarded-For, value=75.113.195.00}, {name=X-Forwarded-Proto, value=https}]

現在的問題是我們如何才能 select 在“httprequest”.“headers”下的 X-Forwarded-For 的值

您的數據不是 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:

_col0
75.113.195.00

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM