Hive命令封装(笔记)

封装hive -e命令,使其实现hive -f功能并且支持传参数
1、hiveF命令
. /etc/profile
sql=`java -jar /root/custom/lib/hiveF.jar $*`
echo "$sql"
hive -e "$sql"

2、hiveUDF.jar及hiveF.jar的编写

3、run-hivef.hql
add jar /root/custom/lib/hiveUDF.jar;
create temporary function getCmsId as 'com.hy.hive.udf.MyUDF';

drop table hivef_udf;

create table hivef_udf as 
select session_id,
       url,
       getCmsId(url)
 from page_views where dt='{$date}' and url like '%topicId%';

4、run-hivef.sh
#!/bin/bash
#set -x
. /etc/profile
cd /root/opt/hive/hivefile
begin=`date -d -1days +%Y-%m-%d`
begin="2014-01-22"
#hive -f ./hive_test.hql
hiveF /root/custom/script/run-hivef.hql -date "$begin" 

5、零碎小结大致步骤
#hiveF
step1:mkdir /root/custom/lib
step2:mkdir /root/custom/bin
step3:cp hiveF.jar /root/custom/lib
step4:cd /root/custom/bin/
step5:touch hiveF
step6:vi hiveF
   . /etc/profile
   sql=`java -jar /root/custom/lib/hiveF.jar $*`
   echo "$sql"
   hive -e "$sql"
step7:chmod +x /root/custom/bin/hiveF
step8:vi /etc/profile
      PATH=$PATH:/root/custom/bin/      
step9:chmod +x run-hivef.sh
step10:./run-hivef.sh

你可能感兴趣的:(storm,spark))