这个问题有点难,不过有些可以设置。
楼主应该不会超出限制,即使谷歌也没有超限这么一说。
分区的话,可以按照时间,
比如:
hive建立分区表,以当天日期(“2014-08-15”)作为分区依据,hql如下:
[mw_shl_code=sql,true]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; [/mw_shl_code]
然后以日期作为分区依据,插入数据,shell脚本如下:
[mw_shl_code=bash,true]#!/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/hive<<EOF
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 [/mw_shl_code]
这个部分难点在于hive中不知道如何调用形如shell日期变量的方式创建日期分区
下面有些参数可参考
[mw_shl_code=bash,true]开启动态分区:
hive.exec.dynamic.partition=true
默认值:false
描述:是否允许动态分区
hive.exec.dynamic.partition.mode=nonstrict
默认值:strict
描述:strict是避免全分区字段是动态的,必须有至少一个分区字段是指定有值的。
读取表的时候可以不指定分区。
设置如下参数配置动态分区的使用环境:
hive.exec.max.dynamic.partitions.pernode=100
默认值:100
描述:each mapper or reducer可以创建的最大动态分区数
hive.exec.max.dynamic.partitions=1000
默认值:1000
描述:一个DML操作可以创建的最大动态分区数
hive.exec.max.created.files=100000
默认值:100000
描述:一个DML操作可以创建的文件数[/mw_shl_code]
|