Skip to content

fix(clickhouse): remove _mutate_label workaround and bump clickhouse-connect to >=0.13.0 - #38280

Merged
villebro merged 3 commits into
apache:masterfrom
joe-clickhouse:joe/remove-ch-mutation-logic
Feb 27, 2026
Merged

fix(clickhouse): remove _mutate_label workaround and bump clickhouse-connect to >=0.13.0#38280
villebro merged 3 commits into
apache:masterfrom
joe-clickhouse:joe/remove-ch-mutation-logic

Conversation

@joe-clickhouse

Copy link
Copy Markdown
Contributor

SUMMARY

Removes the _mutate_label override from ClickHouseConnectEngineSpec that was appending hash suffixes to column aliases as a workaround for column name collision issues in older versions of clickhouse-connect. This is no longer needed as of clickhouse-connect>=0.13.0.

Also bumps the minimum clickhouse-connect version to >=0.13.0 across all locations including pyproject.toml, engine spec metadata, and generated docs for consistency.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

N/A. This change removes a workaround that is no longer needed with modern versions of clickhouse-connect. The base class _mutate_label already returns the label unchanged, so removing the override is a no-op in terms of behavior.

ADDITIONAL INFORMATION

@bito-code-review

bito-code-review Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8f7c6b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: e3a18b5..e3a18b5
    • pyproject.toml
    • superset/db_engine_specs/clickhouse.py
  • Files skipped - 1
    • docs/src/data/databases.json - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Feb 26, 2026
@dosubot dosubot Bot added the data:connect:clickhouse Related to Clickhouse label Feb 26, 2026
@netlify

netlify Bot commented Feb 26, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit e3a18b5
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69a0cdca18c1bd0008de5c62
😎 Deploy Preview https://deploy-preview-38280--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@villebro villebro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this! 🎉

Image

@joe-clickhouse

Copy link
Copy Markdown
Contributor Author

Hi @rusackas, I chatted offline with @villebro and he advised that the problem can be solved directly in clickhouse-connect and was correct. I have published v0.13.0 which contains the fix that allows the mutation logic to be removed entirely. As a side effect, an entire class of problems like alias interference such as #33551 will be eliminated.

@villebro

villebro commented Feb 26, 2026

Copy link
Copy Markdown
Member

@sadpandajoe this is an important fix for ClickHouse users, so if there's a 6.0.1-rc2 forthcoming, please pull this one in!

@villebro
villebro merged commit bb6ee9e into apache:master Feb 27, 2026
64 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

@codecov

codecov Bot commented Feb 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.87%. Comparing base (6589ee4) to head (81b4e03).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #38280      +/-   ##
==========================================
+ Coverage   64.11%   64.87%   +0.76%     
==========================================
  Files        1810     2482     +672     
  Lines       71175   122996   +51821     
  Branches    22650    28515    +5865     
==========================================
+ Hits        45631    79793   +34162     
- Misses      25544    41806   +16262     
- Partials        0     1397    +1397     
Flag Coverage Δ
hive 41.11% <ø> (?)
mysql 64.05% <ø> (?)
postgres 64.13% <ø> (?)
presto 41.13% <ø> (?)
python 65.90% <ø> (?)
sqlite 63.72% <ø> (?)
unit 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ivkhokhlachev

Copy link
Copy Markdown

Looks like this change now brings problems due to a Clickhouse setting prefer_column_name_to_alias
https://clickhouse.com/docs/operations/settings/settings#prefer_column_name_to_alias

Its default value is 0, so "The column name is substituted with the alias."

I'm now testing my charts on Superset 6.1.0 and this removal of random suffixes in column aliases leads to the scenario when applied Time Range filters implicitly depend on a Granularity filter.

E.g. I set values in a Time Range filter: Start 2026-06-10 (which was Wednesday) - End 2026-07-08
Actual Time Range, as shown in a filter, is "2026-06-10 ≤ col < 2026-07-08", days of two months

  1. I select Granularity="Day"
    Resulted query:
SELECT toDate("session_start_date_hour") AS "session_start_date_hour"
...
WHERE "session_start_date_hour" >= toDateTime('2026-06-10 00:00:00')
AND "session_start_date_hour" < toDateTime('2026-07-08 00:00:00')

Everything is ok.

  1. I decide to change granularity of the results and select Granularity="Week"
    "Actual Time Range" still the same "2026-06-10 ≤ col < 2026-07-08", but the resulted query is:
SELECT dateTrunc('WEEK', toDate("session_start_date_hour")) AS "session_start_date_hour"
...
WHERE "session_start_date_hour" >= toDateTime('2026-06-10 00:00:00')
AND "session_start_date_hour" < toDateTime('2026-07-08 00:00:00')

Due to the prefer_column_name_to_alias=0, the minimal day, included into the results is 2026-06-15, and the whole week before that Monday disappears from the results, while I didn't touch Time Range filter and "Actual Time Range" still says me it should be there.

  1. And the same for Granularity="Month"
    Resulted query:
SELECT dateTrunc('MONTH', toDate("session_start_date_hour")) AS "session_start_date_hour"
...
WHERE "session_start_date_hour" >= toDateTime('2026-06-10 00:00:00')
AND "session_start_date_hour" < toDateTime('2026-07-08 00:00:00')

So only results for July are shown.

In Superset 4.1.2, which we have on prod now, there's no such issue, cause the resulted query is always like

SELECT dateTrunc('MONTH', toDate("session_start_date_hour")) AS "session_start_date_hour_a6264a"
...
WHERE "session_start_date_hour" >= toDateTime('2026-06-10 00:00:00')
AND "session_start_date_hour" < toDateTime('2026-07-08 00:00:00')

so dynamic column aliases do not affect filters.

Did I miss anything about this update?

@joe-clickhouse

Copy link
Copy Markdown
Contributor Author

Hi @ivkhokhlachev did you try setting prefer_column_name_alias=1? You can set it in the engine params as:

{"connect_args": {"settings": {"prefer_column_name_to_alias": 1}}}

I ran an test locally and I think that'll solve the issue. It's probably worth a followup PR to default that value to 1 in the engine spec.

@villebro

Copy link
Copy Markdown
Member

Hi @ivkhokhlachev , thanks for the detailed write-up. I agree with @joe-clickhouse that setting it by default to 1 is the correct way to address this, as Superset heavily depends on this assumption. I think the best solution would be to default connect_args to {"settings": {"prefer_column_name_to_alias": 1}}, and then merge any additional connect_args the user defines into the final dict (some type of deep merge that would allow adding new settings but retaining the default seems best).

Abdulrehman-PIAIC80387 added a commit to Abdulrehman-PIAIC80387/superset that referenced this pull request Aug 7, 2026
Applies the pre-apache#38280 6-char hash suffix to column aliases on both
``ClickHouseEngineSpec`` (clickhouse-sqlalchemy) and
``ClickHouseConnectEngineSpec`` by placing the ``_mutate_label``
override on the shared ``ClickHouseBaseEngineSpec``. Fixes ClickHouse
25.3+ raising ``Code: 215`` on charts against virtual datasets when the
outer alias collides lexically with a subquery column name.

Also addresses @ivkhokhlachev's related regression on the apache#38280 thread
where time-range filters silently narrow when the granularity changes
(same root cause: alias == subquery column name → ClickHouse's
``prefer_column_name_to_alias=0`` substitutes the aliased expression
into the WHERE clause).

Documented in UPDATING.md: cached results keyed on the old aliases will
miss the cache once on upgrade, exported CSV/XLSX column names for
ClickHouse charts include the suffix, and any downstream consumer that
parses column headers will see the new names.

Fixes apache#40289
Abdulrehman-PIAIC80387 added a commit to Abdulrehman-PIAIC80387/superset that referenced this pull request Aug 10, 2026
Applies the pre-apache#38280 6-char hash suffix to column aliases on both
``ClickHouseEngineSpec`` (clickhouse-sqlalchemy) and
``ClickHouseConnectEngineSpec`` by placing the ``_mutate_label``
override on the shared ``ClickHouseBaseEngineSpec``. Fixes ClickHouse
25.3+ raising ``Code: 215`` on charts against virtual datasets when the
outer alias collides lexically with a subquery column name.

Also addresses @ivkhokhlachev's related regression on the apache#38280 thread
where time-range filters silently narrow when the granularity changes
(same root cause: alias == subquery column name → ClickHouse's
``prefer_column_name_to_alias=0`` substitutes the aliased expression
into the WHERE clause).

Documented in UPDATING.md: cached results keyed on the old aliases will
miss the cache once on upgrade, exported CSV/XLSX column names for
ClickHouse charts include the suffix, and any downstream consumer that
parses column headers will see the new names.

Fixes apache#40289
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect:clickhouse Related to Clickhouse doc Namespace | Anything related to documentation size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using clickhouse connect, label mutations do not allow using aliases and virtual columns

3 participants