passing multiple dates as a paramters to Hive query

风格不统一 提交于 2019-12-04 16:06:16

Collect array of distinct values using collect_set and concatenate it with delimiter ','. This will produce list without outer quotes 2009-02-01','2009-04-01 and in the second script add outer quotes ' also, or you can add them in the first query. And when executing in inline sql (-e option) you do not need to pass hiveconf variable, direct shell variable substitution will work. Use hiveconf when you are executing script from file (-f option)

Working example:

date_list=$(hive -S -e "select concat_ws('\',\'',collect_set(substr(dt,0,10))) from (select stack (2,'2017-01', '2017-02')as dt)s ;")

hive -e "select * from (select stack (2,'2017-01', '2017-02')as dt)s where dt in ('${date_list}');"

Returns:

OK

2017-01
2017-02
Time taken: 1.221 seconds, Fetched: 2 row(s)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!