没有公共字段的hive连接

r6vfmomb  于 2021-05-30  发布在  Hadoop
关注(0)|答案(2)|浏览(443)

我有以下表格: Table1 :

user_name Url
Rahul    www.cric.info.com
ranbir   www.rogby.com
sahil    www.google.com
banit    www.yahoo.com
``` `Table2` :

Keyword category
cric sports
footbal sports
google search

我想搜索 `Table1` 通过匹配中的关键字 `Table2` . 我可以使用case语句执行相同的查询,但这不是正确的方法,因为每次添加新的搜索关键字时都必须添加case语句。

select user_name from table1
case when url like '%cric%' then sports
else 'undefined'
end as category
from table1;

siv3szwd

siv3szwd1#

谢谢找到这个方法的解决方案。首先我们需要进行连接,然后我们需要过滤记录。

select user_name,url,Keyword,catagory from(select table1.user_name,table1.url ,table2.keyword,table2.catagory from table1 left outer join table2)a where a.url like (concat('%',a.phrase,'%')
dffbzjpn

dffbzjpn2#

不确定是否有更新的版本,但我遇到了类似的问题。。。主要问题是配置单元只支持equi-join语句。。。当您将逻辑应用于连接的任一侧时,很难将其转换为map reduce函数。
如果您有一个结构可靠的字段,另一种方法是可以从较大的字段中创建匹配的键。例如,如果您知道正在查找关键字位于点分隔uri的第二个位置,则可以执行以下操作:

select
Uri
, split(Uri, "\\.")[1] as matchKey
from
Table1
join Table2 on Table2.keyword = Table1.matchKey
;

相关问题