【问题标题】:Hive doesn't pick up partition with the calculated partition keyHive 不使用计算的分区键选择分区
【发布时间】: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

标签: hive hiveql


【解决方案1】:

如果第一个查询有效,您最后一个传递 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

如果没有引号,它会像这样解决where dt=2020-12-12 - 这是错误的,应该是单引号。

至于使用unix_timestamp() - the function is not deterministic and prevents proper query optimization

请改用current_datecurrent_timestamp

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    相关资源
    最近更新 更多