赞
踩
MSCK REPAIR TABLE table_name;
执行后,Hive会检测如果HDFS目录下存在但表的metastore中不存在的partition元信息,更新到metastore中。
- CREATE TABLE `xxxxxx_uid_online`(
- `datehour` string,
- `halfhourtype` string,
- `uid` string,
- `roomid` string,
- `roomcreatoruid` string,
- `staytime` string)
- PARTITIONED BY (
- `pt_day` string)
- ROW FORMAT SERDE
- 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
- STORED AS INPUTFORMAT
- 'org.apache.hadoop.mapred.TextInputFormat'
- OUTPUTFORMAT
- 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
- LOCATION
- 'hdfs://emr-cluster/user/hive/warehouse/xxxxxx_uid_online'
- TBLPROPERTIES (
- 'transient_lastDdlTime'='1516865482')
2、查看分区信息- hive> show partitions xxxxxx_uid_online;
- OK
- Time taken: 0.048 seconds
3、复制数据- hadoop distcp hdfs://10.28.28.177:9000/user/hive/warehouse/xxxxxx_uid_online/2018-01-01 hdfs://emr-cluster/user/hive/warehouse/xxxxxx_uid_online/pt_day=2018-01-01
- hadoop distcp hdfs://10.28.28.177:9000/user/hive/warehouse/xxxxxx_uid_online/2017-12-31 hdfs://emr-cluster/user/hive/warehouse/xxxxxx_uid_online/pt_day=2017-12-31
- hadoop distcp hdfs://10.28.28.177:9000/user/hive/warehouse/xxxxxx_uid_online/2017-12-30 hdfs://emr-cluster/user/hive/warehouse/xxxxxx_uid_online/pt_day=2017-12-30
- hadoop distcp hdfs://10.28.28.177:9000/user/hive/warehouse/xxxxxx_uid_online/2017-12-29 hdfs://emr-cluster/user/hive/warehouse/xxxxxx_uid_online/pt_day=2017-12-29
- hadoop distcp hdfs://10.28.28.177:9000/user/hive/warehouse/xxxxxx_uid_online/2017-12-28 hdfs://emr-cluster/user/hive/warehouse/xxxxxx_uid_online/pt_day=2017-12-28
4、执行修复命令- hive> MSCK REPAIR TABLE xxxxxx_uid_online;
- OK
- Partitions not in metastore: xxxxxx_uid_online:pt_day=2017-12-28 xxxxxx_uid_online:pt_day=2017-12-29 xxxxxx_uid_online:pt_day=2017-12-30 xxxxxx_uid_online:pt_day=2017-12-31
- Repair: Added partition to metastore xxxxxx_uid_online:pt_day=2017-12-28
- Repair: Added partition to metastore xxxxxx_uid_online:pt_day=2017-12-29
- Repair: Added partition to metastore xxxxxx_uid_online:pt_day=2017-12-30
- Repair: Added partition to metastore xxxxxx_uid_online:pt_day=2017-12-31
- Time taken: 0.133 seconds, Fetched: 5 row(s)
如果目录格式不对,则会报错:- hive> MSCK REPAIR TABLE xxxxxx_uid_online;
- FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
5、查看分区信息- hive> show partitions xxxxxx_uid_online;
- OK
- pt_day=2017-12-28
- pt_day=2017-12-29
- pt_day=2017-12-30
- pt_day=2017-12-31
- pt_day=2018-01-01
- Time taken: 0.039 seconds, Fetched: 5 row(s)
注意:Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。