Certified Data Engineer Associate Exam QuestionsBrowse all questions from this exam

Certified Data Engineer Associate Exam - Question 63


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?

Show Answer
Correct Answer: E

To execute a SQL query in a Spark environment using a Python variable, the correct method is to use spark.sql. This method allows you to run SQL queries directly on Spark DataFrames. Therefore, spark.sql(f"SELECT customer_id, spend FROM {table_name}") is the correct way to construct the code block.

Discussion

3 comments
Sign in to comment
meow_akkOption: E
Oct 22, 2023

E is correct you use spark.sql to execute python comamands

azure_bimonsterOption: E
Jan 20, 2024

E is correct

benni_aleOption: E
Apr 29, 2024

E is correct