Fabric: false destructive change on SCD2 `valid_from`/`valid_to` because `TIMESTAMP` and `DATETIME2(6)` are seen as different types

Đang mở
#6,224 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
53/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, sql
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start with sqlmesh/core/schema_diff.py and the Fabric adapter’s MSSQLEngineAdapter.columns() implementation. Reproduce the issue with the provided get_schema_differ("fabric") snippet, then check how dialect-rendered types are compared and how DATETIME_PRECISION is queried. Done means the comparison emits only ADD c for the repro and the existing datetime2 precision is read correctly.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem
On Fabric (SQLMesh 0.236.4), adding a nullable column to an existing SCD_TYPE_2_BY_COLUMN model fails the plan:

ALTER TABLE .. ADD cancelled_flag BIT
ALTER TABLE .. DROP COLUMN _dwh_valid_from
ALTER TABLE .. ADD _dwh_valid_from DATETIME2(6)
ALTER TABLE .. DROP COLUMN _dwh_valid_to
ALTER TABLE .. ADD _dwh_valid_to DATETIME2(6)
Error: Plan requires a destructive change to a forward-only model.

Allowing it would wipe all SCD2 history.

Cause

  • The plan's destructive check compares the old and new columns_to_types, including the SCD2 managed columns.
  • The stored snapshot has DATETIME2(6), while the new model keeps the generic TIMESTAMP. Both render as DATETIME2(6) in Fabric.
  • SchemaDiffer compares the raw types, sees a type change, and plans DROP + ADD.

Repro

from sqlglot import exp
from sqlmesh.core.schema_diff import get_schema_differ

sd = get_schema_differ("fabric")
cur = {"v": exp.DataType.build("DATETIME2(6)", dialect="fabric")}
new = {"v": exp.DataType.build("TIMESTAMP"), "c": exp.DataType.build("BIT")}
print([o.expression.sql("fabric") for o in sd.compare_columns("t", cur, new)])
# actual:   ADD c, DROP v, ADD v DATETIME2(6)
# expected: ADD c

Proposed fix

  1. Treat types that render identically in the dialect as unchanged. In SchemaDiffer (or in PlanBuilder before calling compare_columns):
    exp.DataType.build(t.sql(dialect), dialect=dialect)
  2. Add DATETIME_PRECISION to the column query in MSSQLEngineAdapter.columns(). Today an existing datetime2(6) column is read back as datetime2, which counts as (7).
Ngôn ngữ chính
Python
Star
3.3k
Fork
471
Merge trung bình
6 ngày 7 giờ
Pull request đã merge (30 ngày)
35

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SQLMesh/sqlmesh

Tất cả issue của SQLMesh/sqlmesh

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.