Databricks Certified Associate Developer for Apache Spark — Question 138
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?
Answer options
- A. storesDF.createOrReplaceTempView() spark.sql("SELECT storeId, managerName FROM stores")
- B. storesDF.query(”SELECT storeid, managerName from stores")
- C. spark.createOrReplaceTempView("storesDF") storesDF.sql("SELECT storeId, managerName from stores")
- D. storesDF.createOrReplaceTempView("stores") spark.sql("SELECT storeId, managerName FROM stores")
- E. storesDF.createOrReplaceTempView("stores") storesDF.query("SELECT storeId, managerName FROM stores")
Correct answer: D
Explanation
Option D is correct because it properly creates a temporary view named 'stores' from storesDF and then executes a SQL query to select the desired columns. The other options either do not create the view correctly or use incorrect methods for querying, making them invalid for the task at hand.