Hive分区参数配置

Hive本身是不支持动态分区的..

但动态分区是真的方便啊..不然手动维护要累死..按日期甚至小时来分区时动辄就好几千上万的分区..手动到哪一年去..?

想要用动态分区要先做一些设置来修改默认的配置..

set hive.exec.dynamic.partition=true;(可通过这个语句查看:set hive.exec.dynamic.partition;) 
set hive.exec.dynamic.partition.mode=nonstrict; 
SET hive.exec.max.dynamic.partitions=100000;(如果自动分区数大于这个参数,将会报错)
SET hive.exec.max.dynamic.partitions.pernode=100000;
set hive.exec.max.created.files=100000;

可以直接把上述设置项在控制台中运行一下..以后就可以自由动态分区了..

建立分区表的语法.

Drop table table_name; --先删除表 没有则直接建表了
CREATE TABLE table_name    --创建表
(col1 string, col2 date, col3 double) 
partitioned by (datekey date)  --可以多个字段的组合分区 
 ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' Stored AS TEXTFILE;

插入数据..

复制代码
INSERT INTO TABLE table_Name

PARTITION (DateKey)

SELECT col1,col2,col3,DateKey FROM otherTable

WHERE DATEKEY IN ('2017-02-26','2013-06-12','2013-09-24')

GROUP BY col1,col2,col3,DateKey  

DISTRIBUTE BY DateKey
复制代码

删除分区:

ALTER TABLE table_Name DROP PARTITION (Datekey='2016-05-05');

猜你喜欢

转载自blog.csdn.net/gyxinguan/article/details/80402533
今日推荐