abc_spark
abc_spark

Reputation: 383

How to provide arguments to IN Clause in HIve

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 ?

Upvotes: 1

Views: 681

Answers (1)

leftjoin
leftjoin

Reputation: 38325

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

Upvotes: 1

Related Questions