sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Pretty SQL before sending to execution engine

Open MikeWallis42 opened this issue 1 year ago • 9 comments

A small request I hope. Would it be possible to use SQLGlot's pretty functionality before executing SQL statements? It would be much easier to find syntax issues if it wasn't one long line.

MikeWallis42 avatar Jul 24 '24 13:07 MikeWallis42

had a similar comment for audits - it's great to be able to cut & paste sql for a failing audit, but would be even better if I could see pretty sql without an external tool. either by default or with sqlmesh audit --pretty or something.

patricksurry avatar Jul 26 '24 13:07 patricksurry

@izeigerman, please correct me if I'm wrong but would this be as simple to implement as changing this line from False to True?

https://github.com/TobikoData/sqlmesh/blob/v0.117.0/sqlmesh/core/engine_adapter/base.py#L2037

If so then I'd be happy to contribute this.

MikeWallis42 avatar Aug 14 '24 07:08 MikeWallis42

@MikeWallis42 is the purpose of this to make the queries in logs prettier? Or some other place?

izeigerman avatar Aug 14 '24 20:08 izeigerman

I'm concerned that this will significantly increase the size of the payload and the IO overhead as a result. I'm open to making this configurable with this behavior being disabled by default.

izeigerman avatar Aug 14 '24 20:08 izeigerman

If I were to be really specific then this would be to better enable debugging and would typically be used during development more than in a production setting. As SQLGlot cannot and should not be validating the syntax of the SQL (apart from really basic things), it's often the case that bad SQL is written and run whilst developing. Finding the location of the bad SQL (from the execution engine) is typically easier when we can scan down and then across. At the moment all the issues are on line 1 and, sometimes, several thousand characters in.

It might be that this would be configured against a specific gateway in the context of SQLMesh, at least in the way that I'm using it currently.

MikeWallis42 avatar Aug 15 '24 07:08 MikeWallis42

@MikeWallis42 are you planning to make a PR?

tobymao avatar Aug 22 '24 18:08 tobymao

I would love to have a go! I've made a start today

MikeWallis42 avatar Aug 23 '24 14:08 MikeWallis42

Great let us know if you need any help, you can ping us on slack.

tobymao avatar Aug 23 '24 14:08 tobymao

@MikeWallis42 looks like you're not the only one that cares about this: https://github.com/TobikoData/sqlmesh/issues/3086#issuecomment-2329678997

But looks like you don't want to see the pretty SQL rendered in the terminal, only in the query history for the engine executing the SQL. Is that correct?

sungchun12 avatar Sep 05 '24 17:09 sungchun12