hive:加入regex

hive:加入regex,hive,Hive,我想用regex/rlike条件实现一个连接。但蜂巢不起作用 select a.col_1, b.col_2 from table1 a left join table2 b on a.col_1 rlike b.col_2 这实际上是可行的,但我想将b.col2中的全文与a.colu_1中的字符串相匹配。有办法做到这一点吗 示例数据集: **table1** apple iphone apple iphone 6s google nexus samsung galaxy tab **t

我想用regex/rlike条件实现一个连接。但蜂巢不起作用

select a.col_1, b.col_2 
from table1 a left join table2 b
on a.col_1 rlike b.col_2
这实际上是可行的,但我想将b.col2中的全文与a.colu_1中的字符串相匹配。有办法做到这一点吗

示例数据集:

**table1**
apple iphone 
apple iphone 6s
google nexus
samsung galaxy tab

**table2**
apple
google
nexus

**outcome**
col1                   col2
apple iphone          apple
apple iphone 6s       apple
google nexus          google
samsung galaxy tab    null


是否有任何逻辑可用于使用字符串操作隔离
col1
中感兴趣的字符串?一些示例数据在这里会很有帮助。不幸的是,没有。我正在处理搜索关键字。因此,我想将表2中的“苹果”品牌与表1中的关键词“苹果iphone 6s”进行匹配。换句话说,我想找出表2[全文]中有多少关键字与表1中的关键字相匹配。@TimBiegeleisen添加了示例数据集搜索关键字是否总是单个单词?表1是否有ID列?
select  col1
       ,col2

from   (select  t1.col1
               ,t2.col2
               ,count      (col2) over (partition by col1)      as count_col2
               ,row_number ()     over (partition by col1,col2) as rn

        from                   (select  *

                                from    table1 t1 
                                        lateral view explode(split(col1,'\\s+')) e as token
                                ) t1

                left join      (select  *

                                from    table2 t2
                                        lateral view explode(split(col2,'\\s+')) e as token
                                ) t2


                on              t2.token = 
                                t1.token     
        ) t  

where   (   count_col2 = 0
        or  col1 rlike concat ('\\b',col2,'\\b')
        )

    and rn = 1
;
+--------------------+--------+
|        col1        |  col2  |
+--------------------+--------+
| apple iphone       | apple  |
| apple iphone 6s    | apple  |
| google nexus       | google |
| google nexus       | nexus  |
| samsung galaxy tab | (null) |
+--------------------+--------+