[英]How to convert json object into array in prestodb/athena
I have a JSON object in this format data = {"1": {"col1":"a", "col2":"b"}, "2": {"col1":"c", "col2":"d"}....,"99":{"col1":"asd", "col2":"exm"}}.
我有一个 JSON object,格式
data = {"1": {"col1":"a", "col2":"b"}, "2": {"col1":"c", "col2":"d"}....,"99":{"col1":"asd", "col2":"exm"}}.
I would like to get all the values for col_1 and col_2 using athena.我想使用 athena 获取 col_1 和 col_2 的所有值。 How do I achieve this using athena?
我如何使用雅典娜实现这一目标?
I was able to solve it by converting it to Map and then unnesting it like我能够通过将其转换为 Map 然后将其取消嵌套来解决它
select key, value from table where unnest(cast(json_parse(data) as Map(varchar,JSON)) as t(key,value)) select key, value from table where unnest(cast(json_parse(data) as Map(varchar,JSON)) as t(key,value))
Ignore that it is a JSON format (since it is not simple enough) and use the regex function:忽略它是 JSON 格式(因为它不够简单)并使用正则表达式 function:
SELECT regexp_extract_all(column_data, '"col1":"([a-z]+)",'); -- [a, c, ... asd]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.