如何在配置单元中调用shell脚本

rryofs0p  于 2021-05-29  发布在  Hadoop
关注(0)|答案(3)|浏览(391)

有人能解释一下如何从hive调用shell脚本吗?。我对此进行了探索,发现我们必须使用 source FILE 命令从配置单元调用shell脚本。但我不确定如何使用 source File 命令。有人能帮我吗?提前谢谢。

mepcadol

mepcadol1#

使用 ! <command> - Executes a shell command from the Hive shell. 测试1.sh:


# !/bin/sh

echo "This massage is from $0 file"

配置单元测试.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
mwyxok5s

mwyxok5s2#

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

!sh file.sh;

!./file.sh;

有关更多信息,请浏览下面链接中的“配置单元交互式shell命令”部分。https://cwiki.apache.org/confluence/display/hive/languagemanual+cli

x8goxv8g

x8goxv8g3#

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


# !/bin/bash

hive -e 'SELECT count(*) from table' > temp.txt
cat temp.txt

相关问题