22
33import datetime
44import typing as t
5+ import logging
56
67from sqlglot import exp
78from sqlglot .errors import SqlglotError
3435 from sqlmesh .core .audit .definition import ModelAudit
3536 from sqlmesh .dbt .context import DbtContext
3637
38+ logger = logging .getLogger (__name__ )
39+
3740
3841INCREMENTAL_BY_TIME_STRATEGIES = set (["delete+insert" , "insert_overwrite" , "microbatch" ])
3942INCREMENTAL_BY_UNIQUE_KEY_STRATEGIES = set (["merge" ])
@@ -503,6 +506,7 @@ def to_sqlmesh(
503506 """Converts the dbt model into a SQLMesh model."""
504507 model_dialect = self .dialect (context )
505508 query = d .jinja_query (self .sql_no_config )
509+ kind = self .model_kind (context )
506510
507511 optional_kwargs : t .Dict [str , t .Any ] = {}
508512 physical_properties : t .Dict [str , t .Any ] = {}
@@ -522,15 +526,20 @@ def to_sqlmesh(
522526 optional_kwargs ["partitioned_by" ] = partitioned_by
523527
524528 if self .cluster_by :
525- clustered_by = []
526- for c in self .cluster_by :
527- try :
528- clustered_by .append (d .parse_one (c , dialect = model_dialect ))
529- except SqlglotError as e :
530- raise ConfigError (
531- f"Failed to parse model '{ self .canonical_name (context )} ' cluster_by field '{ c } ' in '{ self .path } ': { e } "
532- ) from e
533- optional_kwargs ["clustered_by" ] = clustered_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
534543
535544 model_kwargs = self .sqlmesh_model_kwargs (context )
536545 if self .sql_header :
@@ -627,7 +636,6 @@ def to_sqlmesh(
627636 if physical_properties :
628637 model_kwargs ["physical_properties" ] = physical_properties
629638
630- kind = self .model_kind (context )
631639 allow_partials = model_kwargs .pop ("allow_partials" , None )
632640 if (
633641 allow_partials is None
0 commit comments