Skip to content

Commit bb7f3d0

Browse files
committed
Improvements
1 parent 9cbe531 commit bb7f3d0

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

sqlmesh/dbt/model.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import datetime
44
import typing as t
5+
import logging
56

67
from sqlglot import exp
78
from sqlglot.errors import SqlglotError
@@ -34,6 +35,8 @@
3435
from sqlmesh.core.audit.definition import ModelAudit
3536
from sqlmesh.dbt.context import DbtContext
3637

38+
logger = logging.getLogger(__name__)
39+
3740

3841
INCREMENTAL_BY_TIME_STRATEGIES = set(["delete+insert", "insert_overwrite", "microbatch"])
3942
INCREMENTAL_BY_UNIQUE_KEY_STRATEGIES = set(["merge"])
@@ -522,16 +525,21 @@ def to_sqlmesh(
522525
partitioned_by.append(self._big_query_partition_by_expr(context))
523526
optional_kwargs["partitioned_by"] = partitioned_by
524527

525-
if self.cluster_by and not isinstance(kind, ViewKind):
526-
clustered_by = []
527-
for c in self.cluster_by:
528-
try:
529-
clustered_by.append(d.parse_one(c, dialect=model_dialect))
530-
except SqlglotError as e:
531-
raise ConfigError(
532-
f"Failed to parse model '{self.canonical_name(context)}' cluster_by field '{c}' in '{self.path}': {e}"
533-
) from e
534-
optional_kwargs["clustered_by"] = clustered_by
528+
if self.cluster_by:
529+
if isinstance(kind, ViewKind):
530+
logger.warning(
531+
f"Ignoring cluster_by config for model '{self.name}'; cluster_by is not supported for views."
532+
)
533+
else:
534+
clustered_by = []
535+
for c in self.cluster_by:
536+
try:
537+
clustered_by.append(d.parse_one(c, dialect=model_dialect))
538+
except SqlglotError as e:
539+
raise ConfigError(
540+
f"Failed to parse model '{self.canonical_name(context)}' cluster_by field '{c}' in '{self.path}': {e}"
541+
) from e
542+
optional_kwargs["clustered_by"] = clustered_by
535543

536544
model_kwargs = self.sqlmesh_model_kwargs(context)
537545
if self.sql_header:

tests/dbt/test_transformation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,17 @@ def test_model_cluster_by():
18371837
exp.to_column('"QUX"'),
18381838
]
18391839

1840+
model = ModelConfig(
1841+
name="model",
1842+
alias="model",
1843+
package_name="package",
1844+
target_schema="test",
1845+
cluster_by=["Bar", "qux"],
1846+
sql="SELECT * FROM baz",
1847+
materialized=Materialization.VIEW.value,
1848+
)
1849+
assert model.to_sqlmesh(context).clustered_by == []
1850+
18401851

18411852
def test_snowflake_dynamic_table():
18421853
context = DbtContext()

0 commit comments

Comments
 (0)