gpt4 book ai didi

Hive 不使用计算的分区键选择分区

转载 作者:行者123 更新时间:2023-12-05 07:46:13 25 4
gpt4 key购买 nike

我的外部表 auto1_tracking_events_extdt 列上分区。

首先我执行:

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

没有引号,它的解析方式如下 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);

关于Hive 不使用计算的分区键选择分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40995125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com