ibis-project / ibis

the portable Python dataframe library
https://ibis-project.org
Apache License 2.0
4.36k stars 540 forks source link

refactor(sql): a few SQL compiler rewrite cleanups #9134

Closed jcrist closed 3 weeks ago

jcrist commented 3 weeks ago

A few assorted refactors to simplify and centralize the rewrites needed for the SQL compilers:

The main motivation of this PR was adding LOWERED_OPS, which I need to implement distinct as a composite operation (everything else was a cleanup that I noticed while fixing this). Splitting the "lowering"/"desugaring" rewrite rules from the other rewrite rules (like converting 0-to-1 based indexing) also is necessary so that those SQLizing passes are still applied to the lowered operation graph. Mixing everything in one pass means that if a rewrite rule is used to lower an operation into one composed of e.g. a window function, the rewrite rules needed for backend-specific window function cleanups are never applied (since we don't retraverse).