@@ -316,13 +316,32 @@ def build_properties_sql(storage_format="", order_by="", primary_key="", propert
316316 == "ENGINE=MergeTree ORDER BY (a, b + 1) PRIMARY KEY (a, b)"
317317 )
318318
319+ # Multiple physical_properties must be combined into a single comma-separated
320+ # SETTINGS clause. ClickHouse rejects repeated SETTINGS keywords with a syntax
321+ # error (see https://github.com/SQLMesh/sqlmesh/issues/5803).
319322 assert (
320323 build_properties_sql (
321324 order_by = "ORDER_BY = (a, b + 1)," ,
322325 primary_key = "PRIMARY_KEY = (a, b)," ,
323326 properties = "PROP1 = 1, PROP2 = '2'" ,
324327 )
325- == "ENGINE=MergeTree ORDER BY (a, b + 1) PRIMARY KEY (a, b) SETTINGS prop1 = 1 SETTINGS prop2 = '2'"
328+ == "ENGINE=MergeTree ORDER BY (a, b + 1) PRIMARY KEY (a, b) SETTINGS prop1 = 1, prop2 = '2'"
329+ )
330+
331+ # Regression test for #5803: three or more SETTINGS entries also combine.
332+ assert (
333+ build_properties_sql (
334+ order_by = "ORDER_BY = (orders_id)," ,
335+ properties = (
336+ "min_age_to_force_merge_seconds = 3600, "
337+ "min_age_to_force_merge_on_partition_only = 1, "
338+ "index_granularity = 8192"
339+ ),
340+ )
341+ == "ENGINE=MergeTree ORDER BY (orders_id) "
342+ "SETTINGS min_age_to_force_merge_seconds = 3600, "
343+ "min_age_to_force_merge_on_partition_only = 1, "
344+ "index_granularity = 8192"
326345 )
327346
328347 assert (
@@ -345,6 +364,20 @@ def build_properties_sql(storage_format="", order_by="", primary_key="", propert
345364 )
346365
347366
367+ def test_view_properties_combine_settings (adapter : ClickhouseEngineAdapter ):
368+ # View properties hit the same SettingsProperty code path as table
369+ # properties (#5803): multiple entries must collapse into one SETTINGS
370+ # clause rather than emit repeated SETTINGS keywords.
371+ view_properties_exp = adapter ._build_view_properties_exp (
372+ view_properties = {
373+ "prop1" : exp .Literal .number (1 ),
374+ "prop2" : exp .Literal .string ("2" ),
375+ }
376+ )
377+ assert view_properties_exp is not None
378+ assert view_properties_exp .sql ("clickhouse" ) == "SETTINGS prop1 = 1, prop2 = '2'"
379+
380+
348381def test_partitioned_by_expr (make_mocked_engine_adapter : t .Callable ):
349382 # user doesn't specify, unknown time column type
350383 model = load_sql_based_model (
0 commit comments