my spark sql limit is very slow

有些话、适合烂在心里 提交于 2019-12-08 21:36:30

问题


I use spark to read from elasticsearch.Like

select col from index limit 10;

The problem is that the index is very large, it contains 100 billion rows.And spark generate thousands of tasks to finish the job.
All I need is 10 rows, even 1 tasks returns 10 rows that can finish the job.I don't need so many tasks.
Limit is very slow even limit 1.
Code:

sql = select col from index limit 10
sqlExecListener.sparkSession.sql(sql).createOrReplaceTempView(tempTable)

回答1:


The source code of limit shows that it will take the first limit elements for every partition, and then it will scan all partitions.

To speed up the query you can specify one value of the partition key. Suppose that you are using day as the partition key, the following query will be much faster

select col from index where day = '2018-07-10' limit 10;


来源:https://stackoverflow.com/questions/47565131/my-spark-sql-limit-is-very-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!