Skip to content

Commit 110d7f2

Browse files
crerichaizeigerman
andauthored
Fix: Ignore bigquery partition_by config when the target isn't bigquery (#5280)
Co-authored-by: Iaroslav Zeigerman <zeigerman.ia@gmail.com>
1 parent d307981 commit 110d7f2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

sqlmesh/dbt/model.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
logger = logging.getLogger(__name__)
3939

4040

41+
logger = logging.getLogger(__name__)
42+
43+
4144
INCREMENTAL_BY_TIME_STRATEGIES = set(["delete+insert", "insert_overwrite", "microbatch"])
4245
INCREMENTAL_BY_UNIQUE_KEY_STRATEGIES = set(["merge"])
4346

@@ -521,14 +524,24 @@ def to_sqlmesh(
521524
raise ConfigError(
522525
f"Failed to parse model '{self.canonical_name(context)}' partition_by field '{p}' in '{self.path}': {e}"
523526
) from e
524-
else:
525-
partitioned_by.append(self._big_query_partition_by_expr(context))
526-
optional_kwargs["partitioned_by"] = partitioned_by
527+
elif isinstance(self.partition_by, dict):
528+
if context.target.dialect == "bigquery":
529+
partitioned_by.append(self._big_query_partition_by_expr(context))
530+
else:
531+
logger.warning(
532+
"Ignoring partition_by config for model '%s' targeting %s. The format of the config field is only supported for BigQuery.",
533+
self.name,
534+
context.target.dialect,
535+
)
536+
537+
if partitioned_by:
538+
optional_kwargs["partitioned_by"] = partitioned_by
527539

528540
if self.cluster_by:
529541
if isinstance(kind, ViewKind):
530542
logger.warning(
531-
f"Ignoring cluster_by config for model '{self.name}'; cluster_by is not supported for views."
543+
"Ignoring cluster_by config for model '%s'; cluster_by is not supported for views.",
544+
self.name,
532545
)
533546
else:
534547
clustered_by = []

tests/dbt/test_transformation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,9 @@ def test_partition_by(sushi_test_project: Project):
14691469
model_config.partition_by = {"field": "ds", "data_type": "date", "granularity": "day"}
14701470
assert model_config.to_sqlmesh(context).partitioned_by == [exp.to_column("ds", quoted=True)]
14711471

1472+
context.target = DuckDbConfig(name="target", schema="foo")
1473+
assert model_config.to_sqlmesh(context).partitioned_by == []
1474+
14721475

14731476
@pytest.mark.xdist_group("dbt_manifest")
14741477
def test_partition_by_none(sushi_test_project: Project):

0 commit comments

Comments
 (0)