当我像下面这样编写配置单元查询时
select count(*)
from order
where order_month >= '2016-11';
阶段1的hadoop作业信息:Map器数量:5;减速器数量:1
我只得到5个Map器,这意味着只读取所需的分区(2016-11和2016-12)
与我使用函数编写的查询相同
select count(*)
from order
where order_month >= concat(year(DATE_SUB(to_date(from_unixtime(UNIX_TIMESTAMP())),10)),'-',month(DATE_SUB(to_date(from_unixtime(UNIX_TIMESTAMP())),10)));
注:
concat(年(date \u sub(to \u date(from \u unixtime(unix \u timestamp())),10)),'-',月(date \u sub(to \u date(from \u unixtime(unix \u timestamp())),10))='2016-11'
阶段1的hadoop作业信息:Map器数量:216;减速器数量:1
这次它读取所有分区{2004-10到2016-12}。
如何将查询修改为只读取所需的分区。
1条答案
按热度按时间x33g5p2x1#
unix_timestamp()
函数是不确定的,并且会阻止查询的适当优化-这从2.0开始就被弃用,取而代之的是CURRENT_TIMESTAMP
以及CURRENT_DATE
.使用当前日期,也不需要分别计算年和月: