#!/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文件文件夹是否存在的更多相关文章

  1. 基于sparksql调用shell脚本运行SQL

    [Author]: kwu 基于sparksql调用shell脚本运行SQL,sparksql提供了类似hive中的 -e  , -f ,-i的选项 1.定时调用脚本 #!/bin/sh # uplo ...

  2. shell脚本-循环选择语句

    shell脚本-循环选择语句 过程式编程语言: 顺序执行 选择执行 循环执行 注:条件中的变量,可以在执行语句中使用,不用在加上"$". if语句 根据命令的退出状态来执行命令 单 ...

  3. shell 脚本之判断语句 if 详解

    使用 Linux 系统这么长时间,对 shell 脚本也算是比较熟悉.其实不管是搞开发,还是搞运维,shell 脚本都是必备的基本技能.这次抽时间好好总结一下 shell 方面的知识,综合的再学习一下 ...

  4. 将shell脚本运行情况写入Rsyslog日志server

    在运维工作中,免不了编写一些脚本交由计划任务(cron)去定时运行完毕一些日常工作,实现运维工作自己主动化.比方在我的日常工作中备份数据是一项重要的工作,须要定时将数据备份到备份服器和一些其它的备份介 ...

  5. Linux Shell脚本编程while语句

    Linux Shell脚本编程while语句案例 1,每隔3秒,打印一次系统负载 #!/bin/bash while truedo    uptime    sleep 3done 2,把监控结果保存 ...

  6. IDEA部署项目,并结合Shell脚本运行Java程序

    一.概述 在实际开发中,我们写好的代码,往往打成war包或jar包,通过winscp或其他软件将其上传至服务器,然而这样非常大的一个弊端就是不利于开发,为什么这么说呢?假如我们刚刚将springboo ...

  7. shell脚本之循环语句与函数

    shell脚本之循环语句与函数 echo的用法: echo -n #表示不换行输出 echo -e #输出转义字符,将转义后的内容输出到屏幕上 转义字符: \n :换行,被输出的字符从"\n ...

  8. shell 脚本运行 hive sql

    #!/b START=$(date +%s); datebegin=`date -d "$1" "+%Y%m%d"` dateend=`date -d &quo ...

  9. 用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql

    1:创建shell脚本 touch sqoop_options.sh chmod 777 sqoop_options.sh 编辑文件  特地将执行map的个数设置为变量  测试 可以java代码传参数 ...

随机推荐

  1. 五子棋Web版的开发(一)---搭建IDEA SSH环境

    最近公司都没啥事,我在完成了控制台版的本地五子棋后(github地址:https://github.com/lkq51/wuziqi_console2),想将他升级成为一个web版的五子棋游戏.因为公 ...

  2. BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队( RMQ )

    RMQ.. ------------------------------------------------------------------------------- #include<cs ...

  3. 射频识别技术漫谈(16)——Mifare UltraLight

    Mifare UltraLight又称为MF0,从UltraLight(超轻的)这个名字就可以看出来,它是一个低成本.小容量的卡片.低成本,是指它是目前市场中价格最低的遵守ISO14443A协议的芯片 ...

  4. Qt中QFtp获取带有中文的文件名称出现乱码的解决方法(执行操作前就转换编码)

    今天研究了一下QFtp这个类,发现访问得到的文件名称中一旦出现中文,不管怎么转换编码格式,最终显示出来的始终都是乱码.由于编码错误,我写了两个函数用于互相转换编码. 一个是由正常编码转为QFTP上所谓 ...

  5. 导入Excel加行公式和验证

    package com.sprucetec.tms.controller.fee.export; import com.sprucetec.tms.controller.base.BaseFeeExp ...

  6. 在VPS上安裝BT軟體Transmission

    在VPS上安裝BT軟體Transmission   作者: 窮苦人家的小孩 | 2009-12-04 55 Comments   VPS 還能怎玩?! 裝Proxy,裝VPN,這還不夠,我還用來掛種子 ...

  7. cocos2d-x中的尺寸之二

    接下来我们再做些坏事,比如给EGLView设置分辨率,代码如下: pEGLView->setDesignResolutionSize(240, 320, kResolutionExactFit) ...

  8. TableLayoutPanel 的使用

    VS自带控件TableLayoutPanel的功能应用网上都有资料.下面是使用中的一些问题. 1.动态加载控件时使用SetRowSpan.SetColumnSpan方法会使得界面响应缓慢 解决方案: ...

  9. asp导航条子菜单横向

    示意图:(代码红色部分为主要.) <%@ Master Language="C#" AutoEventWireup="true" CodeFile=&qu ...

  10. JavaScript算法描述(一)

    function swap(arr,index1,index2){ var temp=arr[index1]; arr[index1]=arr[index2]; arr[index2]=temp; } ...