Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this exam
Question 83

The code block shown below should use SQL to return a new DataFrame containing column storeId and column managerName from a table created from DataFrame storesDF. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.

Code block:

__1__.__2__("stores")

__3__.__4__("SELECT storeId, managerName FROM stores")

    Correct Answer: D

    To return a new DataFrame containing the columns 'storeId' and 'managerName' from the table created from the DataFrame 'storesDF', the appropriate steps include creating a temporary view of the DataFrame using 'createOrReplaceTempView' method and then executing an SQL query using Spark SQL. The correct sequence is: spark.createOrReplaceTempView('stores') to create the temporary view, and subsequently, spark.sql('SELECT storeId, managerName FROM stores') to run the SQL query, providing the new DataFrame with the specified columns. Hence, the correct option is D.

Discussion
Sowwy1Option: E

It's E. df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"]) df.createTempView("people") df2 = spark.sql("SELECT * FROM people")

Samir_91Option: E

It's E

Sowwy1Option: E

It's E

tangerine141Option: D

spark.createOrReplaceTempView("stores") storesDF.sql("SELECT storeId, managerName FROM stores")

naman405verma

no Bro https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.createTempView.html check this E is correct only

Samir_91

spark.createOrReplaceTempView("stores") gives an error AttributeError: 'SparkSession' object has no attribute 'createOrReplaceTempView'