1、對數據進行歸檔
alter table tableName archive partition(current='2020-07-02');
報錯如下:
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org/apache/hadoop/tools/HadoopArchives
查看hive的日志,日志文件在 ls /tmp/${USER}/hive.log
java.lang.NoClassDefFoundError: org/apache/hadoop/tools/HadoopArchives
3、分析
hive在進行歸檔的時候需要使用到hadoop的archive相關的類,但是在hive的lib目錄下面沒有。
2、解決辦法:
從hadoop的lib目錄下拷貝archive相關類到hive的lib下面
① 找到相關類
[hduser@yjt hive]$ find /data1/hadoop/hadoop/ -name *archive*
② 拷貝
cp /data1/hadoop/hadoop/share/hadoop/tools/lib/hadoop-archives-2.9.2.jar /data1/hadoop/hive/lib/
3、開啟archive功能
hive> set hive.archive.enabled=true;
4、測試
歸檔前:
開始歸檔:
hive> alter table hive_text archive partition(folder='docs');
intermediate.archived is hdfs://yjt:9000/user/test/hive_text/folder=docs_INTERMEDIATE_ARCHIVED
intermediate.original is hdfs://yjt:9000/user/test/hive_text/folder=docs_INTERMEDIATE_ORIGINAL
Creating data.har for hdfs://yjt:9000/user/test/hive_text/folder=docs
in hdfs://yjt:9000/user/test/hive_text/folder=docs/.hive-staging_hive_2020-07-07_14-39-31_376_7443789806325398792-1/-ext-10000/partlevel
Please wait... (this may take a while)
Moving hdfs://yjt:9000/user/test/hive_text/folder=docs/.hive-staging_hive_2020-07-07_14-39-31_376_7443789806325398792-1/-ext-10000/partlevel to hdfs://yjt:9000/user/test/hive_text/folder=docs_INTERMEDIATE_ARCHIVED
Moving hdfs://yjt:9000/user/test/hive_text/folder=docs to hdfs://yjt:9000/user/test/hive_text/folder=docs_INTERMEDIATE_ORIGINAL
Moving hdfs://yjt:9000/user/test/hive_text/folder=docs_INTERMEDIATE_ARCHIVED to hdfs://yjt:9000/user/test/hive_text/folder=docs
OK
歸檔后:
5、解壓歸檔文件
hive> alter table hive_text unarchive partition(folder='docs');