Databricks Data Engineer Associate Question 60
Select 2You are working on a Databricks notebook and need to run another notebook named 'data_processing' located in the folder '/Shared/Projects'. Which of the following methods can be used to execute the 'data_processing' notebook from within your current notebook?
- A
Use the
%run /Shared/Projects/data_processingcommand in a cell - B
Call
dbutils.notebook.run('/Shared/Projects/data_processing', 60) - C
Import the 'data_processing' notebook as a Python module using
import /Shared/Projects/data_processing - D
Use
spark.read('/Shared/Projects/data_processing')to execute the notebook - E
Use the
%include /Shared/Projects/data_processingmagic command
Show answer and explanation
Correct answers: A, B
Explanation
In Databricks, you can execute one notebook from another in two ways: using the %run magic command or the dbutils.notebook.run method. %run executes the notebook in the same context, sharing variables, while dbutils.notebook.run runs the notebook as a separate job with its own execution context. Other approaches, such as importing notebooks as Python modules, are not supported.
- A. Correct.
Correct. The
%runmagic command is used to execute another notebook within the current notebook, allowing you to share variables and functions between notebooks. - B. Correct.
Correct. The
dbutils.notebook.runmethod is also used to execute another notebook, but it runs the notebook as a separate job and supports passing arguments as well as setting a timeout. - C. Incorrect.
Incorrect. Databricks does not allow importing notebooks using standard Python import statements. Notebooks need to be executed through
%runordbutils.notebook.run. - D. Incorrect.
Incorrect.
spark.readis used to read data from files or tables, not to execute notebooks. - E. Incorrect.
Incorrect.
%includeis not a valid magic command in Databricks. Notebooks can only be executed using%runordbutils.notebook.run.