
Explanation:
To use SQL on a DataFrame, you must first create a temporary view. Option D correctly registers the DataFrame as a temp view named 'stores' using createOrReplaceTempView("stores") and then queries it with spark.sql(), which returns a new DataFrame. Other options have issues: A misses the view name, B and E use non-existent query method for SQL, and C incorrectly calls createOrReplaceTempView on SparkSession.
Ultimate access to all questions.
No comments yet.
Which of the following code blocks uses SQL syntax to create a new DataFrame with columns storeId and managerName from a table derived from the storesDF DataFrame?
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")