Hive 查询中 LIKE 子句中的动态条件
Dynamic condition in LIKE clause in a Hive query
通常,当我在配置单元查询中应用 LIKE 条件时,我会应用这样的静态条件-
select * from table where col1 like '%abc%';
我有一个用例,我希望 LIKE 条件是动态的,我希望参数“%abc%”来自另一个配置单元 table 中的列,所以像这样-
select * from table where col1 like (select regex from table2);
我能在 Hive 中做到这一点吗?
通常在 SQL 中,我可以通过使用 LIKE 条件的连接来完成,但据我所知,Hive 只允许相等连接。
至少最新版本的 Hive 支持非等值连接(参见 here)。
所以,你应该能够做到:
select t.*
from table t join
table2 t2
on t.col1 like t2.regex;
请注意 like
模式不等同于正则表达式。
其中 col1 喜欢 (select 来自 table2 的正则表达式);
通常,当我在配置单元查询中应用 LIKE 条件时,我会应用这样的静态条件-
select * from table where col1 like '%abc%';
我有一个用例,我希望 LIKE 条件是动态的,我希望参数“%abc%”来自另一个配置单元 table 中的列,所以像这样-
select * from table where col1 like (select regex from table2);
我能在 Hive 中做到这一点吗?
通常在 SQL 中,我可以通过使用 LIKE 条件的连接来完成,但据我所知,Hive 只允许相等连接。
至少最新版本的 Hive 支持非等值连接(参见 here)。
所以,你应该能够做到:
select t.*
from table t join
table2 t2
on t.col1 like t2.regex;
请注意 like
模式不等同于正则表达式。
其中 col1 喜欢 (select 来自 table2 的正则表达式);