Resolution: Won't Fix
Affects Version/s: 3.2.0
Fix Version/s: None
When querying only the partition columns of a partitioned table, it seems that Spark nonetheless scans through all files in the table, even though it doesn't need to.
Here's an example:
Note the 1158 tasks. This matches the number of partitions in the table, which is partitioned on a single field named file_date:
The table itself has over 138K files, though:
Now let's try to query just the file_date field and see what Spark does.
Notice that Spark has spun up 41,011 tasks. Maybe more will be needed as the job progresses? I'm not sure.
What I do know is that this operation takes a long time (~20 min) running from my laptop, whereas to list the top-level file_date partitions via the AWS CLI take a second or two.
Spark appears to be going through all the files in the table, when it just needs to list the partitions captured in the S3 "directory" structure. The query is only touching file_date, after all.
The current workaround for this performance problem / optimizer wastefulness, is to query the catalog directly. It works, but is a lot of extra work compared to the elegant query against file_date that users actually intend.
Spark should somehow know when it is only querying partition fields and skip iterating through all the individual files in a table.
Tested on Spark 3.0.1.