'What is the Athena equivalent of MySQL's JSON_REMOVE?
I want to remove items from a json value, producing a new json value, within the scope of an Athena query.
MySQL has the function JSON_REMOVE
which does this nicely.
What is the equivalent in Athena?
I have checked the documentation and found nothing:
https://docs.aws.amazon.com/athena/latest/ug/extracting-data-from-JSON.html
As a temporary hack, I can sometimes use a regex before parsing the json:
REGEXP_REPLACE(json, '\"(fieldName|anotherFieldName)\":\"[^"]*\"', ''))
Solution 1:[1]
Found the answer is to cast JSON to MAP and then use map_filter
, for example:
select map_filter(cast(json_parse(json) as map<varchar,varchar>), (k,v) -> k !='fieldName') from ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex R |