Hive - 如何将查询结果存储在 Bash 脚本中的变量中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27851808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hive - How to store a query result in a variable in a Bash script
提问by CodingInCircles
I need to store the result of a Hive query in a variable whose value will be used later. So, something like:
我需要将 Hive 查询的结果存储在稍后将使用其值的变量中。所以,像这样:
$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?
所有这些都是 bash shell 脚本的一部分。如何形成查询以获得所需的结果?
回答by qqibrow
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.
Hive 应该为您提供命令行支持。我对 hive 不熟悉,但我发现了这个:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli,您可以检查它是否有效。
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';"
就个人而言,我之前使用 mysql 来实现类似的目标。命令是:
mysql -u root -p`[script to generate the key]` -N -B -e "use XXXDB; select aaa, bbb, COUNT(*) from xxxtable where some_attribute='$CertainValue';"