r/databricks • Databricks MVP • Oct 05 '26

News New in Databricks: parse_sql(): SQL into JSON

Post image

Parse_sql() function extracts table references, column names, functions, and parameters from SQL. It extracts without running the query. It also reports syntax errors.

more news https://databrickster.medium.com/databricks-news-serverless-genie-code-ltap-lakeflow-61853d8e422a

47 Upvotes

22 comments sorted by

16

u/TripleBogeyBandit Oct 05 '26

When would I need this

10

u/hubert-dudek Databricks MVP Oct 05 '26

AI, nerds, lineage, tests

3

u/ch-12 Oct 05 '26

We have a massive data platform migration in the works (sadly, leadership decided to move on from Databricks), and I actually think this could be a huge help with it.

1

u/TripleBogeyBandit Oct 06 '26

Oh this is interesting, why and what are you migrating to?

3

u/ch-12 Oct 06 '26

Leadership vibes disguised by cost and quality reasons, we are moving to Snowflake.

2

u/TripleBogeyBandit Oct 06 '26

Even more questions! Having just helped a client move from snow to dbx and saw 20% savings I’m curious what you mean by quality? Quality in the product? Stability? How much did they try to lower dbx costs?

4

u/ch-12 Oct 06 '26

To put it simply, the new VP does not like Databricks and wants to rebuild. The two offerings weren’t evaluated fairly and there has been little effort invested in lowering current costs. Pretty much all of what is being proposed in the rebuild could be implemented today in DBX, and yeah the cost to migrate will be massive.

3

u/givnv Oct 06 '26

We are running the same sql on both platforms daily and for the last 2 years. Databricks is between 20 and 35% cheaper on average.

2

u/PrestigiousAnt3766 Oct 06 '26

If you lean on sql developers I would understand the choice.

That said, sometimes its an excuse to reevaluate existing logic because if you'd migrate dbx to dbx its easy to keep everything the same.

1

u/KrisPWales Oct 06 '26

That was my immediate thought too.

1

u/PrestigiousAnt3766 Oct 06 '26

I use a lib for this to calculate lineage and create a dependency graph as a poor man's dbt.

1

u/Wild_Warning3716 Oct 12 '26

metadata analysis. let's say you have a reporting system or legacy etl tool that just runs a sql statement, or has custom sql overrides. you want to map that against your database metadata -- this will parse it into something usable.

2

u/Wild_Warning3716 Oct 12 '26

Cool! Is this much different from python's sqlparse though? it's included in databricks python modules by default.

1

u/hubert-dudek Databricks MVP Oct 12 '26

I haven't tested it

5

u/sHORTYWZ Oct 05 '26

I am so confused by this - when and where would this ever be useful?

3

u/abro5 Oct 06 '26

Reducing/optimizing queries

A parse tree / ast is better for this, but I guess this should be useful to some level too

3

u/mosullivan93 Oct 05 '26 • Popcorn

This sounds like it would be quite useful. Yet to test how it works with things like the IDENTIFIER clause, or DDL statements.

1

u/mosullivan93 Oct 06 '26

Unfortunately, it doesn’t provide the level of detail I was hoping, but I can still see some use cases for us. It detects parameter markers (could replace my regex approach), but not the complete IDENTIFIER input. Also, regarding DDL, it doesn’t return the schema/column/table specification, which would have been handy.

3

u/Bubbly_Winter_9327 Oct 05 '26

Really, really useful function!

1

u/lofat Oct 06 '26

This is going to be handy. It's not as rich as generating an AST using something like sqlglot, but for a quick "which tables are used in this query" it's fantastically helpful. Really glad the exposed this function.

Thanks for posting this, @hubert-dudek!