DATABRICKS-CERTIFIED-DATA-ENGINEER-ASSOCIATE · Question #74
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…
The correct answer is E. spark.sql. spark.sql() is the standard Databricks/PySpark method for executing SQL queries programmatically. It accepts a string argument, so wrapping it in an f-string allows you to interpolate a Python variable like table_name directly into the query. spark.delta.sql does not exist as a…
Question
Options
- Aspark.delta.sql
- Bspark.delta.table
- Cspark.table
- Ddbutils.sql
- Espark.sql
How the community answered
(59 responses)- B2% (1)
- C3% (2)
- D2% (1)
- E93% (55)
Explanation
spark.sql() is the standard Databricks/PySpark method for executing SQL queries programmatically. It accepts a string argument, so wrapping it in an f-string allows you to interpolate a Python variable like table_name directly into the query. spark.delta.sql does not exist as a method. spark.delta.table() and spark.table() load a table as a DataFrame but do not execute arbitrary SQL strings. dbutils does not have a sql() method - dbutils is for file system operations, secrets, and widgets.
Topics
Community Discussion
No community discussion yet for this question.