Databricks Data Engineer Associate Question 56
Single answerYou are working on a Databricks notebook for a data pipeline and need to reuse logic from another notebook called 'data_processing'. How can you run the 'data_processing' notebook from within your current notebook?
- A
Use the %run magic command followed by the relative path to the 'data_processing' notebook.
- B
Use the %load magic command followed by the relative path to the 'data_processing' notebook.
- C
Use the includeNotebook() function with the absolute path to the 'data_processing' notebook.
- D
Use the dbutils.notebook.run() function to call the 'data_processing' notebook.
Show answer and explanation
Correct answer: A
Explanation
To run one notebook from within another in Databricks, you use the %run magic command followed by the relative or absolute path to the target notebook. This allows you to execute all the code from the specified notebook in the current notebook's context, making it highly useful for reusing logic across multiple notebooks.
- A. Correct.
This is the correct way to execute another notebook within the same workspace in Databricks. The %run magic command allows you to import and run all the code from the specified notebook.
- B. Incorrect.
The %load magic command is not valid in Databricks notebooks. It is used in IPython to load code for review but does not execute other notebooks.
- C. Incorrect.
The includeNotebook() function is not a valid function in Databricks. This option is incorrect.
- D. Incorrect.
While dbutils.notebook.run() is used to call another notebook, it is used to invoke the notebook as a separate job with parameters, not directly run the code inline.