Looking for CLI-based SQL formatter for Databricks: Alternative to gethue/sql-formatter for .

Lenoq
New Contributor III

I'm looking for a SQL formatter (CLI) for two different contexts within Databricks.

1. SQL queries in .sql files - What tool does Databricks use by default to format SQL?

2. %sql magic cells in notebooks (.ipynb files) - What tool does Databricks use by default to format SQL in %sql cells?

Databricks currently appears to use gethue/sql-formatter for both contexts, but I have some concerns with this tool:
- The project hasn't been updated in four years.
- It doesn't properly support %sql cells in .ipynb notebooks. I'm sure there are custom customizations, especially for #2.
- I don't want to rely on an unmaintained tool.

What I'm looking for:

I'm looking for an alternative tool that meets the following criteria:
- Officially provided by Databricks or Databricks Labs
- Supports both .sql files and %sql cells in .ipynb
- Available as a CLI command or installable package (e.g., for CI/CD pipelines)

Does Databricks or Databricks Labs provide such a tool? If not, are there any officially recommended commands or packages that meet these requirements?

I'd appreciate any guidance.

ilir_nuredini
Honored Contributor

Hi @Lenoq ,

As far as I know, currently there is no tool that meets your given criteria by databricks/labs. The closest that I can see is the tool you gave as an example, but as you said its not that good. what I would do maybe is an intermedial option with sqlfluff that would format the sql queries, however, it would need some extra handling to strip or ignore %sql magic lines when used on notebook content.

Best, Ilir

View solution in original post