Skip to content

Commit ca54b15

Browse files
benc-dbclaude
andauthored
fix: Use DROP + CREATE for MV partition_by changes (#1327)
CREATE OR REPLACE MATERIALIZED VIEW cannot change partition_by, so use DROP + CREATE when partition_by is changing. This restores the previous behavior for partition_by changes while keeping CREATE OR REPLACE for other full refresh scenarios. ### Checklist - [x] I have run this code in development and it appears to resolve the stated issue - [x] This PR includes tests, or tests are not required/relevant for this PR - [ ] I have updated the `CHANGELOG.md` and added information about my change to the "dbt-databricks next" section. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 25caa2a commit ca54b15

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • dbt/include/databricks/macros/relations/materialized_view

dbt/include/databricks/macros/relations/materialized_view/alter.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
) %}
2828
-- apply a full refresh immediately if needed
2929
{% if configuration_changes.requires_full_refresh %}
30-
{% do return(get_replace_sql(existing_relation, relation, sql)) %}
30+
{#- CREATE OR REPLACE cannot change partition_by, so use DROP + CREATE when partition_by changes -#}
31+
{% if configuration_changes.changes["partition_by"] %}
32+
{{- log('Applying REPLACE to: ' ~ existing_relation) -}}
33+
{% do return(drop_and_create(existing_relation, relation, sql)) %}
34+
{% else %}
35+
{% do return(get_replace_sql(existing_relation, relation, sql)) %}
36+
{% endif %}
3137

3238
-- otherwise apply individual changes as needed
3339
{% else %}

0 commit comments

Comments
 (0)