/google/gmail/inbox
/google/drive/map
/google/apps
/yahoo/news/cricket
/yahoo/mail/
/yahoo/sports
/wiki/ind/jack
/wiki/us/jil
我需要获取所需的页组。如果我使用配置单元查询搜索以“google”开头的页组,我需要获取前 3 行的数据。
/google/gmail/inbox
/google/drive/map
/google/apps
这样我需要根据页面组获取数据。
我使用 like 函数搜索了字符串。
select * from table where field like '%/google/%';
最佳答案
听起来您需要页组。这可能是谷歌,但似乎也可能是雅虎。如果你想通过搜索引擎提取页面组,你可以使用正则表达式。您可以在 (page1|page2|...|pageN) 中放置多个网站。
Select column from table
where column rlike '.*(google|yahoo).*'
输出:
/google/gmail/inbox
/google/drive/map
/google/apps
您可能想要创建一个新列,以搜索引擎命名或登陆页面。路径中的第一个位置似乎是着陆页。您可以通过这种方式提取登录页面:
select * from
(Select column
, regexp_extract('^(\\/[a-zA-Z]*\\/)',1) as landing_page
from table) a
where landing page in ('google','yahoo',...,'bing')
;
输出:
column new column
/google/gmail/inbox /google/
/google/drive/map /google/
/google/apps /google/
/yahoo/news/cricket /yahoo/
/yahoo/mail/ /yahoo/
/yahoo/sports /yahoo/
/bing/meats/delisandwich /bing/
/bing/maps/delis /bing/
如果您不想要/google/而更喜欢 google 那么请执行以下操作:
regexp_extract('^\\/([a-zA-Z]*)\\/',1) as landing_page
现在我假设着陆页在您描述的路径中排在第一位。
关于hadoop - 在字符串中搜索特定文本 - Hive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31450622/