apache / apache/datafusion

Avoid check function type by matching names in the optimizer

Offen
#18,643 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Rust
Sterne
9.3k
Forks
2.4k
Ø Merge
3 T. 11 Std.
Gemergte PRs (30 T.)
360

Beschreibung

### 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_

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die Prüfungen von Funktionsnamen in datafusion/optimizer/src/single_distinct_to_groupby.rs, datafusion/optimizer/src/analyzer/resolve_grouping_function.rs und datafusion/optimizer/src/decorrelate.rs zu überprüfen. Untersuche anschließend die UDF- und Function-Registry-APIs, um zu bestimmen, wie sich integrierte Funktionen von überschriebenen Implementierungen unterscheiden lassen, ohne dass der Optimizer von deren Implementierungs-Crate abhängt; abgeschlossen ist die Aufgabe, wenn die Prüfungen im Optimizer sicher sind und die betroffenen Regeln abgedeckt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
data-engineering
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.