DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #80
The code block shown below should cache DataFrame storesDF only in Spark's memory. Choose the response that correctly fil ls in the numbered blanks within the code block to complete this task. Code…
The correct answer is E. 1. storesDF. To cache a DataFrame exclusively in Spark's memory (without spilling to disk), you must use persist(StorageLevel.MEMORY_ONLY). The simple cache() method in many Spark versions defaults to MEMORY_AND_DISK, which allows spilling to disk when memory is insufficient. The pattern…
Question
The code block shown below should cache DataFrame storesDF only in Spark's memory. Choose the response that correctly fil ls in the numbered blanks within the code block to complete this task. Code block:
1.2(3).count()
Options
- A
- storesDF
- B
- storesDF
- C
- storesDF
- D
- storesDF
- E
- storesDF
How the community answered
(55 responses)- A2% (1)
- B2% (1)
- D5% (3)
- E91% (50)
Explanation
To cache a DataFrame exclusively in Spark's memory (without spilling to disk), you must use persist(StorageLevel.MEMORY_ONLY). The simple cache() method in many Spark versions defaults to MEMORY_AND_DISK, which allows spilling to disk when memory is insufficient. The pattern storesDF.persist(StorageLevel.MEMORY_ONLY).count() explicitly specifies memory-only storage and calls count() to trigger the actual caching action (since Spark is lazily evaluated). Option E correctly fills blank 2 with persist and blank 3 with StorageLevel.MEMORY_ONLY.
Topics
Community Discussion
No community discussion yet for this question.