如何编写子查询并使用“In” Hive 中的子句
如何在 Hive 中使用 In 子句 我想在 Hive 中写这样的东西 从 y 中选择 x,其中 yz 按 x 顺序(从 y 中选择不同的 z); 但我没有找到任何方法可以做到这一点.. 我在 Hive 0.7 中尝试了 In 子句,它抛出错误,我还尝试了 Find_in_Set .. 使用 find_in_set(yz,subquery) ..但是作业失败了。
我想在 Hive 上执行此操作。如果有人知道如何在 Hive 中执行此操作,请帮助我。
谢谢&问候, 阿图尔
How can I use In clause in Hive
I want to write something like this in Hive
select x from y where y.z in (select distinct z from y) order by x;
But I am not finding any way of doing it..
I tried In clause in Hive 0.7 it was throwing error, Also I tried Find_in_Set ..
using find_in_set(y.z,subquery).. but the job is getting failed.
I want to do this on Hive. Please help me if anybody knows how to do this in Hive..
Thanks & Regards,
Atul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用半连接(https://cwiki.apache.org/Hive/languagemanual-joins.html):
LEFT SEMI JOIN 以有效的方式实现相关的 IN/EXISTS 子查询语义。由于 Hive 目前不支持 IN/EXISTS 子查询,因此您可以使用 LEFT SEMI JOIN 重写查询。使用 LEFT SEMI JOIN 的限制是右侧表只能在连接条件(ON 子句)中引用,而不能在 WHERE 或 SELECT 子句等中引用。
可以重写为:
You can use semi join(https://cwiki.apache.org/Hive/languagemanual-joins.html):
LEFT SEMI JOIN implements the correlated IN/EXISTS subquery semantics in an efficient way. Since Hive currently does not support IN/EXISTS subqueries, you can rewrite your queries using LEFT SEMI JOIN. The restrictions of using LEFT SEMI JOIN is that the right-hand-side table should only be referenced in the join condition (ON-clause), but not in WHERE- or SELECT-clauses etc.
can be rewritten to:
Hive 0.13 现在支持 WHERE 子句中的 IN/EXISTS .. 问题 https:// issues.apache.org/jira/browse/HIVE-784 已在 4 年后得到解决:)
Hive 0.13 now do support IN/EXISTS in the WHERE-clause .. The issue https://issues.apache.org/jira/browse/HIVE-784 has been resolved after 4 years :)
根据 https://cwiki.apache.org/confluence/display/Hive/LanguageManual +Select:
“Hive 不支持 WHERE 子句中的 IN、EXISTS 或子查询。”
您可能想看看:
https://issues.apache.org/jira/browse/HIVE-801
https://issues.apache.org/jira/browse/HIVE-1799
According to https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select:
"Hive does not support IN, EXISTS or subqueries in the WHERE clause."
You might want to look at:
https://issues.apache.org/jira/browse/HIVE-801
https://issues.apache.org/jira/browse/HIVE-1799
我正在使用 hive 版本
0.7.1
和SELECT * FROM MYTABLE WHERE MYCOLUMN IN ('thisThing','thatThing');
我在列类型上对此进行了测试
STRING
所以我不确定这是否适用于所有数据类型,因为我注意到像上面提到的 Wawrzyniec 一样,Hive 语言手册说不支持它,而是使用LEFT SEMI JOIN
但在我的测试中效果很好。I'm using hive version
0.7.1
andSELECT * FROM MYTABLE WHERE MYCOLUMN IN ('thisThing','thatThing');
I tested this on a column type
STRING
so I am not sure if this works universally on all data types since I noticed like Wawrzyniec mentioned above that the Hive Language Manual says that it is not supported and to instead useLEFT SEMI JOIN
but it worked fine in my test.Hive 完美支持 IN ...它不支持 WHERE 子句中的子查询
自 4 年来 Facebook 工程师就有一个开放功能票证...
https://issues.apache.org/jira/browse/HIVE-784 ?focusedCommentId=13579059
Hive supports perfectly the IN ... it does not support the subquery in the WHERE clause
there is an open feature ticket from Facebook engineers since 4 years...
https://issues.apache.org/jira/browse/HIVE-784?focusedCommentId=13579059
假设
table t1(id,name)
和table t2(id,name)
仅列出 t2 中存在的
t1
中的 id(基本上 < code>IN 子句)仅列出
t1
中仅存在于t1
但不存在于 t2 的 id(基本上是NOT IN
子句)assume
table t1(id,name)
andtable t2(id,name)
listing only those ids from
t1
that exists in t2(basicallyIN
clause)listing only those ids from
t1
that exists only int1
but not in t2(basicallyNOT IN
clause)从 Hive 0.13 开始,Hive 确实支持 IN/EXISTS 语句,但有一些限制。请参考 https://cwiki.apache.org/confluence/display/Hive /LanguageManual+SubQueries 了解更多详细信息。
Hive does support IN/EXISTS statements since Hive 0.13 with few limitations. Please refer to https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SubQueries for more details.