将hive模糊查询结果写入分区表中

需求:只保留表1中12月27号的数据  其他日期的都不要 然后将结果又放回表1

 最开始我是这种思路 :

       ~设置开启动态分区开关
  set hive.exec.dynamic.partition=true;

       ~严格模式

  set hive.exec.dynamic.partition.mode=strict; # strict/nonstrict
  默认为strict, 对于分区表, 若插入语句没有指定至少一个静态分区字段, 则执行失败

    就是得指定 partition(ds)    ps:ds是分区名 

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict; 
insert overwrite table finallyresult partition(ds)  select * from finallyresult where ds like '20181227%';

//三行同时执行,不然会报以下错误   这是开启hive动态分区

FAILED: SemanticException [Error 10096]: Dynamic partition strict mode requires at least one static partition column. To turn this off set hive.exec.dynamic.partition.mode=nonstrict


但是结果还是全表数据,like无效!!!!  不知道什么原因

之后这样写,创建了表2    将表1数据结果放入到表2,结果就正常了

复制表结构

create table 表2 like 表1;
//刷新新表分区
MSCK REPAIR TABLE 表2;

方法1:时间短

insert overwrite table newtable partition(ds)  select id,lon,lat,utc,tags,substring(ds,1,8)as ds from finallyresult where ds='20181227';

方法2:时间长

insert overwrite table newtable partition(ds)  select * from finallyresult where ds like '20181227%';

猜你喜欢

转载自blog.csdn.net/weixin_41804049/article/details/85288876
今日推荐