DATABRICKS-DATA-ENGINEER-ASSOCIATE practice question 23 of 25

A data analyst has a series of queries in a SQL program. The data analyst wants this program to run every day. They only want the final query in the program to run on Sundays. They ask for help from the data engineering team to complete this task. Which of the following approaches could be used by the data engineering team to complete this task?

Full set: 177 questions
Answer options
A: They could submit a feature request with Databricks to add this functionality.
B: They could wrap the queries using PySpark and use Python’s control flow system to determine when to run the final query. Correct answer
C: They could only run the entire program on Sundays.
D: They could automatically restrict access to the source table in the final query so that it is only accessible on Sundays.
E: They could redesign the data model to separate the data used in the final query into a new table.
Correct Answer:
B. They could wrap the queries using PySpark and use Python’s control flow system to determine when to run the final query.
Explanation

The most effective and standard approach within the Databricks platform is to leverage its multi-language capabilities. By wrapping the SQL queries in a PySpark environment (e.g., a Databricks notebook), a data engineer can use Python's native date/time libraries and control flow statements (e.g., if-elif-else). This allows them to check the current day of the week and conditionally execute the final SQL query using the spark.sql() function only on Sundays. The entire notebook can then be scheduled as a daily Databricks Job, satisfying the requirement for the other queries to run every day while the final one runs selectively.

Why Incorrect

A. Submitting a feature request is not a technical solution; the required functionality already exists through standard programming constructs available in Databricks.
C. This approach violates the primary requirement that the initial part of the program must run every day, not just on Sundays.
D. Using table access control (ACLs) to manage execution logic is an improper use of security features and would likely cause job failures rather than conditional skipping.
E. Redesigning the data model does not solve the core problem, which is about conditional, time-based execution logic, not data structure. ---

References

1. Databricks Documentation

"Use multiple languages in a notebook": This document explains how to mix languages like Python and SQL within a single Databricks notebook. A Python cell can be used to implement the control logic before calling a SQL query.

Reference: Databricks Documentation > Develop and run code on Databricks > Notebooks > Use multiple languages in a notebook.

2. Databricks Documentation

"PySpark APIs

pyspark.sql.SparkSession.sql": The official API documentation shows that the spark.sql() method is the standard way to execute SQL queries from within a PySpark session. This is the mechanism used to run the conditional query from the Python control block.

Reference: Databricks Documentation > Reference > APIs > PySpark API Reference > pyspark.sql module > SparkSession class > sql method.

3. Databricks Documentation

"Introduction to Databricks Workflows": This documentation confirms that notebooks containing such logic can be scheduled to run on a recurring basis (e.g.

daily). The Python logic within the notebook handles the conditional execution of the specific task.

Reference: Databricks Documentation > Orchestrate data pipelines with Databricks Workflows > Introduction to Databricks Workflows.

Scroll to Top