向一個定義了分區的空表中插入數據,命令如下:
insert overwrite table t_name
partition (par_1)
select t1.field1 as field1, t1.field2 as field2, t1.field3 as par_1
from (
select * from t3 where par_2=value2) t1
where t1.field1 not in (select field1from t2) ;
結果如下錯誤:
大概的意思是,在動態分區‘strict’模式下至少需要有一個’strict’列,可以通過設置hive.exec.dynamic.partition.mode=nonstrict來關閉’strict’模式。
至少需要一個’strict’分區列是指至少有一個分區列有至少一個值。
做如下設置:
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=1000;
運行成功。
set hive.exec.dynamic.partition.mode的設置貌似是一次性的,我自己使用的結果是設置完,跑一次插入之後,下一次對新的空動態分區表做插入,又報同樣的錯誤,又設置一次之後,運行成功。
需要注意的是,系統自動將最後partition後的select中的最後n個字段作爲n個分區列的值。