apache / apache/datafusion

Regression: SQL parser became less tolerant to columns that match SQL keywords

Aperta
#17,802 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Rust
Stelle
9.3k
Fork
2.4k
Merge medio
3g 6h
PR unite (30g)
363

Descrizione

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:

> 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci le query in datafusion-cli, soprattutto i casi in cui un literal precede una colonna usando offset e limit, e confronta il comportamento con DataFusion 49.0.2. Investiga la possibile modifica alla crate sqlparser tra le versioni 0.55.0 e 0.58.0; il lavoro è completato quando le colonne con nomi costituiti da parole chiave vengono analizzate correttamente senza richiedere virgolette, anche quando un literal le precede.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust, sql
Ambito
backend, databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.