我在 AWS Athena 上工作以过滤负载均衡器日志。我创建了下表并将日志导入表中。
CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs (
request_timestamp string,
elb_response_code string,
url string,
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
'serialization.format' = '1','input.regex' = '([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:\-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\" (\"[^\"]*\") ([A-Z0-9-]+) ([A-Za-z0-9.-]*)$' )
LOCATION 's3://athena-examples/elb/raw/';
现在我想获得200 OK、400 和 500 响应计数的计数。所以我执行了以下查询。
SELECT distinct(elb_response_code),
count(url) AS count
FROM elb_logs
GROUP BY elb_response_code
它有效,但它返回所有响应,如下所示。
**response count**
401 1270
201 1369
422 342
200 3568727
400 1221
404 444
304 10435
413 3
206 30
500 1542
我想对所有 400,401,404,413,422 和 2xx、3xx 和 5xx 求和所以结果应该是 4xx sum(400,401,404,413,422)
**response count**
4xx 52145
2xx 1363224
5xx 532