apache / apache/datafusion-sqlparser-rs

formatting the AST while preserving the source location information from the original query

Open
#1,634 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
3.5k
Forks
772
Avg merge
4d 9h
Merged PRs (30d)
17

Description

In the current sqlparser, parsing

```sql
select
a,
b
from
t
```

and then fromatting it back to a string results in

```sql
select a,b from t
```

Since sqlparser v0.53, we have the source location information inside the AST, which theoretically makes it possible to reconstruct the original query formatting (or at least getting very close to it).

I know this is a huge undertaking, but it would be really useful. For instance, in [sqlpage](https://github.com/lovasoa/SQLpage), I would love being able to respect the initial user formatting of queries, in order for database errors that contain source position information to be meaningful and not confusing.

I'm opening this issue to start discussing this with the community (and especially with you @iffyio and @alamb :wink: ).

Am I the only one interested in this ? What would be the best approach to implementing this ?

Contributor guide

No contributing guide indexed for this repository

Research direction

No specific files or tests are named. Start by reviewing the AST source-location support introduced in sqlparser v0.53 and the existing formatting path; done means reconstructing the original query formatting closely enough that source positions remain meaningful.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.