Shell脚本运行hive语句 | hive以日期建立分区表 | linux schedule程序 | sed替换文件字符串 | shell推断hdfs文件文件夹是否存在
#!/bin/bash
source /etc/profile; ##################################################
# Author: ouyangyewei #
# #
# Content: Combineorder Algorithm #
################################################## # change workspace to here
cd /
cd /home/deploy/recsys/algorithm/schedule/project/combineorder # generate product_sell data
yesterday=$(date -d '-1 day' '+%Y-%m-%d')
lastweek=$(date -d '-1 week' '+%Y-%m-%d') /usr/local/cloud/hive/bin/hive<<EOF
CREATE EXTERNAL TABLE IF NOT EXISTS product_sell(
category_id bigint,
province_id bigint,
product_id bigint,
price double,
sell_num bigint
)
PARTITIONED BY (ds string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE; INSERT OVERWRITE TABLE product_sell PARTITION (ds='$yesterday') select a.category_id, b.good_receiver_province_id as province_id, a.id as product_id, (b.sell_amount/b.sell_num) as price, b.sell_num from product a join (select si.product_id, s.good_receiver_province_id, sum(si.order_item_amount) sell_amount, sum(si.order_item_num) sell_num from so_item si join so s on (si.order_id=s.id) where si.is_gift=0 and si.is_hidden=0 and si.ds between '$lastweek' and '$yesterday' group by s.good_receiver_province_id, si.product_id) b on (a.id=b.product_id);
EOF # generate yhd_gmv_month data
yesterday=$(date -d '-1 day' '+%Y-%m-%d')
lastmonth=$(date -d '-1 month' '+%Y-%m-%d') /usr/local/cloud/hive/bin/hive<<EOF
CREATE EXTERNAL TABLE IF NOT EXISTS yhd_gmv_month(
province_id bigint,
price_area int,
product_id bigint,
sell_num bigint
)
PARTITIONED BY (ds string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE; INSERT OVERWRITE TABLE yhd_gmv_month PARTITION (ds='$yesterday') select ssi.province_id, (case when price>0.0 and price<=10.0 then 0 when price>10.0 and price<=20.0 then 1 when price>20.0 and price<=30.0 then 2 when price>30.0 then 3 else -1 end) as price_area, ssi.product_id, ssi.sell_num from (select s.good_receiver_province_id as province_id, si.product_id, sum(si.order_item_num) as sell_num, sum(si.order_item_amount)/sum(si.order_item_num) as price from so_item si join so s on (si.order_id=s.id) where si.is_hidden=0 and si.is_gift=0 and si.ds between '$lastmonth' and '$yesterday' group by s.good_receiver_province_id, si.product_id) ssi;
EOF # execute the combineorder algorithm job
cd /
cd /home/deploy/recsys/algorithm/schedule/project/combineorder/schedule/pms_category_rec_prod
hadoop jar /home/deploy/recsys/algorithm/schedule/project/combineorder/schedule/recommender-dm-1.0-SNAPSHOT.jar com.yhd.recommender.combineorder.schedule.CombineorderRecommendScheduler # export "pms_category_rec_prod" data to mysql
cd /
cd /home/deploy/recsys/algorithm/schedule/project/combineorder/schedule/pms_category_rec_prod
hadoop jar /home/deploy/recsys/algorithm/schedule/project/combineorder/schedule/recommender-dm-1.0-SNAPSHOT.jar com.yhd.recommender.exporter.db.HdfsToDBProcessor # check "yhd_gmv_month" is exist
yesterday=$(date -d '-1 day' '+%Y-%m-%d')
hadoop fs -test -e /user/hive/warehouse/yhd_gmv_month/ds=2014-08-27
if [ $? -ne 0 ] ;then
echo 'Error! Directory is not exist'
else
# auto modify date time
oldestVersionDay=$(date -d '-3 day' '+%Y-%m-%d')
olderVersionDay=$(date -d '-2 day' '+%Y-%m-%d')
newVersionDay=$(date -d '-1 day' '+%Y-%m-%d') sed -r -i '{s/oldestVersion=\/user\/hive\/warehouse\/yhd_gmv_month\/ds=.*/oldestVersion=\/user\/hive\/warehouse\/yhd_gmv_month\/ds='"${oldestVersionDay}"'/}' /home/deploy/recsys/algorithm/schedule/verifaction/combineorder/yhd_gmv_month/input/verification.properties
sed -r -i '{s/olderVersion=\/user\/hive\/warehouse\/yhd_gmv_month\/ds=.*/olderVersion=\/user\/hive\/warehouse\/yhd_gmv_month\/ds='"${olderVersionDay}"'/}' /home/deploy/recsys/algorithm/schedule/verifaction/combineorder/yhd_gmv_month/input/verification.properties
sed -r -i '{s/newVersion=\/user\/hive\/warehouse\/yhd_gmv_month\/ds=.*/newVersion=\/user\/hive\/warehouse\/yhd_gmv_month\/ds='"${newVersionDay}"'/}' /home/deploy/recsys/algorithm/schedule/verifaction/combineorder/yhd_gmv_month/input/verification.properties # export "yhd_gmv_month" data to mysql
cd /
cd /home/deploy/recsys/algorithm/schedule/project/combineorder/schedule/yhd_gmv_month hadoop jar /home/deploy/recsys/algorithm/schedule/project/combineorder/schedule/recommender-dm-1.0-SNAPSHOT.jar com.yhd.recommender.exporter.db.HdfsToDBProcessor
fi
Shell脚本运行hive语句 | hive以日期建立分区表 | linux schedule程序 | sed替换文件字符串 | shell推断hdfs文件文件夹是否存在的更多相关文章
- 基于sparksql调用shell脚本运行SQL
[Author]: kwu 基于sparksql调用shell脚本运行SQL,sparksql提供了类似hive中的 -e , -f ,-i的选项 1.定时调用脚本 #!/bin/sh # uplo ...
- shell脚本-循环选择语句
shell脚本-循环选择语句 过程式编程语言: 顺序执行 选择执行 循环执行 注:条件中的变量,可以在执行语句中使用,不用在加上"$". if语句 根据命令的退出状态来执行命令 单 ...
- shell 脚本之判断语句 if 详解
使用 Linux 系统这么长时间,对 shell 脚本也算是比较熟悉.其实不管是搞开发,还是搞运维,shell 脚本都是必备的基本技能.这次抽时间好好总结一下 shell 方面的知识,综合的再学习一下 ...
- 将shell脚本运行情况写入Rsyslog日志server
在运维工作中,免不了编写一些脚本交由计划任务(cron)去定时运行完毕一些日常工作,实现运维工作自己主动化.比方在我的日常工作中备份数据是一项重要的工作,须要定时将数据备份到备份服器和一些其它的备份介 ...
- Linux Shell脚本编程while语句
Linux Shell脚本编程while语句案例 1,每隔3秒,打印一次系统负载 #!/bin/bash while truedo uptime sleep 3done 2,把监控结果保存 ...
- IDEA部署项目,并结合Shell脚本运行Java程序
一.概述 在实际开发中,我们写好的代码,往往打成war包或jar包,通过winscp或其他软件将其上传至服务器,然而这样非常大的一个弊端就是不利于开发,为什么这么说呢?假如我们刚刚将springboo ...
- shell脚本之循环语句与函数
shell脚本之循环语句与函数 echo的用法: echo -n #表示不换行输出 echo -e #输出转义字符,将转义后的内容输出到屏幕上 转义字符: \n :换行,被输出的字符从"\n ...
- shell 脚本运行 hive sql
#!/b START=$(date +%s); datebegin=`date -d "$1" "+%Y%m%d"` dateend=`date -d &quo ...
- 用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql
1:创建shell脚本 touch sqoop_options.sh chmod 777 sqoop_options.sh 编辑文件 特地将执行map的个数设置为变量 测试 可以java代码传参数 ...
随机推荐
- sql server中关于批处理与脚本的简单介绍
1.批处理 批处理指的是包含一条或多条T-SQL语句的语句组,这组语句从应用程序一次性地发送到SQL Server服务器执行.SQL Server服务器将批处理语句编译成一个可执行单元(即执行计划), ...
- Linux(Debain)环境安装WordPress
一.相关组件安装 1. 安装Apache apt-get install apache2 安装完毕后浏览器 http://localhost/ 或者 http://127.0.0.1 出现It Wor ...
- p95 3.5、3.8
3.5 有一农夫带一条狼,一只羊和一筐菜欲从河的左岸乘船到右岸,但受下列条件限制:(1)船太小,农夫每次只能带一样东西过河:(2)如果没有农夫看管,则狼要吃羊,羊要吃菜.请设计一个过河方案,是的农夫 ...
- C# 微信公众平台开发(3)-- 接受/发送消息
1.接收事件 关注/取消关注事件: 用户在关注与取消关注公众号时,微信会把这个事件推送到开发者填写的URL. 通过微信返回的XML,我们通过代码 就可以作相应的处理: 先获取返回的信息: if (Ht ...
- 创建Xml的将但方法和向Xml中添加数据
</SendUserId>// ::</DateTime></AcceptUserId> <AcceptUserId></Accept ...
- 制作一个vagrant的win7 box
准备: 1.win7镜像文件 2.vagrant安装文件 3.virtual box安装文件 步骤: 1.先在本机上安装virtualbox和vagrant,本机为win7,安装虚机也为win7 2. ...
- codeforces 522D. Closest Equals 线段树+离线
题目链接 n个数m个询问, 每次询问输出给定区间中任意两个相同的数的最近距离. 先将询问读进来, 然后按r从小到大排序, 将n个数按顺序插入, 并用map统计之前是否出现过, 如果出现过, 就更新线段 ...
- makefile 里面 := 和 = 的区别
此文版权属于作者所有,任何人.媒体或者网站转载.借用都必须征得作者本人同意! 参考:What is the colon equals sign ( := ) in makefiles? Makefil ...
- C++设计模式实现--组合(Composite)模式
一. 举例 这个样例是书上的,如果有一个公司的组结结构例如以下: 它的结构非常像一棵树,当中人力资源部和財务部是没有子结点的,详细公司才有子结点. 并且最关健的是,它的每一层结构非常相似. 代码实现例 ...
- 理解SQL SERVER中的分区表
转自:http://www.cnblogs.com/sienpower/archive/2011/12/31/2308741.html 简介 分区表是在SQL SERVER2005之后的版本引入的特性 ...