使用一个脚本创建多个月的配置单元分区 [英] Creating hive partitions for multiple months using one script

查看:79
本文介绍了使用一个脚本创建多个月的配置单元分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4年的数据。像

 '2011 
2012
2013
2014'

我必须根据一个月的数据运行查询。所以我创建分区如下。

 'ALTER TABLE table1_2010Jan ADD PARTITION(year ='2010',month = '01' ,day = '01')
LOCATION'path';
ALTER TABLE table1_2010Jan ADD PARTITION(year ='2010',month = '01',day = '02')
LOCATION'path';
ALTER TABLE table1_2010Jan ADD PARTITION(year ='2010',month = '01',day = '03')
LOCATION'path';'

我在每个月的每一天都创建像上面一样的分区。



我想知道如果我们可以编写一个脚本(任何语言),每次运行一次为每个月的所有日期创建这些分区?或者有没有办法在配置单元本身做到这一点。



任何建议请。

解决方案

对于外部表,配置单元不能这样做。您可以创建shell / perl脚本来执行相同的操作(使用循环)。



对于配置单元托管表,您可以使用MSCK REPAIR命令轻松完成操作。



https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-RecoverPartitions%28MSCKREPAIRTABLE%29



只有你必须确保数据加载的是正确的分区。


I have data for 4 years. Like

'2011
 2012
 2013
 2014'

I have to run queries based on one month's data. So i am creating partitions as below.

'ALTER TABLE table1_2010Jan ADD PARTITION(year='2010', month='01', day='01')
 LOCATION 'path';
 ALTER TABLE table1_2010Jan ADD PARTITION(year='2010', month='01', day='02')
 LOCATION 'path';
 ALTER TABLE table1_2010Jan ADD PARTITION(year='2010', month='01', day='03')
 LOCATION 'path';'

I am creating individual partitions like above for every day of every month.

I want to know if we can write a script(any language) an run it one time to create these partitions for the all the days of a month for every year? Or is there a way to do this in hive itself.

Any suggestions please..

解决方案

For external table , hive can not do it. You can create shell/perl script to to do the same (using loop).

For hive managed table, you can do it easily using MSCK REPAIR command.

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-RecoverPartitions%28MSCKREPAIRTABLE%29

Only thing you have to ensure that the data is loaded is correct partition.

这篇关于使用一个脚本创建多个月的配置单元分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆