Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions sqlmesh/dbt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
logger = logging.getLogger(__name__)


logger = logging.getLogger(__name__)


INCREMENTAL_BY_TIME_STRATEGIES = set(["delete+insert", "insert_overwrite", "microbatch"])
INCREMENTAL_BY_UNIQUE_KEY_STRATEGIES = set(["merge"])

Expand Down Expand Up @@ -521,14 +524,24 @@ def to_sqlmesh(
raise ConfigError(
f"Failed to parse model '{self.canonical_name(context)}' partition_by field '{p}' in '{self.path}': {e}"
) from e
else:
partitioned_by.append(self._big_query_partition_by_expr(context))
optional_kwargs["partitioned_by"] = partitioned_by
elif isinstance(self.partition_by, dict):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if neither dict nor list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if context.target.dialect == "bigquery":
partitioned_by.append(self._big_query_partition_by_expr(context))
else:
logger.warning(
"Ignoring partition_by config for model '%s' targeting %s. The format of the config field is only supported for BigQuery.",
self.name,
context.target.dialect,
)

if partitioned_by:
optional_kwargs["partitioned_by"] = partitioned_by

if self.cluster_by:
if isinstance(kind, ViewKind):
logger.warning(
f"Ignoring cluster_by config for model '{self.name}'; cluster_by is not supported for views."
"Ignoring cluster_by config for model '%s'; cluster_by is not supported for views.",
self.name,
)
else:
clustered_by = []
Expand Down
3 changes: 3 additions & 0 deletions tests/dbt/test_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ def test_partition_by(sushi_test_project: Project):
model_config.partition_by = {"field": "ds", "data_type": "date", "granularity": "day"}
assert model_config.to_sqlmesh(context).partitioned_by == [exp.to_column("ds", quoted=True)]

context.target = DuckDbConfig(name="target", schema="foo")
assert model_config.to_sqlmesh(context).partitioned_by == []


@pytest.mark.xdist_group("dbt_manifest")
def test_partition_by_none(sushi_test_project: Project):
Expand Down