Databricks Data Engineer Associate Question 59
Select 2You are working on a Databricks notebook and need to execute another notebook called 'Data_Cleaning' from within your current notebook. Which of the following methods can you use to achieve this?
- A
Use the %run magic command with the relative path to the 'Data_Cleaning' notebook
- B
Use the dbutils.notebook.run() function with the absolute path to the 'Data_Cleaning' notebook
- C
Use the import statement to import the 'Data_Cleaning' notebook as a Python module
- D
Use the %load magic command to load and execute the 'Data_Cleaning' notebook
- E
Use the os.system() function to call the 'Data_Cleaning' notebook
Show answer and explanation
Correct answers: A, B
Explanation
In Databricks, you can run one notebook from another using either the %run magic command or the dbutils.notebook.run() function. The %run command is used for executing notebooks in the same workspace with a relative path, while dbutils.notebook.run() allows for programmatically invoking a notebook using its absolute path, with the ability to pass parameters and handle return values.
- A. Correct.
Correct: The %run magic command allows you to execute another notebook by specifying its relative path. This is a common and straightforward way to run one notebook from another within Databricks.
- B. Correct.
Correct: The dbutils.notebook.run() function can be used to call another notebook programmatically, and it allows passing parameters and handling return values. This method requires the absolute path of the notebook.
- C. Incorrect.
Incorrect: Databricks notebooks are not Python modules and cannot be imported using the import statement. This will result in an error.
- D. Incorrect.
Incorrect: The %load magic command is not supported in Databricks notebooks. This command is specific to some other notebook environments like Jupyter.
- E. Incorrect.
Incorrect: While the os.system() function can execute shell commands, it cannot directly call Databricks notebooks. This is not a valid method for running a notebook within another notebook.