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

Certified Associate Developer for Apache Spark 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")

Show Answer
Correct Answer: DE

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

4 comments
Sign in to comment
Sowwy1Option: E
Apr 2, 2024

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

tangerine141Option: D
Feb 23, 2024

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

naman405verma
Feb 24, 2024

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
Jun 4, 2024

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

Sowwy1Option: E
Apr 5, 2024

It's E

Samir_91Option: E
Jun 4, 2024

It's E