nerdexam
Databricks

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

Which of the following code blocks uses SQL to return a new DataFrame containing column storeId and column managerName from a table created from DataFrame storesDF?

The correct answer is D. storesDF.createOrReplaceTempView("stores"). To query a DataFrame using Spark SQL, you must first register it as a temporary view using createOrReplaceTempView('viewName'), then call spark.sql('SELECT ...'). Choice D - storesDF.createOrReplaceTempView('stores') - correctly registers the DataFrame as a temp view named…

Data Manipulation with Spark SQL

Question

Which of the following code blocks uses SQL to return a new DataFrame containing column storeId and column managerName from a table created from DataFrame storesDF?

Options

  • AstoresDF.createOrReplaceTempView()
  • BstoresDF.query("SELECT storeid, managerName from stores")
  • Cspark.createOrReplaceTempView("storesDF")
  • DstoresDF.createOrReplaceTempView("stores")
  • EstoresDF.createOrReplaceTempView("stores")

How the community answered

(22 responses)
  • C
    5% (1)
  • D
    86% (19)
  • E
    9% (2)

Explanation

To query a DataFrame using Spark SQL, you must first register it as a temporary view using createOrReplaceTempView('viewName'), then call spark.sql('SELECT ...'). Choice D - storesDF.createOrReplaceTempView('stores') - correctly registers the DataFrame as a temp view named stores, which can then be queried with spark.sql('SELECT storeId, managerName FROM stores'). Choice A is missing the required view name argument. Choice B uses a non-existent .query() method. Choice C incorrectly calls createOrReplaceTempView on the spark session object rather than on the DataFrame - only DataFrames have this method.

Topics

#Spark SQL#DataFrame Operations#Temporary Views

Community Discussion

No community discussion yet for this question.

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