apache / apache/datafusion

to_string and from_string have different behavior for TableReference

Aperta
#6,853 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Rust
Stelle
9.3k
Fork
2.4k
Merge medio
3g 11h
PR unite (30g)
360

Descrizione

### Describe the bug

`to_string` simply concat components with `.`:
https://github.com/apache/arrow-datafusion/blob/02a470f6061cce8ee8e57f7af8a6a0e0ddc1571b/datafusion/common/src/table_reference.rs#L107-L121

but `from_string` will transform them to lowercase:
https://github.com/apache/arrow-datafusion/blob/02a470f6061cce8ee8e57f7af8a6a0e0ddc1571b/datafusion/common/src/utils.rs#L248-L257

`TableReference` is the most common table identifier for tables. But I don't think converting cases or considering quotes is necessary when the object name becomes `TableReference`. At this stage (i.e., after the initial plan is constructed from AST), those object names should be fixed.

This implicit conversion makes it difficult when handling complex table identifiers. Thus I propose to make `TableReference` as simple as possible and gather all those `to_lower_cases` and "quotes" before generating the very first `TableReference`.

### To Reproduce

```rust
#[test]
fn to_lower_case() {
let table_ref = TableReference::Full {
catalog: Cow::Owned("catalog".to_string()),
schema: Cow::Owned("schema".to_string()),
table: Cow::Owned("TABLE".to_string()),
};
let concatted = table_ref.to_string();
println!("concatted: {}", concatted);
let parsed = TableReference::parse_str(&concatted);
println!("parsed: {:?}", parsed.to_vec());
}
```

The output is
```
concatted: catalog.schema.TABLE
parsed: ["catalog", "schema", "table"]
```

### Expected behavior

```
concatted: catalog.schema.TABLE
parsed: ["catalog", "schema", "TABLE"]
```

### Additional context

(Not sure if this is "bug"...)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da datafusion/common/src/table_reference.rs e dalla logica di parsing referenziata in datafusion/common/src/utils.rs, quindi esegui il test riproducibile to_lower_case usando TableReference::parse_str. Confronta il comportamento corrente di to_string e from_string e definisci test che coprano la conservazione delle maiuscole/minuscole e gli identificatori tra virgolette o complessi; il lavoro è completato quando il valore TABLE previsto sopravvive al round trip.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.