fix(db2): explicitly register DB2Interval in TRANSFORMS for sqlglot 30

sqlglot 30 changed how the generator dispatch is built. In 28 the
auto-discovery walked all expression subclasses; in 30 it only
considers classes registered in sqlglot.expressions.EXPR_CLASSES,
which is populated once at module load via subclasses(__name__, Expr)
— i.e. ONLY built-in expression types. Custom user-defined
Expression subclasses defined outside that module — like our
DB2Interval — no longer get auto-wired to their <name>_sql handler.

Adding DB2Interval to TRANSFORMS as a lambda → db2interval_sql
restores the dispatch. All 24 dialects/db2_tests.py tests pass.
This commit is contained in:
Claude
2026-05-20 17:45:55 -07:00
parent 9f9c3737a2
commit c5fc31a67f

View File

@@ -136,6 +136,12 @@ class DB2(Postgres):
TRANSFORMS = {
**Postgres.Generator.TRANSFORMS,
# sqlglot 30 only auto-discovers <Name>_sql handlers for expression
# classes that live in sqlglot.expressions.EXPR_CLASSES (the
# registry is built once at module load via ``subclasses(__name__, Expr)``).
# Custom Expression subclasses defined outside that module — like
# DB2Interval below — must be wired up explicitly in TRANSFORMS.
DB2Interval: lambda self, e: self.db2interval_sql(e),
}
def db2interval_sql(self, expression: DB2Interval) -> str: