apache / apache/datafusion

Support accessing a map with non-literal, non-constant key

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

Descrizione

Accessing a map with a non-string key doesn't work (at least via DataFusion SQL) and is covered by https://github.com/apache/datafusion/issues/11785

Accessing a map with a literal string key works:

https://github.com/apache/datafusion/blob/5e1e693b6e30888d710aefc57be58ea25f62d34d/datafusion/sqllogictest/test_files/map.slt#L69-L72

Add support for accessing a map with non-literal key.
For example this should work (and also other cases where key cannot be constant-folded to a literal):

```
query ok
SELECT SUM(ints['by' || 'tes']) FROM data;
```

but it does not:
> `DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'array_element' function: coercion from [Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false), Utf8] to the signature ArraySignature(ArrayAndIndexes(1)) failed No function matches the given name and argument types 'array_element(Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false), Utf8)'. You might need to add explicit type casts.
Candidate functions:
array_element(array, index`

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Il caso map esistente si trova in datafusion/sqllogictest/test_files/map.slt (L69-L72); inizia da lì e ispeziona il percorso di pianificazione SQL che produce l'errore di coercizione di array_element. Aggiungi la copertura per SELECT SUM(ints['by' || 'tes']) FROM data e verifica che le chiavi non costanti funzionino senza compromettere l'accesso con chiavi letterali.

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

Valutazione

Stack tecnologico
rust, sql
Ambito
data-engineering, database
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.