hive表show partitions时显示分区数与实际的分区数不符问题
·
hive表show partitions时显示分区数与实际的分区数不符问题
--创建分区表
CREATE TABLE ypg_0116(
clientcode string,
addresscname string)
PARTITIONED BY (
etl_date string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'field.delim'='|',
'serialization.format'='|')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://hacluster/user/hive/warehouse/test/ypg_0116'
TBLPROPERTIES (
'bucketing_version'='2',
'transient_lastDdlTime'='1705408871')
--写入数据到分区表
insert into ypg_0116 values ('1','one','20250101');
insert into ypg_0116 values ('2','two','20250102');
insert into ypg_0116 values ('3','three','20250103');
--手工删除hdfs对应分区的数据
hadoop fs -rm -r hdfs://hacluster/user/hive/warehouse/test/ypg_0116/etl_date=20250101
--修复分区
msck repair table ypg_0116;
--查看分区
show partitions ypg_0116;
+--------------------+
| partition |
+--------------------+
| etl_date=20250101 |
| etl_date=20250102 |
| etl_date=20250103 |
+--------------------+
3 rows selected (0.441 seconds)
--查询分区数据
select etl_date,count(1) from ypg_0116 group by etl_date order by etl_date;
+-----------+------+
| etl_date | _c1 |
+-----------+------+
| 20250102 | 1 |
| 20250103 | 1 |
+-----------+------+
2 rows selected (60.448 seconds)
--为解决分区不一致的情况,需手工删除分区
alter table ypg_0116 drop partition (etl_date=20250101);
更多推荐




所有评论(0)