我有一个连接这些表的查询。如何优化才能运行得更快?
val q = """
| select a.value as viewedid,b.other as otherids
| from bm.distinct_viewed_2610 a, bm.tets_2610 b
| where FIND_IN_SET(a.value, b.other) != 0 and a.value in (
| select value from bm.distinct_viewed_2610)
|""".stripMargin
val rows = hiveCtx.sql(q).repartition(100)表说明:
hive> desc distinct_viewed_2610;
OK
value string
hive> desc tets_2610;
OK
id int
other string 数据如下所示:
hive> select * from distinct_viewed_2610 limit 5;
OK
1033346511
1033419148
1033641547
1033663265
1033830989和
hive> select * from tets_2610 limit 2;
OK
1033759023
103973207,1013425393,1013812066,1014099507,1014295173,1014432476,1014620707,1014710175,1014776981,1014817307,1023740250,1031023907,1031188043,1031445197distinct_viewed_2610表有110万条记录,我正在尝试从表tets_2610中获得类似的id,它通过拆分第二列来获得200000行。
对于100000条记录,用两台机器完成这项工作需要8.5小时,一台机器有16 gb的内存,第二台机器有8 gb的内存和8个内核。
有没有优化查询的方法?

发布于 2017-10-27 22:04:13
现在,您正在进行笛卡尔连接。笛卡尔连接提供了1.1M*200K =2200亿行。笛卡尔连接后,按where FIND_IN_SET(a.value, b.other) != 0过滤
分析您的数据。如果'other‘字符串平均包含10个元素,那么分解它将在表b中得到220万行。如果假设只有1/10的行将连接,那么由于内部连接,您将有2.2M/10=220K行。
如果这些假设是正确的,那么分解数组和连接将比笛卡尔join+filter执行得更好。
select distinct a.value as viewedid, b.otherids
from bm.distinct_viewed_2610 a
inner join (select e.otherid, b.other as otherids
from bm.tets_2610 b
lateral view explode (split(b.other ,',')) e as otherid
)b on a.value=b.otherid你不需要这样做:
and a.value in (select value from bm.distinct_viewed_2610)对不起,我不能测试查询,请自己做。
发布于 2017-10-28 01:02:29
如果你正在使用orc formate,根据你的数据改变拼图,我会说选择范围分区。
选择适当的并行化以快速执行。
我已经回答了下面的链接可能会对你有帮助。
Spark doing exchange of partitions already correctly distributed
也请读一读
http://dev.sortable.com/spark-repartition/
https://stackoverflow.com/questions/46970552
复制相似问题