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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fix PK/FK constraints declaring an `expression` (e.g. `RELY`) being dropped and re-added on every incremental run. **Regression:** changing the `expression` on an existing PK/FK (`RELY`↔`NORELY`, or an expression-form FK's target) is no longer applied on incremental runs — use `--full-refresh`. ([#1552](https://github.com/databricks/dbt-databricks/pull/1552) closes [#1513](https://github.com/databricks/dbt-databricks/issues/1513))
- Honor `incremental_apply_config_changes` in the V1 incremental merge path, allowing users to skip metadata diff queries (tags, column_tags, constraints, column_masks, tblproperties, describe_extended) when set to `false`. Matches the existing V2 behavior. ([1467](https://github.com/databricks/dbt-databricks/pull/1467) partially solves [#1402](https://github.com/databricks/dbt-databricks/issues/1402))
- Fix column-level `databricks_tags` on Unity Catalog views updated via `ALTER` (`view_update_via_alter: true`) ([#1526](https://github.com/databricks/dbt-databricks/pull/1526) closes [#1525](https://github.com/databricks/dbt-databricks/issues/1525))
- Apply `tblproperties` to `metric_view` models at create time, not only on a later alter/replace run ([#1530](https://github.com/databricks/dbt-databricks/pull/1530) closes [#1527](https://github.com/databricks/dbt-databricks/issues/1527))

### Under the Hood

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
{{ get_create_metric_view_as_sql(target_relation, sql) }}
{%- endcall %}
{{ apply_tags(target_relation, tags) }}
{% set tblproperties = config.get('tblproperties') %}
{% if tblproperties %}
{{ apply_tblproperties(target_relation, tblproperties) }}
{% endif %}
{% endif %}

{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke(existing_relation, full_refresh_mode=True)) %}
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/adapter/metric_views/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,23 @@
- name: order_count
expr: count(1)
"""

metric_view_with_tblproperties = """
{{
config(
materialized='metric_view',
tblproperties={
'quality': 'gold'
}
)
}}

version: 1.1
source: "{{ ref('source_orders') }}"
dimensions:
- name: status
expr: status
measures:
- name: order_count
expr: count(1)
"""
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
metric_view_bare_ref,
metric_view_with_config,
metric_view_with_filter,
metric_view_with_tblproperties,
source_table,
)

Expand Down Expand Up @@ -254,3 +255,27 @@ def test_bare_ref_metric_view_creates_and_queries(self, project):
fetch="all",
)
assert query_result and query_result[0][0] == 3


@pytest.mark.skip_profile("databricks_cluster")
class TestMetricViewCreateTblProperties:
"""tblproperties configured on a metric view are set on the freshly created view."""

@pytest.fixture(scope="class")
def models(self):
return {
"source_orders.sql": source_table,
"tblprops_metrics.sql": metric_view_with_tblproperties,
}

def test_tblproperties_applied_on_create(self, project):
results = run_dbt(["run"])
assert len(results) == 2
assert all(result.status == "success" for result in results)

rows = project.run_sql(
f"show tblproperties {project.database}.{project.test_schema}.tblprops_metrics",
fetch="all",
)
tblprops = {row[0]: row[1] for row in rows}
assert tblprops.get("quality") == "gold"
Loading