Anupam Alok
Anupam Alok

Reputation: 433

Unix_TIMESTAMP for hive not working in Shell Script

I am Running a hive Query

hive -hiveconf prvDate=$prvDate -S -e "select max(ID) from Employee where unix_timestamp(date,'dd-MM-yyyy') > unix_timestamp('${hiveconf:prvDate}','dd-MM-yyyy')"

It is returning NULL. prvdate is 15-12-2017

but when I running the same script in Hive

select max(ID) from Employee where unix_timestamp(date,'dd-MM-yyyy') > unix_timestamp('15-12-2017','dd-MM-yyyy')

I am able to see the Result. Can someone help?

Upvotes: 2

Views: 217

Answers (2)

leftjoin
leftjoin

Reputation: 38335

In case you are running hive with inline SQL inside shell script you do not need to pass -hiveconf variable, use shell substitution instead.

Example (shell):

prvDate="01-01-2017"

hive -S -e "select unix_timestamp('$prvDate','dd-MM-yyyy')"

Output: 1483257600

Use --hiveconf only if you are executing SQL script file:

hive --hiveconf bla="$bla" -f myscript.hql

Upvotes: 1

hlagos
hlagos

Reputation: 7957

it is because you are calling your hiveconf var, change the name and it should work

hive -hiveconf prvDate=$prvDate -S -e "select max(ID) from Employee where unix_timestamp(date,'dd-MM-yyyy') > unix_timestamp('${hiveconf:prvDate}','dd-MM-yyyy')"

Upvotes: 0

Related Questions