Skip to content

Commit 961284e

Browse files
committed
fix: cluster_by as single string with multiple columns
1 parent 93c7a10 commit 961284e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sqlmesh/dbt/model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@ class ModelConfig(BaseModelConfig):
157157

158158
@field_validator(
159159
"unique_key",
160-
"cluster_by",
161160
"tags",
162161
mode="before",
163162
)
164163
@classmethod
165164
def _validate_list(cls, v: t.Union[str, t.List[str]]) -> t.List[str]:
166165
return ensure_list(v)
167166

167+
@field_validator("cluster_by", mode="before")
168+
@classmethod
169+
def _validate_cluster_by(cls, v: t.Union[str, t.List[str]]) -> t.Union[str, t.List[str]]:
170+
if isinstance(v, str):
171+
return [c.strip() for c in v.split(",")]
172+
return ensure_list(v)
173+
168174
@field_validator("check_cols", mode="before")
169175
@classmethod
170176
def _validate_check_cols(cls, v: t.Union[str, t.List[str]]) -> t.Union[str, t.List[str]]:

tests/dbt/test_transformation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,20 @@ def test_model_cluster_by():
22542254
)
22552255
assert model.to_sqlmesh(context).clustered_by == []
22562256

2257+
model = ModelConfig(
2258+
name="model",
2259+
alias="model",
2260+
package_name="package",
2261+
target_schema="test",
2262+
cluster_by="Bar, qux",
2263+
sql="SELECT * FROM baz",
2264+
materialized=Materialization.TABLE.value,
2265+
)
2266+
assert model.to_sqlmesh(context).clustered_by == [
2267+
exp.to_column('"BAR"'),
2268+
exp.to_column('"QUX"'),
2269+
]
2270+
22572271

22582272
def test_snowflake_dynamic_table():
22592273
context = DbtContext()

0 commit comments

Comments
 (0)