All array functions should represent `NULL` as an element
- 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?
Follow on to https://github.com/apache/arrow-datafusion/pull/6662
We have important problem related to using array functions with `NULL` statements. As @alamb said in PR (see below for full details) DataFusion casting system should be adapted for it, otherwise it will always throw errors.
The current implementation:
```
❯ select array_append([1, 2, 3, 4, 5], NULL);
Optimizer rule 'simplify_expressions' failed
caused by
This feature is not implemented: Array_append is not implemented for types 'Int64' and 'Null'.
```
Should be:
```
❯ select array_append([1, 2, 3, 4, 5], NULL);
----
[1, 2, 3, 4, 5, NULL]
```
### Describe the solution you'd like
@alamb statement about the issue:
> I am not sure about this approach of taking either a `ListArray` or a `NullArray`
>
> In the other functions, the way NULL is treated is that the input types are always the same (in this case ListArray) and the values would be `null` (aka `array.is_valid(i)` would return false for rows that are null.
>
> Complicating matters is if you type a literal `null` in sql like:
>
> ```sql
> select array_concat([1,2], null)
> ```
>
> That comes to DataFusion as a `null` literal (with DataType::Null). The coercion / casting logic normally will coerce this to the appropriate type.
>
> For example, here is how I think arithmetic works with null:
>
> ```sql
> select 1 + NULL
> ```
>
> Arrives like
>
> ```sql
> ScalarValue::Int32(Some(1)) + ScalarValue::Null
> ```
>
> And then the coercion logic will add a cast to Int32:
>
> ```sql
> ScalarValue::Int32(Some(1)) + CAST(ScalarValue::Null, DataType::Int32)
> ```
>
> And then the constant folder will collapse this into:
>
> ```sql
> ScalarValue::Int32(Some(1)) + ScalarValue::Int32(None)
> ```
>
> So by the time the arithmetic kernel sees it, it only has to deal with arguments of `Int32`
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo gli esempi SQL per array_append e array_concat con NULL, quindi segui la gestione dei tipi delle funzioni array e la logica di coercizione/casting descritta nell'issue. Il lavoro è completato quando le funzioni array accettano un literal NULL come elemento e restituiscono l'array previsto invece di un errore unsupported-type, con una copertura per le funzioni interessate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, sql
- Ambito
- data-engineering, databases
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100