Hive中的数据分区
2015-05-24 22:13
706 查看
首先认识什么是分区
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. 加载数据到指定分区
load data local inpath '/home/hadoop/data.log' overwrite into table
test partition(birth='1980-01-01',age='30');
创建分区原则: 最少粒度原则
4 向partition_test的分区中插入数据:
hive> insert overwrite table partition_test partition(stat_date='20110728',province='henan') select member_id,name from partition_test_input where stat_date='20110728' and province='henan';
5 还可以同时向多个分区插入数据,0.7版本以后不存在的分区会自动创建,0.6之前的版本官方文档上说必须要预先创建好分区:
hive>
> from partition_test_input
> insert overwrite table partition_test partition (stat_date='20110526',province='liaoning')
> select member_id,name where stat_date='20110526' and province='liaoning'
> insert overwrite table partition_test partition (stat_date='20110728',province='sichuan')
> select member_id,name where stat_date='20110728' and province='sichuan'
> insert overwrite table partition_test partition (stat_date='20110728',province='heilongjiang')
> select member_id,name where stat_date='20110728' and province='heilongjiang';
Total MapReduce jobs = 4
http://biansutao.blog.163.com/blog/static/6702418820115332453560/
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. 加载数据到指定分区
load data local inpath '/home/hadoop/data.log' overwrite into table
test partition(birth='1980-01-01',age='30');
创建分区原则: 最少粒度原则
4 向partition_test的分区中插入数据:
hive> insert overwrite table partition_test partition(stat_date='20110728',province='henan') select member_id,name from partition_test_input where stat_date='20110728' and province='henan';
5 还可以同时向多个分区插入数据,0.7版本以后不存在的分区会自动创建,0.6之前的版本官方文档上说必须要预先创建好分区:
hive>
> from partition_test_input
> insert overwrite table partition_test partition (stat_date='20110526',province='liaoning')
> select member_id,name where stat_date='20110526' and province='liaoning'
> insert overwrite table partition_test partition (stat_date='20110728',province='sichuan')
> select member_id,name where stat_date='20110728' and province='sichuan'
> insert overwrite table partition_test partition (stat_date='20110728',province='heilongjiang')
> select member_id,name where stat_date='20110728' and province='heilongjiang';
Total MapReduce jobs = 4
http://biansutao.blog.163.com/blog/static/6702418820115332453560/
相关文章推荐
- 大数据【五】Hive(部署;表操作;分区)
- hive按当天日期建立分区表 | 动态往日期分区插入数据
- 在Hive中如何实现数据分区
- Hive中的数据分区
- Sqoop 数据导入多分区Hive解决方法
- 利用sqoop1将mysql数据导入至hive多分区
- hive从查询中获取数据插入到表或动态分区
- hive 自动加载数据多分区目录
- hive从查询中获取数据插入到表或动态分区
- 数据迁移 mysql ——> Hive(按天分区)
- logstash传输自定义字段数据到hdfs进行分年月日分区,并且hive可以通过hiveQL快速查询数据
- 在Impala 和Hive里进行数据分区(1)
- hive从查询中获取数据插入到表或动态分区
- 以某列为分区ID,导入数据到HIVE
- HIVE的安装配置、mysql的安装、hive创建表、创建分区、修改表等内容、hive beeline使用、HIVE的四种数据导入方式、使用Java代码执行hive的sql命令
- 数据仓库(八)---hive的性能优化---hive动态分区
- hive导入CSV数据,使用动态分区重新分区
- hive从查询中获取数据插入到表或动态分区
- hive 同一个表不同分区的数据求和