如题,将hive查询到的结果插入动态分区表时,可以指定其中一列或几列为分区字段,剩下的几列为表中内容。
首先,需要在查询开始进行若干设置:
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=1000;
set io.sort.mb=1024;
然后
INSERT OVERWRITE TABLE T PARTITION (ds='20170524155200', hr)
SELECT
key
, value
, ds
, hr
FROM oldtable
WHERE
ds IS NOT NULL
AND hr>10
;
另外,向hive中传参可以采用如下方式:
myconf='20170524175200'
hive -e "INSERT OVERWRITE TABLE T PARTITION (ds='${myconf}', hr)
SELECT key, value, hr FROM srcpart WHERE ds is not null and hr>10;"