Shell指令碼執行hive語句 | hive以日期建立分區表 | linux schedule程式

來源:互聯網
上載者:User

標籤:io   for   ar   art   linux   line   ad   on   

#!/bin/bashsource /etc/profile;################################################### Author: ouyangyewei                            ##                                                ## Content: Combineorder Algorithm                #################################################### change workspace to herecd /cd /home/deploy/recsys/workspace/ouyangyewei# generate product_sell datayesterday=$(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 DELIMITEDFIELDS 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 datayesterday=$(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 DELIMITEDFIELDS 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 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# exit hiveexit;# execute the combineorder algorithm jobcd /cd /home/deploy/recsys/workspace/ouyangyewei/schedule/pms_category_rec_prodhadoop jar /home/deploy/recsys/workspace/ouyangyewei/schedule/pms_category_rec_prod/recommender-dm-1.0-SNAPSHOT.jar com.yhd.recommender.combineorder.schedule.CombineorderRecommendScheduler# export "pms_category_rec_prod" data to mysqlcd /cd /home/deploy/recsys/workspace/ouyangyewei/schedule/pms_category_rec_prodhadoop jar /home/deploy/recsys/workspace/ouyangyewei/schedule/pms_category_rec_prod/recommender-merchantrank.jar com.yhd.recommender.exporter.db.HdfsToDBProcessor# export "yhd_gmv_month" data to mysqlcd /cd /home/deploy/recsys/workspace/ouyangyewei/schedule/yhd_gmv_monthhadoop jar /home/deploy/recsys/workspace/ouyangyewei/schedule/yhd_gmv_month/recommender-merchantrank.jar com.yhd.recommender.exporter.db.HdfsToDBProcessor

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.