Databricks Data Engineer Associate Question 53
Select 2You are working on a Databricks notebook that requires running SQL queries to extract data and then processing that data using Python. Which of the following actions would correctly allow you to use multiple languages within the same notebook?
- A
Use language-specific magic commands like
%sqland%pythonat the beginning of cells to specify the language for that cell. - B
Write all code in a single cell and prefix each line with the language-specific magic command like
%pythonor%sql. - C
Use
%runto execute an external notebook written in another language. - D
Directly switch between languages in the same cell without using any special syntax.
- E
Create separate notebooks for each language and combine them using Databricks workflows.
Show answer and explanation
Correct answers: A, C
Explanation
Databricks notebooks support multiple languages by using language-specific magic commands such as %sql, %python, %scala, and %r at the beginning of cells to specify the language for that cell. Additionally, %run can be used to execute another notebook written in a different language, enabling multi-language workflows. It is important to use these features correctly to ensure seamless integration of multiple languages within a single notebook.
- A. Correct.
Correct: Language-specific magic commands like
%sqland%pythonare used to specify the language of a cell in a Databricks notebook. - B. Incorrect.
Incorrect: Language-specific magic commands are used at the beginning of a cell, not for every line within the cell.
- C. Correct.
Correct:
%runallows you to execute another notebook, which can be written in a different language, enabling multi-language workflows. - D. Incorrect.
Incorrect: Switching between languages in the same cell without using special syntax is not supported in Databricks notebooks.
- E. Incorrect.
Incorrect: While creating separate notebooks is possible, it is not the recommended approach for using multiple languages within the same notebook.