我正在将Elastic Load Balancing access日志传递给Athena,我想获取位于URL列中的值。下面的代码适用于mySQL,但是Athena使用SQL可以从下面的方法中获取County的价值吗?
create table elb_logs(row varchar(100),url varchar(100));
insert into elb_logs values("Row1","Lauguage=English&Country=USA&Gender=Male");
insert into elb_logs values("Row2","Gender=Female&Language=French&Country=");
insert into elb_logs values("Row3","Country=Canada&Gender=&Language=English");
insert into elb_logs values("Row4","Gender=&Language=English");
SELECT `row`,IF(LOCATE('Country=',url)>0,COALESCE(
NULLIF(SUBSTRING_INDEX(SUBSTRING_INDEX(url,'Country=',-1),'&',1),''),'Blank string is not valid!'),'Missing Country!') AS ColumnB
FROM `elb_logs`
+------+----------------------------+
| row | ColumnB |
+------+----------------------------+
| Row1 | USA |
| Row2 | Blank string is not valid! |
| Row3 | Canada |
| Row4 | Missing Country! |
+------+----------------------------+