Databricks Data Engineer Associate Question 57
Select 2You are working on a Databricks notebook and need to modularize your workflow by running another notebook from within your current notebook. Which of the following methods can you use to achieve this?
- A
Use the
%runcommand followed by the path to the target notebook - B
Use the
Notebook.run()method in a Python cell - C
Use the
dbutils.notebook.run()method with the notebook path and required arguments - D
Use a SQL
RUN NOTEBOOKstatement with the notebook path - E
Use the
importstatement to directly import the target notebook as a Python module
Show answer and explanation
Correct answers: A, C
Explanation
In Databricks, there are two primary methods to run one notebook from another: the %run command and the dbutils.notebook.run() method. The %run command includes the code from the other notebook directly into the current notebook, while dbutils.notebook.run() executes the notebook as a separate job and allows passing arguments and receiving a return value. Other options like importing notebooks as Python modules, using Notebook.run, or running notebooks via SQL statements are not supported.
- A. Correct.
The
%runcommand is a valid way to run another notebook in Databricks. It allows you to include the code from the specified notebook into your current notebook. - B. Incorrect.
The
Notebook.run()method is not a valid way to run another notebook in Databricks. This is not a recognized method in the Databricks environment. - C. Correct.
The
dbutils.notebook.run()method is a valid way to call another notebook and pass parameters to it. It runs the notebook as a separate job and returns its output. - D. Incorrect.
There is no SQL statement like
RUN NOTEBOOKto execute another notebook in Databricks. This is not a supported feature. - E. Incorrect.
The
importstatement cannot directly import a Databricks notebook as a Python module. Notebooks are not structured as Python modules.