Databricks Certified Data Engineer Associate — Question 153
A data engineer has a Python variable table_name that they would like to use in a SQL query. They want to construct a Python code block that will run the query using table_name.
They have the following incomplete code block:
____(f"SELECT customer_id, spend FROM {table_name}")
What can be used to fill in the blank to successfully complete the task?
Answer options
- A. spark.delta.sql
- B. spark.sql
- C. spark.table
- D. dbutils.sql
Correct answer: B
Explanation
The correct answer is B, as spark.sql is the method used to execute SQL queries in Spark. The other options, such as spark.delta.sql and spark.table, serve different purposes and cannot execute a SQL statement directly.