【发布时间】:2016-12-06 12:12:04
【问题描述】:
我的外部表 auto1_tracking_events_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};
【问题讨论】:
-
我对此的猜测是 Hive 在进行任何过滤之前会计算表中每条记录的日期比较。您可以尝试将 where 子句过滤器更改为 dt=(select from_unixtime(unix_timestamp()-1*60*60*24, 'yyyy-MM-dd')) 以查看它是否首先计算日期。我也不确定您是否可以在 Hive 的 where 子句中进行选择,因此您可能需要对其进行内部联接。
-
是的。我想过尝试这样做,但不幸的是,在我的 Hive 版本中,子查询是不允许的。它们出现在 0.13