我可以将数据从一个配置单元分区移动到同一个表的另一个分区

时间:2018-01-24 13:32:26

标签: hive hive-partitions

我的分区基于年/月/日。在一周中使用SimpleDateFormat创建了一个错误的分区。使用日期格式的YYYY将2017-31-12日期的数据移至2018-31-12。

   SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");

所以我想要的是将我的数据从分区2018/12/31移动到同一个表的2017/12/31。我没有找到任何相关的文档来做同样的事情。

2 个答案:

答案 0 :(得分:0)

有一个与https://issues.apache.org/jira/browse/SPARK-19187相关的JIRA。将spark版本升级到2.0.1应解决问题

答案 1 :(得分:0)

据我所知,您希望将数据从2018-12-31分区移至2017/12/31。以下是我对如何做到这一点的解释。

#From Hive/Beeline
ALTER TABLE TableName PARTITION (PartitionCol=2018-12-31) RENAME TO PARTITION (PartitionCol=2017-12-31);

FromSparkCode,你基本上必须启动hiveContext并从中运行相同的HQL。您可以参考我的答案here,了解如何启动配置单元上下文。

#If you want to do on HDFS level, below is one of the approaches
#FromHive/beeline run the below HQL
ALTER TABLE TableName ADD IF NOT EXISTS PARTITION (PartitionCol=2017-12-31);

#Now from HDFS Just move the data in 2018 to 2017 partition
hdfs dfs -mv /your/table_hdfs/path/schema.db/tableName/PartitionCol=2018-12-31/* /your/table_hdfs/path/schema.db/tableName/PartitionCol=2017-12-31/

#removing the 2018 partition if you require
hdfs dfs -rm -r /your/table_hdfs/path/schema.db/tableName/PartitionCol=2018-12-31

#You can also drop from beeline/hive
alter table tableName drop if exists partition (PartitionCol=2018-12-31);

#At the end repair the table
msck repair table tableName

Why do i have to repair the table ??

相关问题