传递到分区的参数在配置单元中不起作用

kxkpmulp  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(412)

我想传递分区值作为参数。

SET runmdt = date_sub(current_date,5);

下面的查询工作正常。

SELECT
cal_id,caller_name,location
from
amobe_tbl a
WHERE a.create_dt IN
(select DISTINCT create_dt from mt_call 
WHERE create_dt between date_sub(current_date,20) and current_date)
and a.create_dt=${hiveconf:runmdt};

当插入到分区表时,它不工作。

SET runmdt = date_sub(current_date,5);
INSERT OVERWRITE TABLE amobe_tbl PARTITION (create_dt=${hiveconf:runmdt})
SELECT
cal_id,caller_name,location
from
amobe_tbl a
WHERE a.create_dt IN
(select DISTINCT create_dt from mt_call 
WHERE create_dt between date_sub(current_date,20) and current_date)
and a.create_dt=${hiveconf:runmdt};

失败:parseexception行1:92无法识别“date\u sub”附近的输入(常量create\u dt中的“current\u date”是日期数据类型)。
请帮帮我。
提前谢谢。

3bygqnnd

3bygqnnd1#

1

配置单元变量不过是一种文本替换机制。
替换是在解析和执行之前完成的。

hive> set hivevar:v1=se;
hive> set hivevar:v2=l;
hive> set hivevar:v3=ec;
hive> set hivevar:v4=t 1+;
hive> set hivevar:v5=2;
hive> ${hivevar:v1}${hivevar:v2}${hivevar:v3}${hivevar:v4}${hivevar:v5};
OK
3

2

使用动态分区

set hive.exec.dynamic.partition.mode=nonstrict;

SET runmdt = date_sub(current_date,5);
INSERT OVERWRITE TABLE amobe_tbl PARTITION (create_dt)
SELECT
cal_id,caller_name,location,${hiveconf:runmdt}
from
amobe_tbl a
WHERE a.create_dt IN
(select DISTINCT create_dt from mt_call 
WHERE create_dt between date_sub(current_date,20) and current_date)
and a.create_dt=${hiveconf:runmdt};

相关问题