一、创建测试表
CREATE TABLE `ittemp`.`zxh_test1` (
`col1` VARCHAR(64) COMMENT '测试字段1',
`col2` INT COMMENT '测试字段2',
`col3` DECIMAL(16,2) COMMENT '测试字段3'
)
stored as parquet
PARTITIONED BY (`dt` varchar(8) comment '分区')
COMMENT '测试表1';
二、插入测试数据
insert overwrite `ittemp`.`zxh_test1` partition(dt='20220707') values ('a',1,1.1);
三、spark查询测试
select * from `ittemp`.`zxh_test1`;
四、通过hive新增字段
alter table `ittemp`.`zxh_test1` add columns ( `COL4` VARCHAR(40) comment '测试字段4');
五、spark查询测试(报hive metastore不一致)
select * from `ittemp`.`zxh_test1`;
六、通过hive更新TBLPROPERTIES
1、通过hive执行show create table `ittemp`.`zxh_test1`查看tblproperties信息
注:一般关注'spark.sql.sources.schema.part.0'参数值,当表字段过多时,可能存在 'spark.sql.sources.schema.part.1'、'spark.sql.sources.schema.part.2'等多个,需要关注涉及更新的字段信息在哪个参数里
2、 更新tblproperties值
alter table `ittemp`.`zxh_test1` set TBLPROPERTIES
(
'spark.sql.sources.schema.part.0'='{"type":"struct","fields":[{"name":"col1","type":"varchar(64)","nullable":true,"metadata":{"comment":"测试字段1"}},{"name":"col2","type":"integer","nullable":true,"metadata":{"comment":"测试字段2"}},{"name":"col3","type":"decimal(16,2)","nullable":true,"metadata":{"comment":"测试字段3"}},{"name":"col4","type":"varchar(40)","nullable":true,"metadata":{"comment":"测试字段4"}},{"name":"dt","type":"varchar(8)","nullable":true,"metadata":{"comment":"分区"}}]}'
);
七、再次通过spark查询,hive metastore不一致告警消失
select * from `ittemp`.`zxh_test1`;
转载:https://blog.csdn.net/mypowerhere/article/details/125758845