From 36e6d9e471a244c05d70035da59b3db43b5f8d90 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Wed, 27 Sep 2023 17:08:28 -0500 Subject: [PATCH 1/2] WIP --- core/dbt/contracts/graph/model_config.py | 4 ++++ core/dbt/contracts/graph/nodes.py | 1 + core/dbt/contracts/graph/unparsed.py | 1 + core/dbt/parser/schema_yaml_readers.py | 7 ++++++ tests/functional/semantic_models/fixtures.py | 4 ++++ .../test_semantic_model_configs.py | 23 +++++++++++++++++++ 6 files changed, 40 insertions(+) diff --git a/core/dbt/contracts/graph/model_config.py b/core/dbt/contracts/graph/model_config.py index b28091e68c1..f44fee5d50c 100644 --- a/core/dbt/contracts/graph/model_config.py +++ b/core/dbt/contracts/graph/model_config.py @@ -382,6 +382,10 @@ class SemanticModelConfig(BaseConfig): default=None, metadata=CompareBehavior.Exclude.meta(), ) + meta: Dict[str, Any] = field( + default_factory=dict, + metadata=MergeBehavior.Update.meta(), + ) @dataclass diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index 065a60a6d33..57a6043e49d 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -1583,6 +1583,7 @@ class SemanticModel(GraphNode): refs: List[RefArgs] = field(default_factory=list) created_at: float = field(default_factory=lambda: time.time()) config: SemanticModelConfig = field(default_factory=SemanticModelConfig) + meta: Dict[str, Any] = field(default_factory=dict) unrendered_config: Dict[str, Any] = field(default_factory=dict) primary_entity: Optional[str] = None group: Optional[str] = None diff --git a/core/dbt/contracts/graph/unparsed.py b/core/dbt/contracts/graph/unparsed.py index d06b13faa03..df8149982f5 100644 --- a/core/dbt/contracts/graph/unparsed.py +++ b/core/dbt/contracts/graph/unparsed.py @@ -712,6 +712,7 @@ class UnparsedSemanticModel(dbtClassMixin): name: str model: str # looks like "ref(...)" config: Dict[str, Any] = field(default_factory=dict) + meta: Dict[str, Any] = field(default_factory=dict) description: Optional[str] = None label: Optional[str] = None defaults: Optional[Defaults] = None diff --git a/core/dbt/parser/schema_yaml_readers.py b/core/dbt/parser/schema_yaml_readers.py index dddad84c6db..2e357bbbe8e 100644 --- a/core/dbt/parser/schema_yaml_readers.py +++ b/core/dbt/parser/schema_yaml_readers.py @@ -549,6 +549,7 @@ def _generate_semantic_model_config( base=False, patch_config_dict=precedence_configs, ) + return config def parse_semantic_model(self, unparsed: UnparsedSemanticModel): @@ -595,8 +596,14 @@ def parse_semantic_model(self, unparsed: UnparsedSemanticModel): config=config, unrendered_config=unrendered_config, group=config.group, + meta=unparsed.meta, ) + # If we have meta in the config, copy to node level, for backwards + # compatibility with earlier node-only config. + if "meta" in config and config["meta"]: + parsed.meta = config["meta"] + ctx = generate_parse_semantic_models( parsed, self.root_project, diff --git a/tests/functional/semantic_models/fixtures.py b/tests/functional/semantic_models/fixtures.py index 3fb65a3a4fb..be5d88a7809 100644 --- a/tests/functional/semantic_models/fixtures.py +++ b/tests/functional/semantic_models/fixtures.py @@ -134,6 +134,9 @@ config: enabled: true group: some_group + meta: + my_meta: 'testing' + my_other_meta: 'testing more' dimensions: - name: favorite_color type: categorical @@ -185,6 +188,7 @@ agg_time_dimension: created_at """ + schema_yml = """models: - name: fct_revenue description: This is the model fct_revenue. It should be able to use doc blocks diff --git a/tests/functional/semantic_models/test_semantic_model_configs.py b/tests/functional/semantic_models/test_semantic_model_configs.py index 38009cddbe0..5938b1040c3 100644 --- a/tests/functional/semantic_models/test_semantic_model_configs.py +++ b/tests/functional/semantic_models/test_semantic_model_configs.py @@ -204,3 +204,26 @@ def test_project_plus_yaml_level(self, project): ).config assert isinstance(config_test_table, SemanticModelConfig) + + +# test setting meta attributes in semantic model config +class TestMetaConfig: + @pytest.fixture(scope="class") + def models(self): + return { + "people.sql": models_people_sql, + "metricflow_time_spine.sql": metricflow_time_spine_sql, + "semantic_models.yml": enabled_semantic_model_people_yml, + "people_metrics.yml": models_people_metrics_yml, + "groups.yml": groups_yml, + } + + def test_meta_config(self, project): + run_dbt(["parse"]) + manifest = get_manifest(project.project_root) + sm_id = "semantic_model.test.semantic_people" + assert sm_id in manifest.semantic_models + sm_node = manifest.semantic_models[sm_id] + meta_expected = {"my_meta": "testing", "my_other_meta": "testing more"} + assert sm_node.meta == meta_expected + assert sm_node.config.meta == meta_expected From 558a10f4a4e210b12e066728c603b327581fbf6b Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 29 Sep 2023 17:09:59 -0500 Subject: [PATCH 2/2] changelog --- .../unreleased/Features-20230929-170945.yaml | 6 ++ schemas/dbt/manifest/v11.json | 71 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .changes/unreleased/Features-20230929-170945.yaml diff --git a/.changes/unreleased/Features-20230929-170945.yaml b/.changes/unreleased/Features-20230929-170945.yaml new file mode 100644 index 00000000000..3497b2f5246 --- /dev/null +++ b/.changes/unreleased/Features-20230929-170945.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Add meta attribute to SemanticModels +time: 2023-09-29T17:09:45.0354-05:00 +custom: + Author: emmyoop + Issue: "8511" diff --git a/schemas/dbt/manifest/v11.json b/schemas/dbt/manifest/v11.json index a9dbd5cf32f..18047ef5135 100644 --- a/schemas/dbt/manifest/v11.json +++ b/schemas/dbt/manifest/v11.json @@ -4610,6 +4610,21 @@ } ], "default": null + }, + "join_to_timespine": { + "type": "boolean", + "default": false + }, + "fill_nulls_with": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "default": null } }, "additionalProperties": false, @@ -5137,6 +5152,17 @@ ], "default": null }, + "label": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null + }, "role": { "anyOf": [ { @@ -5257,6 +5283,17 @@ ], "default": null }, + "label": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null + }, "create_metric": { "type": "boolean", "default": false @@ -5381,6 +5418,17 @@ ], "default": null }, + "label": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null + }, "is_partition": { "type": "boolean", "default": false @@ -5449,6 +5497,12 @@ } ], "default": null + }, + "meta": { + "type": "object", + "propertyNames": { + "type": "string" + } } }, "additionalProperties": true @@ -5521,6 +5575,17 @@ ], "default": null }, + "label": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null + }, "defaults": { "anyOf": [ { @@ -5576,6 +5641,12 @@ "config": { "$ref": "#/$defs/SemanticModelConfig" }, + "meta": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "unrendered_config": { "type": "object", "propertyNames": {