cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How can I fix strange magic command behaviour in Databricks notebooks?

jowziph
New Contributor III

Hi,

I have encountered a strange issue when using magic commands on my Azure Databricks workspace.

When I create a cell and type the magic command for a language which is not default in the notebook, the code is instead interpreted as the default notebook language.

Here you can see a notebook with python as the default language, with a sql magic command:

magic command manually typedmagic command manually typed 2And here, the same notebook. But with python code written in the cell.

 image 

However, if I create a cell at the end of the notebook (not in between existing cells). And then set the language to SQL using this button, the code will be correctly interpreted as SQL.

This issue first arose this week on Monday the 26th of September. It has broken a lot of my existing notebooks which use "%sql".

I have tried restarting my cluster, creating a new cluster, creating a new notebook, and changing my notebook default language. But none of these have fixed the issue.

Thanks,

Joe

2 REPLIES 2

Debayan
Databricks Employee
Databricks Employee

Hi, Is this happening when magic command is used in between two cells of the default language?

You can override the default language in a cell by clicking the language button and selecting a language from the dropdown menu. Alternately, you can use the language magic command %<language> at the beginning of a cell. The supported magic commands are: %python , %r , %scala , and %sql .

jowziph
New Contributor III

Hi,

Yeah this is happening when magic command is used in between two cells of the default language. But this is not the only case.

This is happening when magic command is manually typed out (e.g. %sql or %scala in a python notebook). OR when magic command is selected from the language button and the cell is not a brand new cell at the bottom of the notebook.

The issue is making it difficult for me to develop multi language notebooks.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group