一起學Hive——使用MSCK命令修復Hive分割槽
最近在使用Hive的過程中,在備份資料時,經常會使用cp或mv命令來複製資料,將資料複製到我們新建備份表的目錄下面,如果不是分割槽表,則上面的操作之後,新建的備份表可以正常使用,但是如果是分割槽表的,一般都是使用alter table add partition命令將分割槽資訊新增到新建的表中,每新增一條分割槽資訊就執行一個alter table add partition命令,如果分割槽數量少還好辦,但是遇到分割槽數量多的情況,特別是分割槽數量大於50的情況,如果還是使用alter命令新增分割槽,那是一件耗時耗力的事情,還容易出錯。
幸運的是Hive提供了MSCK命令,用於修復表的分割槽,我們先看Hive官方是如果介紹MCSK命令的:
Hive stores a list of partitions for each table in its metastore. If, however, new partitions are directly added to HDFS (say by using hadoop fs -put command), the metastore (and hence Hive) will not be aware of these partitions unless the user runs ALTER TABLE table_name ADD PARTITION commands on each of the newly added partitions.
However, users can run a metastore check command with the repair table option:
MSCK REPAIR TABLE table_name;
which will add metadata about partitions to the Hive metastore for partitions for which such metadata doesn't already exist. In other words, it will add any partitions that exist on HDFS but not in metastore to the metastore. See HIVE-874 for more details. When there is a large number of untracked partitions, there is a provision to run MSCK REPAIR TABLE batch wise to avoid OOME. By giving the configured batch size for the property hive.msck.repair.batch.size it can run in the batches internally. The default value of the property is zero, it means it will execute all the partitions at once.
The equivalent command on Amazon Elastic MapReduce (EMR)'s version of Hive is:
ALTER TABLE table_name RECOVER PARTITIONS;
Starting with Hive 1.3, MSCK will throw exceptions if directories with disallowed characters in partition values are found on HDFS. Use hive.msck.path.validation setting on the client to alter this behavior; "skip" will simply skip the directories. "ignore" will try to create partitions anyway (old behavior). This may or may not work.
翻譯成中文的大概意思就是:Hive將每個表的分割槽資訊儲存在metastore中,如果透過hadoop fs -put命令直接將分割槽資訊新增到HDFS,metastore是不會感知到這些新增的分割槽,除非執行了ALTER TABLE table_name ADD PARTITION命令。但是使用者可以執行metastore檢查命令MSCK REPAIR TABLE table_name;
該命令將關於分割槽的元資訊新增到Hive metastore中,這是對於那些沒有元資訊的分割槽來說的。換句話說,就是將任何存在於HDFS上但不在metastore上的分割槽新增到metastore。
下面介紹如果使用MSCK命令,建立了一個bigdata17_partition表,然後透過cp命令將幾個目錄的檔案複製到bigdata17_partition目錄下面,然後執行show partitions bigdata17_partition命令,將不會顯示分割槽的資訊:
hive> show partitions bigdata17_partition;OK Time taken: 1.121 seconds
然後執行MSCK REPAIR TABLE bigdata17_partition;命令新增分割槽:
hive> MSCK REPAIR TABLE bigdata17_partition;18/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 1012418/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 2123418/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 34678318/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 253216218/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 290119818/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 312908718/10/11 17:27:15 WARN log: Updating partition stats fast for: bigdata17_partition;18/10/11 17:27:15 WARN log: Updated size to 23190876OK Partitions not in metastore: bigdata17_partition;:dt=2018-09-15 bigdata17_partition;:dt=2018-09-16 bigdata17_partition;:dt=2018-09-17 bigdata17_partition;:dt=2018-09-18 bigdata17_partition;:dt=2018-09-19 bigdata17_partition;:dt=2018-09-20 bigdata17_partition;:dt=2018-09-21Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-15Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-16Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-17Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-18Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-19Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-20Repair: Added partition to metastore bigdata17_partition;:dt=2018-09-21Time taken: 0.613 seconds, Fetched 8 row(s)
透過上述的結果可以看到已經將bigdata17_partition表的分割槽資訊新增到Hive metastore中,和add partition命令比起來既方便又高效。
有點需要注意的是,分割槽的目錄結構必遵循
/partition_name=partition_value/結構,否則msck無法自動新增分割槽,只能使用add partition命令。
作者:Summer哥
出處:https://www.cnblogs.com/airnew/p/9776023.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1978/viewspace-2818552/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- HIVE基本語法以及HIVE分割槽Hive
- [Hive]hive分割槽設定注意事項Hive
- hive分割槽分桶Hive
- Hive動態分割槽Hive
- Hive的分割槽和排序Hive排序
- Hive和Spark分割槽策略HiveSpark
- Spark操作Hive分割槽表SparkHive
- Hive的靜態分割槽與動態分割槽Hive
- Hive動態分割槽詳解Hive
- hive學習筆記之四:分割槽表Hive筆記
- Hive中靜態分割槽和動態分割槽總結Hive
- hive分割槽和分桶你熟悉嗎?Hive
- hive Sql的動態分割槽問題HiveSQL
- hive 動態分割槽插入資料表Hive
- 【趙渝強老師】Hive的分割槽表Hive
- hive 分割槽表和分桶表區別Hive
- hive迷案之消失的分割槽檔案Hive
- Hive shell 命令Hive
- hive從入門到放棄(四)——分割槽與分桶Hive
- 好程式設計師大資料培訓分享Hive的靜態分割槽與動態分割槽程式設計師大資料Hive
- Hive學習之常用互動命令Hive
- hive建立分割槽表報錯AccessControlException Permission denied: user=NONE, access=WRITE, inodeHiveExceptionNone
- 好程式設計師大資料開發之掌握Hive的靜態分割槽與動態分割槽程式設計師大資料Hive
- 好程式設計師大資料學習路線分享hive分割槽和分桶程式設計師大資料Hive
- Hive學習之Hive的安裝Hive
- 電腦硬碟分割槽表損壞怎麼修復?電腦硬碟分割槽表損壞的修復方法硬碟
- Hive學習Hive
- hive 的使用Hive
- hive beeline使用Hive
- 使用hive增量更新Hive
- 【HIVE】hive 使用shell指令碼跑歷史資料Hive指令碼
- Hive --------- hive 的優化Hive優化
- [Hive]Hive排序優化Hive排序優化
- Windows啟動問題修復(重建活動分割槽)Windows
- LVM分割槽恢復LVM
- 【Hive】hive資料遷移Hive
- HIVE學習之(三)Hive
- HIVEHive