- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Beeline CLI parameters (hivevar) not evaluating
- Labels:
-
Apache Hive
Created 06-16-2017 12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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://
Created 06-16-2017 12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Created on 11-20-2019 08:48 AM - edited 11-20-2019 08:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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'
Created 06-16-2017 12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Created 06-16-2017 12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please try the following:
beeline -u jdbc:hive2:// --hivevar rdate=112211 -e "select 9${hivevar:rdate}9"
Created 06-16-2017 12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Created 06-16-2017 12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Made it to work. Had to use the full database path, i.e.
Doesnt work: -u jdbc:hive2://
Works: -u jdbc:hive2://localhost:10000