Avoid check function type by matching names in the optimizer
- 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?
When implementing optimizer rules, it's common to check if a expression is certain function. Now it's commonly done through function name match check. A potential risk is: datafusion dependents might override the function implementation in the function registry, in such cases those optimizer rules should not be enabled, it's better to figure out a way to accurately check the function type.
I believe now they're done through name match because all function implementations live in a different crate than optimizer, and we don't want to add a crate dependency between them, so we can't do the trait object downcasting for type check.
One way I can think of is add a `source()` API in UDFs, so we can differentiate if this is builtin or added by the 3rd party, and in the optimizer we can check it safer like `fun.source() == BuiltIn && fun.name() == "min"`
Current optimizer examples for checking function type by name matching:
https://github.com/apache/datafusion/blob/0d52a1eebe403790a480ba404c2fe65b1aa1e897/datafusion/optimizer/src/single_distinct_to_groupby.rs#L90-L92
https://github.com/apache/datafusion/blob/0d52a1eebe403790a480ba404c2fe65b1aa1e897/datafusion/optimizer/src/analyzer/resolve_grouping_function.rs#L151-L153
https://github.com/apache/datafusion/blob/0d52a1eebe403790a480ba404c2fe65b1aa1e897/datafusion/optimizer/src/decorrelate.rs#L496
### Describe the solution you'd like
_No response_
### 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 esaminando i controlli sui nomi delle funzioni in datafusion/optimizer/src/single_distinct_to_groupby.rs, datafusion/optimizer/src/analyzer/resolve_grouping_function.rs e datafusion/optimizer/src/decorrelate.rs. Esamina quindi le API UDF e del registro delle funzioni per determinare come distinguere le funzioni integrate dalle implementazioni sovrascritte senza una dipendenza dell’ottimizzatore dal crate che ne contiene l’implementazione; il lavoro è completo quando i controlli dell’ottimizzatore sono sicuri e le regole interessate sono coperte.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- data-engineering
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100