如何在Hive中调用shell脚本

问题描述 投票:0回答:3

如何从 Hive 调用 shell 脚本?我对此进行了探索,发现我们必须使用

source FILE
命令从 hive 调用 shell 脚本。

我该怎么做?

shell hadoop hive
3个回答
4
投票

使用

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

test_1.sh:

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

hive-test.hql:

! echo showing databases... ; 
show databases;

! echo showing tables...;
show tables;

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

输出:

$ 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

3
投票

要通过 HIVE CLI 调用 shell 脚本,请查看下面的示例。

!sh file.sh; 

!./file.sh;

请访问下面链接中的Hive Interactive Shell Commands部分以获取更多信息。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Cli


1
投票

不知道它是否适合您,但您可以通过从 bash shell 结合 hive 查询结果启动 hive 命令来解决您的问题。您甚至可以为此创建一个 bash 脚本,以将您的 hive 查询与 bash 命令组合在一个脚本中:

#!/bin/bash
hive -e 'SELECT count(*) from table' > temp.txt
cat temp.txt
© www.soinside.com 2019 - 2024. All rights reserved.