0
votes

I have checked the related thread - How to set variables in HIVE scripts

Inside hive the variable is working fine:

hive> set hivevar:cal_month_end='2012-01-01';
hive> select ${cal_month_end};

But when I run this through command line:

$ hive -e "set hivevar:cal_month_end='2012-01-01';select '${cal_month_end}';"

It keeps giving me below error:

Error: java.lang.IllegalArgumentException: Can not create a Path from an empty string at org.apache.hadoop.fs.Path.checkPathArg(Path.java:131) at org.apache.hadoop.fs.Path.(Path.java:139) at org.apache.hadoop.hive.ql.io.HiveInputFormat$HiveInputSplit.getPath(HiveInputFormat.java:110) at org.apache.hadoop.mapred.MapTask.updateJobWithSplit(MapTask.java:463) at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:411) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:347) at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:167) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1469) at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:162)

4

4 Answers

0
votes

You have to escape few characters. This is working for me.

hive -e "set hivevar:cal_month_end=\'2012-01-01\';select '\${cal_month_end}';"
0
votes

you have to get the " and ' right.
use this :
hive -e 'set hivevar:cal_month_end="2012-01-01";select ${cal_month_end};'

0
votes

I finally know what's went wrong. The problem is in command line I can't just select something, it needs to from some table. Below is working fine.

$ hive -e "set hivevar:cal_month_end='2012-01-01';select * from foo where start_time > '${cal_month_end}' limit 10"
0
votes

You can also set variables as an argument of the hive command:

hive --hivevar cal_month_end='2012-01-01' -e "select '${cal_month_end}';"