Regression: SQL parser became less tolerant to columns that match SQL keywords
- Vorherrschende Sprache
- Rust
- Sterne
- 9.3k
- Forks
- 2.4k
- Ø Merge
- 3 T. 11 Std.
- Gemergte PRs (30 T.)
- 360
Beschreibung
### Describe the bug
Latest release (between `49.0.2` and `50.0.0`) seems to introduce a regression in SQL parser that causes it to be less tolerant of column names that collide with SQL keywords like `limit` and `offset`.
### To Reproduce
Using `datafusion-cli`:
```sql
> create or replace table x as (
select 1 as offset
);
> select * from x;
+--------+
| offset |
+--------+
| 1 |
+--------+
-- NOTE: Disambiguates correctly
> select offset from x;
+--------+
| offset |
+--------+
| 1 |
+--------+
-- NOTE: Adding a literal in the front breaks disambiguation
> select 'a' as a, offset from x;
🤔 Invalid statement: SQL error: ParserError("Expected: end of statement, found: x at Line: 1, Column: 30")
-- NOTE: Adding a literal in the back - does not!
> select offset, 'a' as a from x;
+--------+---+
| offset | a |
+--------+---+
| 1 | a |
+--------+---+
1 row(s) fetched.
-- NOTE: Quoting helps, but is unfortunate
> select 'a' as a, "offset" from x;
+---+--------+
| a | offset |
+---+--------+
| a | 1 |
+---+--------+
1 row(s) fetched.
```
In Datafusion `49.0.2` disambiguation works fine in all cases, so it's a regression.
Same behaviour reproduces for other keywords like `limit`.
### Expected behavior
SQL and its many dialects are rich with keywords, so context-aware parsing really helps to keep queries free of excessive quoting.
It so happens that `offset` column is present in *hundreds* of our datasets, so if this behavior change is highly impactful and I hope can be reversed.
### Additional context
The cause might be in `sqlparser` crate (between versions `0.55.0` and `0.58.0`). Will attempt to isolate the issue there and create a linked ticket.
Beitragsleitfaden
Rechercherichtung
Reproduziere die Abfragen in datafusion-cli, insbesondere die Fälle mit einem Literal vor einer Spalte unter Verwendung von offset und limit, und vergleiche das Verhalten mit DataFusion 49.0.2. Untersuche die mögliche Änderung an der sqlparser-Crate zwischen den Versionen 0.55.0 und 0.58.0; abgeschlossen ist die Aufgabe, wenn Spalten mit als Schlüsselwörter benannten Namen korrekt geparst werden, ohne Anführungszeichen zu erfordern, auch wenn ihnen ein Literal vorausgeht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rust, sql
- Bereich
- backend, databases
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100