首页 文章

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

提问于
浏览
0

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

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

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

2 回答

  • 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。您可以参考我的答案这里中有关如何启动配置单元上下文的信息。

    #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
    

    为什么我要修理桌子?

  • 0

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

相关问题