nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #26

The code block shown below contains an error. The code block is intended to cache DataFrame storesDF only in Spark's memory and then return the number of rows in the cached DataFrame. Identify the…

The correct answer is E. The cache() operation can only cache DataFrames at the MEMORY_AND_DISK level (the. cache() is a convenience shorthand that always uses the MEMORY_AND_DISK storage level-it cannot be configured to use only memory. It does not accept any arguments. To cache a DataFrame exclusively in memory (no disk spillover), you must use persist(StorageLevel.MEMORY_ONLY)…

Spark DataFrame Persistence

Question

The code block shown below contains an error. The code block is intended to cache DataFrame storesDF only in Spark's memory and then return the number of rows in the cached DataFrame. Identify the error. Code block:

storesDF.cache().count()

Options

  • AThe cache() operation caches DataFrames at the MEMORY_AND_DISK level by default - the
  • BThe cache() operation caches DataFrames at the MEMORY_AND_DISK level by default - the
  • CThe storesDF DataFrame has not been checkpointed - it must have a checkpoint in order to be
  • DDataFrames themselves cannot be cached - DataFrame storesDF must be cached as a table.
  • EThe cache() operation can only cache DataFrames at the MEMORY_AND_DISK level (the

How the community answered

(23 responses)
  • A
    4% (1)
  • D
    4% (1)
  • E
    91% (21)

Explanation

cache() is a convenience shorthand that always uses the MEMORY_AND_DISK storage level-it cannot be configured to use only memory. It does not accept any arguments. To cache a DataFrame exclusively in memory (no disk spillover), you must use persist(StorageLevel.MEMORY_ONLY) instead. Since the intent is to cache only in memory, cache() is the wrong method to use for this specific requirement.

Topics

#Spark Caching#Storage Levels#DataFrame Persistence#Spark API

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice