hive建立分區表,以當天日期(“2014-08-15”)作為分區依據,hql如下:
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;
然後以日期作為分區依據,插入數據,shell腳本如下:
#!/bin/bash source /etc/profile; today=$(date +%Y-%m-%d) /usr/local/cloud/hive/bin/hive<這個部分難點在於hive中不知道如何調用形如shell日期變量的方式創建日期分區,mark一下!