Unparse Map plan to SQL string
Nessuno ha ancora preso questa issue.
- Lingua principale
- Rust
- Stelle
- 9.3k
- Fork
- 2.4k
- Merge medio
- 3g 11h
- PR unite (30g)
- 360
Descrizione
### Is your feature request related to a problem or challenge?
It's similar to https://github.com/apache/datafusion/issues/13477. We use the scalar function to handle the Map type but we should unparse it back to the right SQL.
## Map Literal
The SQL for creating a MAP:
``` sql
select MAP {'a': 1, 'b': 2}
```
The plan:
```
Plan: Projection: map(make_array(Utf8("a"), Utf8("b")), make_array(Int64(1), Int64(2)))
EmptyRelation
```
Unparse the plan:
```sql
SELECT map(make_array('a', 'b'), make_array(1, 2))
```
## Access a MAP
The SQL for accessing a MAP:
```sql
select map_col['a'] from (select MAP {'a': 1, 'b': 2} as map_col)
```
The plan:
```
Projection: get_field(map_col, Utf8("a"))
Projection: map(make_array(Utf8("a"), Utf8("b")), make_array(Int64(1), Int64(2))) AS map_col
EmptyRelation
```
Unparse the plan
```sql
SELECT get_field(map_col, 'a') FROM (SELECT map(make_array('a', 'b'), make_array(1, 2)) AS map_col)
```
### Describe the solution you'd like
The SQL should be able to roundtrip for SQL-Plan-SQL.
- The `map` with `make_array` function should be unparsed to `ast::Expr::Map`
- The `get_fields` for MAP should be unparsed to `ast::Expr::MapAccess`
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia tracciando il plan unparser per le funzioni scalari, in particolare map/make_array e get_field o get_fields, quindi esamina le varianti dell'AST SQL ast::Expr::Map e ast::Expr::MapAccess. Il lavoro è completato quando i literal MAP e gli accessi MAP vengono unparsati in queste forme dell'AST e il SQL risultante esegue un roundtrip attraverso SQL-Plan-SQL come mostrato negli esempi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, sql
- Ambito
- databases
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100