ClickHouse virtual catalog is not stripped from CREATE TABLE AS SELECT / INSERT source queries (physical layer)

未关闭
#5,960 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
clickhouse, python, sql
领域
databases

调研方向

Start by comparing the physical-table _create_table and INSERT paths with the create_view fix in issues #5938 and #5940. Trace how source-query table identifiers retain the injected virtual catalog, then add coverage for the ClickHouse CTAS and INSERT cases. Done when source queries sent to ClickHouse use supported identifiers and the reproduced sqlmesh plan completes without a syntax error.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

This is a sibling of #5938 / #5940 ("virtual catalog not stripped from CREATE VIEW source queries"). That fix covered create_view, but the same bug still exists on the physical-table path: _create_table (CTAS) and the INSERT paths strip the injected virtual catalog only from the target table name, not from the source query's FROM tables. As a result ClickHouse receives a 3-part identifier and fails with SYNTAX_ERROR (code 62) whenever a FULL (or incremental) model reads from another model.

Environment

  • sqlmesh 0.236.1
  • A ClickHouse gateway (catalog-unsupported) coexisting with a catalog-aware gateway (BigQuery) in the same project, so scheduler.get_default_catalog_per_gateway() injects a virtual catalog (__ch__) into the ClickHouse adapter.
  • default_gateway: ch

Reproduction

config.yaml:

model_defaults:
  start: 2025-01-01
  dialect: clickhouse

gateways:
  ch:
    connection:
      type: clickhouse
      host: <host>
      username: <user>
      password: <pw>
    state_connection: { type: postgres, host: ..., port: 5432, user: ..., password: ..., database: sqlmesh }
  bigquery:                 # <-- merely defining a catalog-aware gateway triggers virtual-catalog injection
    connection:
      type: bigquery
      method: oauth
      project: my-project
      location: EU
    state_connection: { type: postgres, ... }

default_gateway: ch

models/silver/test_table.sql:

MODEL (name silver.test_table, kind FULL);
SELECT 1 AS first_column;

models/gold/test_table.sql:

MODEL (name gold.test_table, kind FULL);
SELECT *, 2 AS second_column FROM silver.test_table;

Run:

sqlmesh plan

Actual behaviour

"__ch__"."gold"."test_table"
  DatabaseError:
    Code: 62. DB::Exception: Syntax error: failed at position 512 (AS):
    AS "test_table") AS "_subquery". ... (SYNTAX_ERROR)
Error: Plan application failed.

The statement sent to ClickHouse for the physical gold table is:

CREATE TABLE "sqlmesh__gold"."gold__test_table__..." AS
SELECT ...
FROM "__ch__"."sqlmesh__silver"."silver__test_table__..." AS "test_table"   -- <-- 3-part FQN, invalid in ClickHouse

(The nested source table still carries __ch__; ClickHouse only supports database.table.)

Impact

Gateway-managed virtual-layer promotion cannot complete for ClickHouse models
in affected multi-gateway projects. Physical objects may be created before the
promotion failure, leaving a partially applied plan to clean up.

Environment

SQLMesh: 0.236.1
ClickHouse: 26.7

主要语言
Python
星标
3.3k
派生
471
平均合并
6 天 7 小时
30 天内合并 PR
35

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SQLMesh/sqlmesh 的其他 Issue

查看 SQLMesh/sqlmesh 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。