SCD_TYPE_2_BY_COLUMN: opt-in strict attributes on close (no COALESCE(target, source) for updated_rows)
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
The change lives in sqlmesh/core/engine_adapter/base.py inside the _scd_type_2 method. Find the updated_rows CTE where unmanaged attributes are emitted with COALESCE(t_<col>, source.<col>). Add a model-level option to skip the COALESCE and use only t_<col> for closed rows, then add tests covering both the default and strict modes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When SCD_TYPE_2_BY_COLUMN detects a change in check_columns (e.g. a row-level hash), SQLMesh rebuilds existing rows in the updated_rows CTE inside _scd_type_2 (sqlmesh/core/engine_adapter/base.py). For every unmanaged attribute it currently uses:
COALESCE(t_<col>, source.<col>)
— i.e. prefer the previous open row (t_*), but if that value is NULL, take the incoming batch (source).
Why this hurts
-
NULL backfill from the next batch
If the currently open row has NULL and the next daily batch has a value, the closed period’s row can show the new value even though it was NULL for the whole period you just closed. The physical table no longer matches that day’s snapshot. -
Erasures (value → NULL) are mishandled in the same pattern
COALESCE(previous_value, NULL) keeps the old value. So when the new batch clears a field, the closed row may still show the old non-NULL while you expected NULL for the period that just ended—unless the change detection also fires purely on that column in a way that matches your mental model. -
Symptom
After loading a later snapshot, two SCD versions can look identical on business columns even though the underlying snapshot rows differed (e.g. NULL vs populated on a non-tracked attribute). That undermines audits and “as-of” reporting against clients_snapshot.
Desired behavior (strict / snapshot-faithful SCD2)
When a version is closed because check_columns changed:
Attribute columns on that closed row should still describe that version’s row as it was while open—typically the values from t_* (the previous open/target row), not values filled in from the next batch’s source.
When a new version is inserted, it should still come from the current batch’s source as today.
So we want a model-level option on SCD_TYPE_2_BY_COLUMN, for example:
scd_attribute_close_mode: coalesce_null (current default) vs strict (or boolean disable_coalesce_on_updated_rows),
where strict means: for updated_rows, emit unmanaged attributes as t_ only (no COALESCE with source), so:
NULL in the open row stays NULL on the closed row when the next batch fills the field in the new row only.
Clearing a field in the next batch does not leave stale non-NULL on the closed row because of COALESCE.
(Exact naming and defaults are for maintainers; the behavioral split is what matters.)
Motivation
We load daily snapshots. The hash can change between days when e.g. a field is NULL in one extract and populated in another. After the later run, two SCD rows can look the same on business columns because the closed row was rewritten with COALESCE(latest, source). We need an optional mode that keeps closed attribute columns aligned with what was actually true for that version.
References
Implementation: sqlmesh/core/engine_adapter/base.py, _scd_type_2, CTE updated_rows (the COALESCE over prefixed_unmanaged_columns and joined source columns).
- 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
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.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SQLMesh/sqlmesh
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
SQLMesh/sqlmesh#6008 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
VSCode Extension: SQLMesh LSP crashes on startup: ImportError: cannot import name 'WorkspaceDiagnosticRefreshRequest' with lsprotocol 2025.xCó thể đã có người làm @boomesh11 đã nhận 15 ngày trước. Đang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Improvement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
SQLMesh/sqlmesh#5696 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của SQLMesh/sqlmesh
Issue tương tự
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%Có thể đã có người làm @sumitkhond111-del đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bmad-code-org/BMAD-METHOD#3358 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
open-mmlab/mmcv#3352 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
OpenGithubs/weekly#263 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
comp/cli P3 type/feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NousResearch/hermes-agent#162784 ·
Maintainer thường phản hồi trong vòng 1 ngày