首先認識什麼是分區
Hive 中的分區就是分目錄,把一個大的數據集根據業務需要分割成更下的數據集。
1. 如何定義分區,創建分區
hive> create table test(name string,sex int) partitioned by
(birth string, age string);
Time taken: 0.044 seconds
hive> alter table test add partition (birth='1980', age ='30');
Time taken: 0.079 seconds
hive> alter table test add partition (birth='1981', age ='29');
Time taken: 0.052 seconds
hive> alter table test add partition (birth='1982', age ='28');
Time taken: 0.056 seconds
hive> show partitions test;
birth=1980/age =30
birth=1981/age =29
birth=1982/age =28
2. 如何刪除分區
hive> alter table test drop partition (birth='1980',age='30');
3. 加載數據到指定分區
test partition(birth='1980-01-01',age='30');
創建分區原則: 最少粒度原則
4 向partition_test的分區中插入數據:
5 還可以同時向多個分區插入數據,0.7版本以後不存在的分區會自動創建,0.6之前的版本官方文檔上說必須要預先創建好分區: http://biansutao.blog.163.com/blog/static/6702418820115332453560/ |