【问题标题】:Can i move data from one hive partition to another partition of the same table我可以将数据从一个配置单元分区移动到同一张表的另一个分区吗
【发布时间】:2018-01-24 13:32:25
【问题描述】:

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

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

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

【问题讨论】:

    标签: hive hive-partitions


    【解决方案1】:

    据我了解,您想将数据从 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 来了解如何启动 hive 上下文。

    #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 ??

    【讨论】:

    • 谢谢罗伯。我使用了蜂巢方法,它奏效了。 :)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多