How to provide arguments to IN Clause in HIve

蓝咒 提交于 2021-02-10 17:33:48

问题


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').

Is there any way to supply the arguments to IN Clause from a text file ?


回答1:


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

Also you can pass the list of values as a single parameter to the IN: https://stackoverflow.com/a/56963448/2700344

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



来源:https://stackoverflow.com/questions/65235506/how-to-provide-arguments-to-in-clause-in-hive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!