When a column is never used in an action in spark sql, is it ever loaded into memory?

Viewed 278

When I have many columns in a Spark DataFrame, but just some of them are used, is Spark smart enough to never load into memory the unused columns?

1 Answers

In most cases spark's optimizer should be smart enough to only load needed columns (projection pushdown). This is especially powerful for columnar file formats such as parquet, it means that not the entire file(s) needs to be read.

But I think in some cases its still better to make an explicit select statement, I think I have seen cases where the projection pushdown did not work well enough, mostly in very complex queries.

To be sure, use spark's df.explain

Related