impala compute 命令

来源:互联网 发布:js触发a标签href跳转 编辑:程序博客网 时间:2024/05/16 12:14

此用法本人亲自在项目中实践过,表示很有效果。


项目迭代中用Impala逐步替换原有的Hive作为查询组件,速度有了脱胎换骨的飞跃。但在把原先按列存储的表转换成两个按行存储的表之后,联表查询的表现不那么给力了(原先对Hive的十倍速度优势变成了两倍)。
考虑到项目转用Impala是我的提议,调整存储结构也是我的提议,这个结果确实是个让我丢面子的事情,于是挽起袖子找优化查询的方案。

优化前

Query: select count(a.sn) from usermodel_inter_total_label a join usermodel_inter_total_info bon a.sn = b.sn where a.label = 'porn' and a.heat > 0.1 and b.platform = 'android'Returned 1 row(s) in 36.86s

寻路

先不管三七二十一,按SQL调优的套路来,explain一下发现了一个很隐蔽的warning:

WARNING: The following tables are missing relevant table and/or column statistics.default.usermodel_inter_total_info, default.usermodel_inter_total_label

这种waring,不是处(pian)女(zhi)座(kuang)发现不了!
先不忙,记下来,网上找那坑爹的Tuning Impala Performance文档看看(插个题外话,Impala的中文资料太寒酸了,做数据的矿工们已经全部投奔Spark阵营了么?),眼神掠过Column StatisticsTable Statistics的时候心里一凉,矿工的直觉告诉我「秘密就在这」!
大体意思就是通过预先分析表和列(对联表特别重要)的结构,并把这些信息保存到MetaStore,Impala查询时会利用这些信息优化查询的策略。
哟,这是个自动挡!
然后坑爹的文档就把我指到Hive的「ANALYZE TABLE」去了,试了半天Impala没反应啊,果然不是亲生兄弟~
祭出谷歌大法,噢,终于找到答案了,simple,naive!感觉找回了逝去的青春。

神奇指令

COMPUTE STATS usermodel_inter_total_info;COMPUTE STATS usermodel_inter_total_label;

优化后

Query: select count(a.sn) from usermodel_inter_total_label a join usermodel_inter_total_info bon a.sn = b.sn where a.label = 'porn' and a.heat > 0.1 and b.platform = 'android'Returned 1 row(s) in 3.15s

Cool!10倍的提升,相对Hive20倍的提升,和单表查询一样的迅速!

分析

以前老师总说对待问题要知其然更要知其所以然,那时特反感这一句,人生苦短,除了要大干快上,还要及时行乐,哪来的时间去知道那么多道理。
好了离题了,让我做一回现象的搬运工,让更聪明的读者来为我们解释吧。
「COMPUTE STATS」前
指令:

show table stats usermodel_inter_total_label;

返回:

log_date#Rows#FilesSizeBytes CachedFormat2014-12-13-1151.18GBNOT CACHEDTEXT2014-12-14-131.80GBNOT CACHEDTEXT2014-12-15-142.96GBNOT CACHEDTEXTTotal-1225.93GB0B-

指令:

show column stats usermodel_inter_total_label;

返回:

ColumnType#Distinct Values#NullsMax SizeAvg SizesnSTRING-1-1-1-1labelSTRING-1-1-1-1heatDOUBLE-1-1-1-1active_recordSTRING-1-1-1-1log_dateSTRING30-1-1

「COMPUTE STATS」后
指令:

show table stats usermodel_inter_total_label;

返回:

log_date#Rows#FilesSizeBytes CachedFormat2014-12-1394984382469.76MBNOT CACHEDTEXT2014-12-14178915951893.44MBNOT CACHEDTEXT2014-12-152788547321.37GBNOT CACHEDTEXTTotal5527550652.71GB0B-

指令:

show column stats usermodel_inter_total_label;

返回:

ColumnType#Distinct Values#NullsMax SizeAvg SizesnSTRING13984716-13024.0039005279541labelSTRING36-1134.26140022277832heatDOUBLE382126-188active_recordSTRING7-131.667400002479553log_dateSTRING30-1-1

看来「COMPUTE STATS」的作用就是得出Impala原先不知道的值(-1)。

0 0
原创粉丝点击