Databricks Data Engineer Associate Question 52
Select 2You are working in a Databricks notebook and need to process data using both Python and SQL within the same notebook. Which of the following statements about using multiple languages in a Databricks notebook are correct?
- A
You can switch languages within a cell by using a magic command like
%pythonor%sql. - B
All cells in a notebook must use the same programming language.
- C
Variables defined in one language can be accessed in another language using the
dbutils.notebook.data()function. - D
To switch languages within a cell, you must restart the cluster.
- E
You can use the
display()function to view the output of SQL queries executed in a%sqlcell.
Show answer and explanation
Correct answers: A, E
Explanation
Databricks notebooks support the use of multiple languages within the same notebook by leveraging magic commands like %python, %sql, %scala, and %r to specify the language for each cell. This enables flexible workflows where you can process data in one language and analyze or visualize it in another. The display() function is a useful tool for visualizing the results of SQL queries.
- A. Correct.
Correct. Magic commands like
%python,%sql,%scala, or%rallow you to switch the language used in a cell within a Databricks notebook. - B. Incorrect.
Incorrect. Cells in a Databricks notebook can use different languages, and you can switch between them using magic commands.
- C. Incorrect.
Incorrect. While variables can be shared between languages, the
dbutils.notebook.data()function is not used for this purpose. - D. Incorrect.
Incorrect. Switching languages within a cell does not require restarting the cluster; it can be done seamlessly using magic commands.
- E. Correct.
Correct. The
display()function is commonly used to visualize the output of SQL queries executed in%sqlcells.