sitelight commented on code in PR #39340:
URL: https://github.com/apache/superset/pull/39340#discussion_r3433149951
##########
superset/sql/parse.py:
##########
@@ -137,6 +139,32 @@ class CTASMethod(enum.Enum):
VIEW = enum.auto()
+def _normalized_generator(
+ dialect_name: DialectType,
+ *,
+ pretty: bool,
+ comments: bool,
+) -> Generator:
+ """
+ Generator that preserves multi-argument DISTINCT expressions.
+
+ Build a sqlglot generator that preserves user-written multi-argument
+ DISTINCT expressions verbatim. Postgres, Presto, Trino, and DuckDB
+ set ``MULTI_ARG_DISTINCT = False`` to emulate the unsupported
+ ``COUNT(DISTINCT a, b)`` idiom via a ``CASE WHEN`` row-expression, which
+ silently corrupts user-defined aggregates that natively accept multiple
+ arguments. Superset's sanitize / format paths normalize user SQL — they
+ do not transpile — so the emulation is undesirable here.
+ """
+ base_cls = Dialect.get_or_raise(dialect_name).generator_class
Review Comment:
This is a false positive. `Dialect.get_or_raise(None)` returns the base
`Dialect` (verified on sqlglot 30.11.0) — it does *not* raise.
`Dialect.get_or_raise` only raises on unknown *named* strings, but
`SQLGLOT_DIALECTS.get(engine)` returns `None` for missing entries, never an
arbitrary string. The pattern
`Dialect.get_or_raise(SQLGLOT_DIALECTS.get(engine))` is also exactly what
`sanitize_clause` uses on `master` prior to this PR, so engines like
`databend`/`denodo`/`kylin` already fall back to the base generator — this PR
preserves that behavior.
```python
>>> from sqlglot.dialects.dialect import Dialect
>>> Dialect.get_or_raise(None)
<sqlglot.dialects.dialect.Dialect object at 0x...>
>>> Dialect.get_or_raise(None).generator_class.__name__
'Generator'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]