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

p8ekf7hl  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(283)

我的分区基于年/月/日。使用SimpleDataFormat for week year创建了一个错误的分区。2017-31-12日期的数据以日期格式使用yyyy移动到2018-31-12。

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

所以我想把数据从同一个表的分区2018/12/31移到2017/12/31。我没有找到任何相关的文件做同样的事。

ui7jx7zq

ui7jx7zq1#

与此相关的还有一个jirahttps://issues.apache.org/jira/browse/spark-19187. 将spark版本升级到2.0.1应该可以解决这个问题

nqwrtyyt

nqwrtyyt2#

据我所知,您希望将数据从2018-12-31分区移动到2017/12/31分区。下面是我对你如何做的解释。


# From Hive/Beeline

ALTER TABLE TableName PARTITION (PartitionCol=2018-12-31) RENAME TO PARTITION (PartitionCol=2017-12-31);

从sparkcode开始,基本上必须初始化hivecontext并从中运行相同的hql。关于如何启动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

为什么我要修table??

相关问题