nerdexam
Databricks

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…

Submitted by rachelw· Apr 18, 2026ELT with Spark SQL and Python

Question

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}") Which of the following can be used to fill in the blank to successfully complete the task?

Options

  • Aspark.delta.sql
  • Bspark.delta.table
  • Cspark.table
  • Ddbutils.sql
  • Espark.sql

How the community answered

(59 responses)
  • B
    2% (1)
  • C
    3% (2)
  • D
    2% (1)
  • E
    93% (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

#Spark SQL#Python in Spark#SparkSession#Databricks Notebooks

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-DATA-ENGINEER-ASSOCIATE Practice