hive establish the partition table to today's date ( "2014-08-15") as the partition basis, hql as follows:
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;
Then the date as the partitioning, data insertion, shell scripts as follows:
#!/bin/bash
source /etc/profile;
yesterday=$(date -d '-1 day' '+%Y-%m-%d')
lastweek=$(date -d '-1 week' '+%Y-%m-%d')
/ usr / local / Cloud / Hive / bin / the EOF << Hive
the INSERT TABLE product_sell the OVERWRITE the PARTITION (DS = '$ Yesterday') SELECT a.category_id, b.good_receiver_province_id province_id AS, AS a.id the 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 this part of the difficulty is that hive does not know how to call way shaped like a shell variable date of the creation date of partition, mark it!