Impala 分区查询运行缓慢
Posted
技术标签:
【中文标题】Impala 分区查询运行缓慢【英文标题】:Impala partition queries running slow 【发布时间】:2017-02-07 15:42:59 【问题描述】:所以我试图用包含 1500 条不同记录的列“文件”对 Impala 表进行分区。这意味着 1500 个分区。我首先运行这样的查询来返回分区查询:
SELECT DISTINCT
concat('insert into partitioned_table partition (year=',
cast(year as string),', month=',cast(month as string),
') select c1, c2, c3 from raw_data where year=',
cast(year as string),' and month=',cast(month as string),';') AS command
FROM raw_data;
然后我要运行 1500 个查询。
Here is the screenshot
现在有一个问题:因为每个查询可能需要 3 分钟才能完成。 1500 个查询可能需要几天时间。这是一个很长的时间。为了节省时间,我已经做了一些调整:使用 COMPUTE STATS 获取静态数据,将 table 转换为 Parquet。我的问题是,有没有办法可以加快这个过程?像 Hive 一样最大化 executor 吗?
【问题讨论】:
【参考方案1】:您可以使用dynamic partitioning
insert into partitioned_table partition (year,month)
select c1, c2, c3, year, month
from raw_data
演示
create table t (i int) partitioned by (year string,month string);
insert into t partition (year,month) values
( 1,'2015','02')
,( 2,'2017','01')
,( 3,'2016','02')
,( 4,'2013','09')
,( 5,'2015','07')
,( 6,'2012','03')
,( 7,'2012','12')
,( 8,'2017','12')
,( 9,'2015','11')
,(10,'2015','02')
;
select * from t order by year,month,i;
+----+------+-------+
| i | year | month |
+----+------+-------+
| 6 | 2012 | 03 |
| 7 | 2012 | 12 |
| 4 | 2013 | 09 |
| 1 | 2015 | 02 |
| 10 | 2015 | 02 |
| 5 | 2015 | 07 |
| 9 | 2015 | 11 |
| 3 | 2016 | 02 |
| 2 | 2017 | 01 |
| 8 | 2017 | 12 |
+----+------+-------+
hdfs dfs -ls -R /user/hive/warehouse/t;
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2012
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2012/month=03
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2012/month=03/174c30c4e1edc236-b57504ce4afd76a2_1891304442_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2012/month=12
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2012/month=12/174c30c4e1edc236-b57504ce4afd76a2_798564417_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2013
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2013/month=09
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2013/month=09/174c30c4e1edc236-b57504ce4afd76a2_432428758_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2015
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2015/month=02
-rw-r--r-- 1 impala supergroup 5 2017-02-07 13:45 /user/hive/warehouse/t/year=2015/month=02/174c30c4e1edc236-b57504ce4afd76a2_768620898_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2015/month=07
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2015/month=07/174c30c4e1edc236-b57504ce4afd76a2_2029099237_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2015/month=11
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2015/month=11/174c30c4e1edc236-b57504ce4afd76a2_974618320_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2016
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2016/month=02
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2016/month=02/174c30c4e1edc236-b57504ce4afd76a2_502842645_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2017
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2017/month=01
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2017/month=01/174c30c4e1edc236-b57504ce4afd76a2_2014291428_data.0.
drwxr-xr-x - impala supergroup 0 2017-02-07 13:45 /user/hive/warehouse/t/year=2017/month=12
-rw-r--r-- 1 impala supergroup 2 2017-02-07 13:45 /user/hive/warehouse/t/year=2017/month=12/174c30c4e1edc236-b57504ce4afd76a2_1693475255_data.0.
【讨论】:
嗨 Dudu,在我运行这个查询一段时间后,它抛出一个异常: Could not connect to vn1.localdomain:21050 (code THRIFTTRANSPORT): TTransportException('Could not connect to vn1 .localdomain:21050',) .这是屏幕截图:link 我的猜测是 impala 可能由于多个并发读/写而耗尽内存。你怎么解决这个问题?谢谢 嗨亚伦。在没有日志的情况下解决它是有问题的 您可以尝试一个简单的解决方案 - 使用 where 子句运行插入,只获取部分数据。 附言。或者干脆在 Hive 中完成 我通过使用 where 子句分隔成功地对其进行了分区,现在它可以正常工作了。感谢您的帮助!以上是关于Impala 分区查询运行缓慢的主要内容,如果未能解决你的问题,请参考以下文章