
Explanation:
The correct method to run a SQL query in a Databricks environment using a Python variable is by using spark.sql. The expression should be spark.sql(f"SELECT customer_id, spend FROM {table_name}"). Other options like spark.delta.sql, spark.table, and dbutils.sql are either incorrect or do not exist.
Ultimate access to all questions.
A data engineer has a Python variable named table_name that they intend to incorporate into a SQL query in order to dynamically reference a table. Their goal is to construct a Python code block capable of executing the SQL query which selects the columns customer_id and spend from the specified table referenced by table_name. They currently possess the following incomplete code block: ____(f"SELECT customer_id, spend FROM {table_name}"). What keyword or function should be used to fill in the blank to successfully complete this task?
A
spark.delta.sql
B
spark.sql
C
spark.table
D
dbutils.sql
No comments yet.