Skip to content

fix(clickhouse): support multi-gateway projects with catalog-aware engines#5826

Open
mday-io wants to merge 3 commits into
SQLMesh:mainfrom
mday-io:fix/clickhouse-multi-gateway-catalog-support
Open

fix(clickhouse): support multi-gateway projects with catalog-aware engines#5826
mday-io wants to merge 3 commits into
SQLMesh:mainfrom
mday-io:fix/clickhouse-multi-gateway-catalog-support

Conversation

@mday-io
Copy link
Copy Markdown
Contributor

@mday-io mday-io commented Jun 3, 2026

Description

When adding a ClickHouse gateway to a project that already has a catalog-aware gateway (catalog.schema.table) (e.g. Trino), SQLMesh throws an error.

Error: Failed to update model schemas

Table "default"."connection_test" must match the schema's nesting level: 3.

The issue is that sqlglot's MappingSchema expects all models to use the same FQN depth. ClickHouse doesn't have a catalog concept so its models are 2-level (db.table), while Trino models are 3-level (catalog.db.table). SQLMesh doesn't handle the mix — registering models from both gateways causes a nesting mismatch.

Found this by accident: plan worked fine after manually adding a fake third tier to ClickHouse model references, which confirmed the mismatch was the culprit.

The fix injects the gateway name as a virtual catalog for ClickHouse, bumping its models up to 3-level FQNs internally so they match. The virtual catalog is stripped before anything hits the wire, so ClickHouse never sees it.

Note: Projects that previously used ClickHouse as a single gateway and now add a catalog-aware gateway will see ClickHouse models re-materialized once. Their FQNs transition from 2-level to "3-level", which changes their fingerprints.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

mday-io added 3 commits June 3, 2026 15:18
…gines

ClickHouse's UNSUPPORTED catalog_support caused 2-level FQNs that broke
sqlglot MappingSchema when mixed with 3-level FQNs from Trino or other
catalog-aware gateways. Fix: auto-inject a virtual catalog (gateway name)
for UNSUPPORTED adapters when catalog-aware peers exist, then strip it
before any SQL reaches ClickHouse.

Signed-off-by: mday-io <mdaytn@gmail.com>
@mday-io mday-io force-pushed the fix/clickhouse-multi-gateway-catalog-support branch from b1435d7 to 89696e5 Compare June 3, 2026 19:54
@mday-io mday-io changed the title fix(clickhouse): support multi-gateway projects with catalog-aware gines fix(clickhouse): support multi-gateway projects with catalog-aware engines Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant