Repository navigation
test: assert ClickHouse overwrite SQL - #6149
Conversation
Signed-off-by: Michael Day <mdaytn@gmail.com>
StuffbyYuki
left a comment
There was a problem hiding this comment.
An optional:
Instead of the prefix/sort/split checks in the tests, perhaps consider making the generated ALTER deterministic at the source. In sqlmesh/core/engine_adapter/clickhouse.py, _build_alter_partition_exp loops over partitions_to_replace and partitions_to_drop, which are Python sets, so the action order can change between runs. Sorting them fixes that:
for partition in sorted(partitions_to_replace):
...
for partition in sorted(partitions_to_drop):
...
This only changes the order of actions within the single ALTER statement. It doesn't change which partitions are replaced or dropped, or how many statements are executed. As a side benefit, the SQL in logs and ClickHouse query history becomes stable.
Signed-off-by: mday-io <mdaytn@gmail.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Partition action ordering and overwrite expectations sqlmesh/core/engine_adapter/clickhouse.py, tests/core/engine_adapter/test_clickhouse.py |
Partition replacement and drop actions now use sorted partition IDs. Tests update partitioned and dynamic-key overwrite expectations for the affected_partitions table, distinct ID selection, and replacement order. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Other
Possibly related issues
- SQLMesh/sqlmesh#6171: The changes cover partition replacement SQL and action ordering, but do not address the issue’s
insert_quorumor replica synchronization concerns.
Suggested reviewers: treysp
Merge Risk: 
Minimal · up to a2d02
-
This change makes partition actions deterministic and strengthens overwrite SQL coverage without introducing a demonstrated merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Description
Why
Five ClickHouse overwrite tests compared generated SQL with expected statements without asserting the result, allowing incorrect replacement SQL to pass. Partition actions also varied with Python set order.
How
Restore the assertions across full, time-range, key-based, and partition-based overwrites. Give staging and affected-partition tables distinct test names, and correct DISTINCT and cleanup expectations. Sort replacement and drop partition IDs when building the ALTER statement so tests can assert complete SQL call lists and logs show stable action order. Partition selection and statement count stay the same.
Test Plan
PYTHONHASHSEED=1and42; before sorting, the three partitioned cases failed on action order under both seeds.make stylepassed.make fast-testpassed: 2,895 tests, 13 skipped across all required batches; four xdist workers.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCOSummary by CodeRabbit