如何在HIve中为IN子句提供参数 [英] How to provide arguments to IN Clause in HIve
问题描述
有什么方法可以读取 HIVEquery 中的参数,该参数可以替代 IN 子句.我有以下查询.
Is there any way to read arguments in HIVEquery which can substitute to an IN Clause. I have the below query with me.
Select count (*) from table where id in ('1','2','3','4','5').
是否可以通过文本文件为IN子句提供参数?
Is there any way to supply the arguments to IN Clause from a text file ?
推荐答案
使用in_file:将所有ID放入文件中,连续一个ID.
Use in_file: Put all ids into file, one id in a row.
Select count (*) from table where in_file(id, '/tmp/myfilename'); --local file
您还可以将值列表作为单个参数传递给IN: https://stackoverflow.com/a/56963448/2700344
Also you can pass the list of values as a single parameter to the IN: https://stackoverflow.com/a/56963448/2700344
此外,如果IN可以对包含这些ID的表进行左半连接
,例如,在此答案中:
Also instead if IN you can do left semi join
with a table containing these IDs, like in this answer: https://stackoverflow.com/a/41056870/2700344
这篇关于如何在HIve中为IN子句提供参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!