CodingInCircles
CodingInCircles

Reputation: 2807

Hive - How to store a query result in a variable in a Bash script

I need to store the result of a Hive query in a variable whose value will be used later. So, something like:

$var = select col1 from table;

$var_to_used_later = $var;

All this is part of a bash shell script. How to form the query so as to get the desired result?

Upvotes: 0

Views: 5345

Answers (2)

CodingInCircles
CodingInCircles

Reputation: 2807

I used the method shown here and got it! Instead of calling a file as shown, I run the query directly and use the value stored in the variable.

Upvotes: 0

qqibrow
qqibrow

Reputation: 3022

Hive should provide command line support for you. I am not familiar with hive but I found this: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli, you can check whether that works.

Personally, I used mysql to achieve similar goal before. The command is: mysql -u root -p`[script to generate the key]` -N -B -e "use XXXDB; select aaa, bbb, COUNT(*) from xxxtable where some_attribute='$CertainValue';"

Upvotes: 0

Related Questions