QuestionQ42

VerifiedUsing Spark SQL

The code block below has an error. It is intended to use SQL to return a new DataFrame with the storeId and managerName columns from a table created from DataFrame storesDF. Identify the error.

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

DataFrame.createOrReplaceTempView() correctly makes the DataFrame available as a local temporary SQL view. SQL queries that return DataFrames are executed through the associated SparkSession, using spark.sql("SELECT storeId, managerName FROM stores"); sql() is not a DataFrame method.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!