查找字符串中的所有实例--Apache Presto

时间:2017-06-13 04:01:18

标签: presto

我在HIVE(HDFS)中有以下行,并使用Presto作为查询引擎。

1,@markbutcher72 @charlottegloyn Not what Belinda Carlisle thought. And yes, she was singing about Edgbaston.
2,@tomkingham @markbutcher72 @charlottegloyn It's true the garden of Eden is currently very green...
3,@MrRhysBenjamin @gasuperspark1 @markbutcher72 Actually it's Springfield Park, the (occasional) home of the might

要求是通过Presto Query获取以下内容。我们怎么能得到这个

1,markbutcher72
1,charlottegloyn
2,tomkingham
2,markbutcher72
2,charlottegloyn
3,MrRhysBenjamin
3,gasuperspark1 
3,markbutcher72 

1 个答案:

答案 0 :(得分:1)

select  t.id
       ,u.token

from    mytable as t
        cross join unnest (regexp_extract_all(text,'(?<=@)\S+')) as u(token) 
;
+----+----------------+
| id |     token      |
+----+----------------+
|  1 | markbutcher72  |
|  1 | charlottegloyn |
|  2 | tomkingham     |
|  2 | markbutcher72  |
|  2 | charlottegloyn |
|  3 | MrRhysBenjamin |
|  3 | gasuperspark1  |
|  3 | markbutcher72  |
+----+----------------+