QuestionQ203

VerifiedDevelopment and Ingestion

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?

Explanation

spark.sql() is the Databricks API method that executes SQL queries from Python code. It accepts an f-string with interpolated Python variables and returns results as a DataFrame. This allows seamless integration of SQL queries with Python variable substitution in notebooks and jobs.

Community Discussion

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