Hive 蜂巢不';t使用计算出的分区键拾取分区

Hive 蜂巢不';t使用计算出的分区键拾取分区,hive,hiveql,Hive,Hiveql,我的外部表auto1\u tracking\u events\u ext在列dt上分区 首先,我执行: SET hive.exec.dynamic.partition.mode=nonstrict; SET hive.exec.dynamic.partition=true; 运行此查询时: select count(*) from auto1_tracking_events_ext where dt = '2016-12-05'; 它拾取分区,创建3个映射器,并在几秒钟内完成 但是,如果我运

我的外部表
auto1\u tracking\u events\u ext
在列
dt
上分区

首先,我执行:

SET hive.exec.dynamic.partition.mode=nonstrict;
SET hive.exec.dynamic.partition=true;
运行此查询时:

select count(*)
from auto1_tracking_events_ext
where dt = '2016-12-05';
它拾取分区,创建3个映射器,并在几秒钟内完成

但是,如果我运行以下命令:

select count(*)
from auto1_tracking_events_ext
where dt = from_unixtime(unix_timestamp()-1*60*60*24, 'yyyy-MM-dd');
它确实拾取分区并启动413个映射器,并且需要相当长的时间来计算

发布此问题时:

hive> select from_unixtime(unix_timestamp()-1*60*60*24, 'yyyy-MM-dd');
OK
2016-12-05
为什么Hive不拿起分区

更新:

将日期字符串作为hiveconf参数传递(如下所示)也没有帮助

hive -hiveconf date_yesterday=$(date --date yesterday "+%Y-%m-%d")
hive> select count(*) from auto1_tracking_events_ext where dt = ${hiveconf:date_yesterday};

如果第一个查询起作用,那么传递hiveconf变量的最后一个查询也应该起作用,因为变量将首先被替换,并且只有在执行该查询之后才被替换。这是一个可能的错误,您没有引用变量。试试这个:

hive -hiveconf date_yesterday=$(date --date yesterday "+%Y-%m-%d")
hive> select count(*) from auto1_tracking_events_ext where dt = '${hiveconf:date_yesterday}'; --single quotes here
如果没有引号,它的解析方式如下
,其中dt=2020-12-12
-这是错误的,它应该是单引号

至于使用
unix\u timestamp()
-

改用
当前\u日期
当前\u时间戳

select count(*)
from auto1_tracking_events_ext
where dt = date_sub(current_date,1);

我的猜测是,在进行任何筛选之前,Hive正在计算表中每个记录的日期比较。您可以尝试将where子句过滤器更改为dt=(从\u unixtime(unix\u timestamp()-1*60*60*24,'yyyy-MM-dd')中选择),以查看它是否首先计算日期。我也不确定您是否可以在配置单元中的where子句中使用select,因此您可能需要内部连接到它。是的。我想尝试一下,但不幸的是,在我的版本中,蜂巢子群是不允许的。它们出现在0.13中