如何从bashshell脚本运行直线和配置单元查询

dy2hfwbg  于 2021-05-31  发布在  Hadoop
关注(0)|答案(2)|浏览(421)

在登录到unixbashshell之后,我可以按顺序手动运行以下步骤。

echo "Connecting beeline" 

beeline
!connect jdbc:hive2://a301-1234-1234.stm.XXX.com:10000/default;;ssl=true;sslTrustStore=/app/bds/cloudera_truststore.jks;sslTrustPassword=;principal=hive/_HOST@BDS.XXXX.COM

INSERT OVERWRITE DIRECTORY "/dev/ref/HIVE_EXPORT/" ROW FORMAT DELIMITED FIELDS TERMINATED BY "," ESCAPED BY "\\" SELECT * FROM test_ref_st.Daily_report  limit 10;

hadoop fs -get('/dev/ref/HIVE_EXPORT/000000_0', '/user/rj/hiveExtract.csv')
echo "Query result extracted "

我需要通过类似test1.sh的shell脚本按顺序运行以上所有步骤

bash-4.2$ sh -x test1.sh

然后它只运行到beeline,其余命令不运行。电流输出:

bash-4.2$ sh test1.sh

Picked up JAVA_TOOL_OPTIONS:
Beeline version 1.1.0-cdh5.16.2 by Apache Hive
beeline>
92vpleto

92vpleto1#

使用 !connect 将打开直线壳控制台。要使用beeline cli命令,可以在shell中执行以下操作:


# !/bin/bash

HIVE_CONN=jdbc:hive2://a301-1234-1234.stm.XXX.com:10000/default;;  ## limited for simplicity

echo "executing query using beeline"
beeline -u $HIVE_CONN -e "INSERT OVERWRITE DIRECTORY "/dev/ref/HIVE_EXPORT/" ROW FORMAT DELIMITED FIELDS TERMINATED BY "," ESCAPED BY "\\" SELECT * FROM test_ref_st.Daily_report  limit 10;"

... 
rest of your code

-e表示要执行的查询
更多关于直线cli的信息。

h9a6wy2h

h9a6wy2h2#

bash正在逐行处理脚本。它运行 beeline 等待你的输入。您可以使用heredoc从脚本写入stdin:

beeline <<EOF
!connect jdbc:hive2://a301-1234-1234.stm.XXX.com:10000/default;;ssl=true;sslTrustStore=/app/bds/cloudera_truststore.jks;sslTrustPassword=;principal=hive/_HOST@BDS.XXXX.COM
INSERT OVERWRITE DIRECTORY "/dev/ref/HIVE_EXPORT/" ROW FORMAT DELIMITED FIELDS TERMINATED BY "," ESCAPED BY "\\" SELECT * FROM test_ref_st.Daily_report  limit 10;
EOF

相关问题