A few assorted refactors to simplify and centralize the rewrites needed for the SQL compilers:
Rename UNSUPPORTED_OPERATIONS to UNSUPPORTED_OPS to better match the naming convention of other _OPS class variables.
Simplify __init_subclass__ handling of inheritance for the various _OPS configuration variables.
Add LOWERED_OPS class var to handle mappings from an operation class to a rewrite rule for "lowering" that operation into one composed of simpler operations. If a backend implements one of these high-level operations that has a lowering rule defined in the base class, they can instead map the op to None which will drop the existing rewrite rule. This lets us define high-level rewrites on the SQLGlotCompiler (e.g. for handling Sample or StringSlice), then drop the rewrites for backends where the op is natively supported. This lets us drop a bunch of copy-paste code from the various backends.
Use a rewrite rule to handle dropna/fillna. Right now these are handled via visit_* methods, which prevents fusing these with other Select operations. We had existing (unused) rewrite rules that used to handle this pre-9.0, here I just migrate back to using them.
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).
A few assorted refactors to simplify and centralize the rewrites needed for the SQL compilers:
UNSUPPORTED_OPERATIONS
toUNSUPPORTED_OPS
to better match the naming convention of other_OPS
class variables.__init_subclass__
handling of inheritance for the various_OPS
configuration variables.LOWERED_OPS
class var to handle mappings from an operation class to a rewrite rule for "lowering" that operation into one composed of simpler operations. If a backend implements one of these high-level operations that has a lowering rule defined in the base class, they can instead map the op toNone
which will drop the existing rewrite rule. This lets us define high-level rewrites on theSQLGlotCompiler
(e.g. for handlingSample
orStringSlice
), then drop the rewrites for backends where the op is natively supported. This lets us drop a bunch of copy-paste code from the various backends.dropna
/fillna
. Right now these are handled viavisit_*
methods, which prevents fusing these with otherSelect
operations. We had existing (unused) rewrite rules that used to handle this pre-9.0, here I just migrate back to using them.The main motivation of this PR was adding
LOWERED_OPS
, which I need to implementdistinct
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).