hive中关于 msck repair table 和with as的用法解释

在hive3.0之前我们一般建立hive外部表后,遇到增加字段或者修改字段类型长度等,我们习惯做法,删表重建后全表修复文件MSCK REPAIR TABLE table_name,一般对于没有错误历史数据的表,这样修复是可以的。但是我们如果遇到一些比较复杂的场景,这时我们只需要修复特定分区即可 MSCK REPAIR TABLE table_name partition(pt_d=‘20200331’);
对于hive高版本 3.0以后,实践用msck此方法修复数据,会报异常。这时我们需要手动alter table table_name drop if exists partition(pt_d<=20200331,pt_d>=20200301);再增加分区alter table table_name add if not exists partition(pt_d=‘20200301’);不需msck数据会在增加分区自动修复。

对于hive中的with as用法如下:
–相当于建了个e临时表
with tmp as (select * from emp e where e.empno=7499)
select * from tmp;
很多初学者喜欢这样with tmp as select * from emp e where e.empno=7499 或者 with tmp as (select * from emp e where e.empno=7499) 是会报语法错误的。
–相当于建了e、d临时表
CREATE table lishibiaoname if not exist AS
WITH
e AS (select * from emp),
d AS (select * from dept)
select * from e, d where e.deptno = d.deptno;
实际上临时表 lishibiaoname是由select * from e, d where e.deptno = d.deptno;产生出来的不是 由select * from emp生成。

猜你喜欢

转载自blog.csdn.net/zwmonk/article/details/105441681