fix(clickhouse): combine physical_properties into one SETTINGS clause#5817
Merged
StuffbyYuki merged 1 commit intoMay 29, 2026
Merged
Conversation
When a ClickHouse model declared more than one physical_property, _build_table_properties_exp produced a separate exp.SettingsProperty per key, which sqlglot renders as repeated 'SETTINGS k = v' keywords. ClickHouse rejects that with a syntax error at execution time. Refactor _build_settings_property to take the full settings mapping and emit a single SettingsProperty with one EQ expression per entry, yielding the expected 'SETTINGS k1 = v1, k2 = v2' form. The same fix applies to view properties, which used the identical pattern. Update the existing assertion that pinned the broken output, add a three-entry regression test mirroring the issue reporter's model, and cover the view-properties path that was silently affected. Fixes SQLMesh#5803 Signed-off-by: mokashang <shangmengjiajiajia@gmail.com>
af767e8 to
ac6df37
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #5803.
A ClickHouse model that declared more than one
physical_propertiesentry produced SQL with repeatedSETTINGSkeywords, e.g.ClickHouse rejects this with a syntax error. The valid form is a single comma-separated clause:
Root cause
In
ClickhouseEngineAdapter._build_table_properties_exp(and the analogous_build_view_properties_exp), every leftovertable_properties_copy/view_properties_copyentry was wrapped in its ownexp.SettingsPropertyand added to the property list. sqlglot renders eachSettingsPropertyas a separateSETTINGS …keyword, so N settings became N independent clauses.Fix
Refactor
_build_settings_propertyto accept the full settings mapping and emit a singleSettingsPropertywhoseexpressionslist holds oneexp.EQ(...)per key=value pair. Both the table and view paths now call it once with the entire dict andappendthe resulting property, producing the expectedSETTINGS k1 = v1, k2 = v2, …output.The behavior for a single setting is unchanged — a one-entry
SettingsPropertystill renders asSETTINGS k = v.Test Plan
test_model_propertiesassertion that pinned the brokenSETTINGS prop1 = 1 SETTINGS prop2 = '2'output; it now expects the combined form.test_model_propertiesthat mirrors the model from the issue report (min_age_to_force_merge_seconds,min_age_to_force_merge_on_partition_only,index_granularity) to guard against the failure mode beyond N=2.test_view_properties_combine_settingsthat exercises_build_view_properties_expdirectly, since the same bug existed there and had no unit-test coverage.sqlglotmatches ClickHouse's accepted syntax.pytest tests/core/engine_adapter/— 517 passed, 1 skipped, no regressions.ruff checkandmypyclean on the modified files.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO