简体   繁体   中英

Using Presto's Coalesce function with a row on AWS Athena

I am using AWS Web Application Firewall (WAF). The logs are written to an S3 Bucket and queried by AWS Athena.

Some log fields are not simple data types but complex JSON types. For example "rulegrouplist". It contains a JSON array of complex types and the array might have 0 or more elements.

So I am using Presto's try() function to convert errors to NULLs and trying to use the coalesce() function to put a dash in their place. (Keeping null values cause problems while using GROUP BY)

try() is working fine but coalesce() is causing a type mismatch problem.

The function call below:

coalesce(try(waf.rulegrouplist[1].terminatingrule),'-')

causes this error:

All COALESCE operands must be the same type: row(ruleid varchar,action varchar,rulematchdetails varchar)

How can I convert "-" to a row or what else can I use that will count as a row?

Apperantly you can create an empty row and cast it to a typed row.

This worked...

coalesce(try(waf.rulegrouplist[1].terminatingrule),CAST(row('null','null','null') as row(ruleid varchar,action varchar,rulematchdetails varchar)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM