Skip to content

Commit

Permalink
Fix partial parsing issue not working for changing semantic model name (
Browse files Browse the repository at this point in the history
#8865) (#8878)

* fix

* test

* changelog

(cherry picked from commit 35f46da)

Co-authored-by: Chenyu Li <[email protected]>
  • Loading branch information
github-actions[bot] and ChenyuLInx authored Oct 25, 2023
1 parent 1baebb4 commit ced70d5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231016-163953.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix partial parsing not working for semantic model change
time: 2023-10-16T16:39:53.05058-07:00
custom:
Author: ChenyuLInx
Issue: "8859"
3 changes: 3 additions & 0 deletions core/dbt/parser/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ def delete_schema_semantic_model(self, schema_file, semantic_model_dict):
if unique_id in self.saved_manifest.semantic_models:
semantic_model = self.saved_manifest.semantic_models[unique_id]
if semantic_model.name == semantic_model_name:
# Need to find everything that referenced this semantic model and schedule for parsing
if unique_id in self.saved_manifest.child_map:
self.schedule_nodes_for_parsing(self.saved_manifest.child_map[unique_id])
self.saved_manifest.semantic_models.pop(unique_id)
schema_file.semantic_models.remove(unique_id)
elif unique_id in self.saved_manifest.disabled:
Expand Down
33 changes: 33 additions & 0 deletions tests/functional/semantic_models/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@
agg_time_dimension: created_at
"""

semantic_model_people_diff_name_yml = """
version: 2
semantic_models:
- name: semantic_people_diff_name
label: "Semantic People"
model: ref('people')
dimensions:
- name: favorite_color
label: "Favorite Color"
type: categorical
- name: created_at
label: "Created At"
type: TIME
type_params:
time_granularity: day
measures:
- name: years_tenure
label: "Years Tenure"
agg: SUM
expr: tenure
- name: people
label: "People"
agg: count
expr: id
entities:
- name: id
label: "Primary ID"
type: primary
defaults:
agg_time_dimension: created_at
"""

semantic_model_descriptions = """
{% docs semantic_model_description %} foo {% enddocs %}
{% docs dimension_description %} bar {% enddocs %}
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/semantic_models/test_semantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from dbt.contracts.graph.manifest import Manifest
from dbt.exceptions import CompilationError
from dbt.tests.util import run_dbt
from dbt.tests.util import write_file
from tests.functional.semantic_models.fixtures import (
models_people_sql,
simple_metricflow_time_spine_sql,
semantic_model_people_yml,
models_people_metrics_yml,
semantic_model_people_diff_name_yml,
semantic_model_people_yml_with_docs,
semantic_model_descriptions,
)
Expand Down Expand Up @@ -71,3 +73,27 @@ def test_unknown_model_raises_issue(self, project):
with pytest.raises(CompilationError) as excinfo:
run_dbt(["parse"])
assert "depends on a node named 'people' which was not found" in str(excinfo.value)


class TestSemanticModelPartialParsing:
@pytest.fixture(scope="class")
def models(self):
return {
"people.sql": models_people_sql,
"metricflow_time_spine.sql": simple_metricflow_time_spine_sql,
"semantic_models.yml": semantic_model_people_yml,
"people_metrics.yml": models_people_metrics_yml,
}

def test_semantic_model_deleted_partial_parsing(self, project):
# First, use the default saved_queries.yml to define our saved_query, and
# run the dbt parse command
run_dbt(["parse"])
# Next, modify the default semantic_models.yml to remove the saved query.
write_file(
semantic_model_people_diff_name_yml,
project.project_root,
"models",
"semantic_models.yml",
)
run_dbt(["compile"])

0 comments on commit ced70d5

Please sign in to comment.