eschutho opened a new pull request, #45926: URL: https://github.com/apache/superset/pull/45926
### SUMMARY Typing in a filter-value dropdown (server-side search) on a dataset backed by ClickHouse via `clickhouse-connect` returned an HTTP 500: `CompileError: ClickHouse does not support the ESCAPE clause on LIKE`. **Root cause:** `values_for_column` builds its search predicate with `build_like_predicate`, which uses `contains(..., autoescape=True)`. SQLAlchemy renders that as `LIKE ... ESCAPE '/'`, and `clickhouse-connect`'s compiler (`visit_like_op_binary` -> `_raise_on_escape`) rejects any LIKE carrying an escape modifier. (BigQuery was already handled because its compiler swaps in backslash escaping.) No ClickHouse engine-spec override intercepts this path. **Fix:** `build_like_predicate` now returns a small `FunctionElement` whose rendering is chosen at compile time. The default compile is exactly the previous `contains(..., autoescape=True)`. For the `clickhousedb` dialect (the `clickhouse-connect` dialect name), `\`, `%` and `_` in the term are backslash-escaped by hand and a plain `LIKE` is emitted with no `ESCAPE` clause; backslash is ClickHouse's native LIKE escape character. Keying on the compiled dialect keeps the function signature and its caller unchanged. ### TESTING INSTRUCTIONS - Unit tests: `pytest tests/unit_tests/models/helpers_test.py -k "like or values_for_column"` (48 passed). New test `test_build_like_predicate_clickhouse_uses_backslash_escaping` compiles with the real `clickhouse-connect` dialect (skipped if not installed) and asserts no `ESCAPE` and `\%`, `\_`, `\\` escaping; before the change the same compile raised the `CompileError`. The existing postgres (`ESCAPE` present) and BigQuery (no `ESCAPE`) assertions still pass. - Manual: on a ClickHouse (`clickhouse-connect`) dataset, open a native filter select and type in the search box; it should return matches instead of a 500, and `%`/`_` typed by the user match literally. **Tradeoffs** - No failure-mode semantics change: other dialects compile identically to before, and ClickHouse previously always failed on this path, so it now succeeds rather than changing from one working behavior to another. - Escaping for ClickHouse is now hand-rolled in Superset rather than delegated to SQLAlchemy. - Only the `clickhousedb` dialect is handled. The legacy `clickhouse+native` (`clickhouse-sqlalchemy`) dialect was not verifiable here, so it is untouched. **Follow-ups:** confirm/handle the legacy `clickhouse-sqlalchemy` dialect if it also rejects `ESCAPE`. **Overlap:** #45892 also edits `build_like_predicate` (adds a CAST for non-string columns). This diff is kept localized (an additive helper plus the final `return`) so the merge should be a trivial conflict at most. ### ADDITIONAL INFORMATION - [ ] Has associated issue: - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Introduces new feature or API - [ ] Removes existing feature or API 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
