简体   繁体   English

如何在Hive中调用Shell脚本

[英]how to invoke shell script in hive

Could someone please explain me how to invoke a shell script from hive?. 有人可以解释一下我如何从hive调用shell脚本吗? I explored on this and found that we have to use source FILE command to invoke a shell script from hive. 我对此进行了探索,发现我们必须使用source FILE命令从蜂巢中调用shell脚本。 But I am not sure how exactly I can call my shell script from hive using source File command. 但是我不确定如何使用source File命令从蜂巢中调用我的shell脚本。 So can someone help me on this? 那么有人可以帮我吗? Thanks in Advance. 提前致谢。

To invoke a shell script through HIVE CLI, please look at the example below. 要通过HIVE CLI调用Shell脚本,请查看以下示例。

!sh file.sh; 

or 要么

!./file.sh;

Please go though Hive Interactive Shell Commands section in the link below for more information. 请通过下面链接中的Hive Interactive Shell Commands部分获取更多信息。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli

using ! <command> - Executes a shell command from the Hive shell. 使用! <command> - Executes a shell command from the Hive shell. ! <command> - Executes a shell command from the Hive shell.

test_1.sh: test_1.sh:

#!/bin/sh
echo "This massage is from $0 file"

hive-test.hql: 蜂房test.hql:

! echo showing databases... ; 
show databases;

! echo showing tables...;
show tables;

! echo runing shell script...;
! /home/cloudera/test_1.sh

output: 输出:

$ hive -v -f hive-test.hql
showing databases...

    show databases
OK
default
retail_edw
sqoop_import
Time taken: 0.997 seconds, Fetched: 3 row(s)
showing tables...

    show tables
OK
scala_departments
scaladepartments
stack
stackover_hive
Time taken: 0.062 seconds, Fetched: 4 row(s)
runing shell script...
This massage is from /home/cloudera/test_1.sh file

Don't know if it would suit you, but you can inverse your problem by launching the hive commands from the bash shell in combination with the hive queries results. 不知道它是否适合您,但是您可以通过结合结合hive查询结果从bash shell启动hive命令来解决问题。 You can even create a single bash script for this to combine your hive queries with bash commands in a single script: 您甚至可以为此创建一个bash脚本,以将蜂巢查询与bash命令结合在一个脚本中:

#!/bin/bash
hive -e 'SELECT count(*) from table' > temp.txt
cat temp.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM