我正在使用 AWS Web 应用程序防火墙 (WAF)。日志将写入 S3 存储桶并由 AWS Athena 查询。
有些日志字段不是简单的数据类型,而是复杂的 JSON 类型。例如“规则组列表”。它包含一个复杂类型的 JSON 数组,该数组可能有 0 个或多个元素。
所以我使用 Presto 的 try() 函数将错误转换为 NULL,并尝试使用 coalesce() 函数在它们的位置放置一个破折号。 (使用 GROUP BY 时保留空值会导致问题)
try() 工作正常,但coalesce() 导致类型不匹配问题。
下面的函数调用:
coalesce(try(waf.rulegrouplist[1].terminatingrule),'-')
导致此错误:
All COALESCE operands must be the same type: row(ruleid varchar,action varchar,rulematchdetails varchar)
如何将“-”转换为一行,或者我还可以使用什么来算作一行?
答案 0 :(得分:0)
显然,您可以创建一个空行并将其转换为键入的行。
这有效...
coalesce(try(waf.rulegrouplist[1].terminatingrule),CAST(row('null','null','null') as row(ruleid varchar,action varchar,rulematchdetails varchar)))