Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Beeline CLI parameters (hivevar) not evaluating

avatar

Hello,

I've been struggling with parameters in command line. Parameters work in interactive shell but I cannot figure out what is wrong.

This is the code I'm running. Output should be 9911221199, but only 99 is displayed.

[hive@bitest ~]$ beeline -u jdbc:hive2:// --hivevar rdate=112211 -e "select 9${hivevar:rdate}9"
Connecting to jdbc:hive2://
Connected to: Apache Hive (version 1.2.1000.2.5.0.0-1245)
Driver: Hive JDBC (version 1.2.1000.2.5.0.0-1245)
Transaction isolation: TRANSACTION_REPEATABLE_READ
OK
+------+--+
| _c0  |
+------+--+
| 99   |
+------+--+
1 row selected (3.818 seconds)
Beeline version 1.2.1000.2.5.0.0-1245 by Apache Hive
Closing: 0: jdbc:hive2://


6 REPLIES 6

avatar
beeline -u jdbc:hive2:// --hivevar rdate=112211 -e "set rdate"

Returns rdate is underfined, but

hive --hivevar rdate=112211 -e "set rdate"

returns:

Logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties
rdate=112211

However, using the variable in hive still does not evaluate:

hive --hivevar rdate=112211 -e "select 9${hivevar:rdate}9"
Logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties
OK
99
Time taken: 3.178 seconds, Fetched: 1 row(s)

avatar
New Contributor

To clarify for others, I believe the reason the following doesn't work is that it was executed in a bash shell, i.e. using a typical terminal.

hive --hivevar rdate=112211 -e "select 9${hivevar:rdate}9"

 In double quoted strings, the '$' tells bash to treat  "{hivevar:rdate}" as a variable but it isn't defined so it returns an empty string before being passed in to hive due to the -e flag. i.e. "9${hivevar:rdate}9" is evaulated to "99" even before passing it into hive.

 

In contrast within single quotes there is no substitution in bash, so '9${hivevar:rdate}9' is passed into hive as is, so the following executes as the poster expected.

 

hive --hivevar rdate=112211 -e 'select 9${hivevar:rdate}9'

 

avatar

Managed to get hive to substitute the variable, but not beeline;

hive --hivevar rdate=112211 -e 'select 9${hivevar:rdate}9'
Logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties
OK
91122119
Time taken: 3.76 seconds, Fetched: 1 row(s)

avatar
Super Guru
@Stevens Yeung

Can you please try the following:

beeline -u jdbc:hive2:// --hivevar rdate=112211 -e "select 9${hivevar:rdate}9"

avatar

Thanks @mqureshi, however it gives me the same thing;

beeline -u jdbc:hive2:// --hivevar rdate=112211 -e "select 9${hivevar:rdate}9"
Connecting to jdbc:hive2://
Connected to: Apache Hive (version 1.2.1000.2.5.0.0-1245)
Driver: Hive JDBC (version 1.2.1000.2.5.0.0-1245)
Transaction isolation: TRANSACTION_REPEATABLE_READ
OK
+------+--+
| _c0  |
+------+--+
| 99   |
+------+--+
1 row selected (4.268 seconds)
Beeline version 1.2.1000.2.5.0.0-1245 by Apache Hive
Closing: 0: jdbc:hive2://

I'm on HDP 2.5 btw. Test server, 1 node.

avatar

Made it to work. Had to use the full database path, i.e.

Doesnt work: -u jdbc:hive2://

Works: -u jdbc:hive2://localhost:10000