cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Is there a command in sql cell to ignore formatting for some lines like `# fmt: off` in Python cells

jonathan-dufaul
Valued Contributor

In python cells I can add the comments `# fmt: off` before a block of code that I want black/autoformatter to ignore and `# fmt: on` afterwards. Is there anything similar I can put in sql cells to accomplish the same effect?

Some of the recommendations make the code far less legible.

Also is there any way to ignore single lines in the python cell?

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz
Community Manager
Community Manager

Hi @jonathan-dufaul, Sorry to have misread your question.

 

In Databricks, the # fmt: off and # fmt: on comments are used to control the autoformatter in Python cells. However, based on my search, there doesnโ€™t seem to be a similar command to ignore formatting in SQL ....

 

As for ignoring single lines in a Databricks Python cell, there isnโ€™t a specific command to ignore a single line. The # fmt: off and # fmt: on comments apply to the entire block of code between them. If you want to prevent formatting on a specific line, you might consider isolating it in its own # fmt: off and # fmt: on block.

View solution in original post

4 REPLIES 4

Kaniz
Community Manager
Community Manager

Hi @jonathan-dufaul, Sorry to have misread your question.

 

In Databricks, the # fmt: off and # fmt: on comments are used to control the autoformatter in Python cells. However, based on my search, there doesnโ€™t seem to be a similar command to ignore formatting in SQL ....

 

As for ignoring single lines in a Databricks Python cell, there isnโ€™t a specific command to ignore a single line. The # fmt: off and # fmt: on comments apply to the entire block of code between them. If you want to prevent formatting on a specific line, you might consider isolating it in its own # fmt: off and # fmt: on block.

The sql formatter I'm using is whatever databricks notebooks in the workspace themselves are using (with Ctrl-Shift-F). Is that link related to databricks?

I'll accept since it looks like the answer is a no for an ignore command in sql cells.

I found out that you can ignore single lines in python cells by putting `# fmt: skip` at the end. There has to be a space between the `#` and fmt or else you'll get a "AssertionError: INTERNAL ERROR: Black produced different code on the second pass of the formatter. Please report a bug on https://github.com/psf/black/issues." error

Kaniz
Community Manager
Community Manager

Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance! 
 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.