Parsing a column with LIST, String, and NULL
Hello Team,
I am trying to parse a column that contains either a LIST, a NULL, or a String. As you can see it is the policy action that describes an AWS S3 Bucket.
When I do JSON_ELEMENTS on the column many rows (both NULL, and single String) will disappear.
When I do JSON_ELEMENT I will have to manually define and the values became separate columns.
I would like to have the list be splitted in the same column (different rows) rather than split string in columns.
Can I please have your advice? what is the best practice to deal with this scenario?
Thanks,
anson
-
Hello Anson.
I hope you are doing fine and staying safe these days.
I guess we would need more details about this use-case to be able to suggest the right approach.- As far as I understand, the data type of the policyStatementAction column is STRING, isn't it?
- What is the final goal for the transformation? Do you need to have a list of policy elements in a single column, so you can use each element separately for further analysis?
-
Hello Anson.
In this case, I would suggest the following approach.- Remove brackets and quotes from the initial string via the REPLACEALL function. This gives you the string with comma-separated values (\u0022 is a Unicode for the quote character).
REPLACEALL(REPLACEALL(REPLACEALL(#policyStatementAction; "\\["; ""); "\\]"; ""); "\\u0022"; "")
- Use the TOKENIZELIST function with a comma as a separator to make a list out of the string.
I hope this is what you are looking for.
- Remove brackets and quotes from the initial string via the REPLACEALL function. This gives you the string with comma-separated values (\u0022 is a Unicode for the quote character).
Please sign in to leave a comment.
Comments
3 comments