From d9eacc25a96b6ed25054973fc59cc29e8832b25c Mon Sep 17 00:00:00 2001 From: Peter Allen Webb Date: Tue, 11 Jul 2023 10:36:32 -0400 Subject: [PATCH 1/2] Alias NodeRelation.schema_name to simply 'schema' --- .../implementations/semantic_model.py | 5 ++-- .../default_explicit_schema.json | 4 +-- dbt_semantic_interfaces/parsing/schemas.py | 4 +-- dbt_semantic_interfaces/test_utils.py | 2 +- .../semantic_models/accounts_source.yaml | 2 +- .../semantic_models/bookings_source.yaml | 2 +- .../semantic_models/companies.yaml | 2 +- .../semantic_models/id_verifications.yaml | 2 +- .../semantic_models/listings_latest.yaml | 2 +- .../semantic_models/lux_listing_mapping.yaml | 2 +- .../semantic_models/revenue.yaml | 2 +- .../semantic_models/user_sm_source.yaml | 2 +- .../semantic_models/users_latest.yaml | 2 +- .../semantic_models/views_source.yaml | 2 +- tests/parsing/test_semantic_model_parsing.py | 28 +++++++++---------- tests/validations/test_entities.py | 4 +-- tests/validations/test_measures.py | 14 +++++----- tests/validations/test_semantic_models.py | 2 +- .../test_validity_param_definitions.py | 20 ++++++------- 19 files changed, 52 insertions(+), 51 deletions(-) diff --git a/dbt_semantic_interfaces/implementations/semantic_model.py b/dbt_semantic_interfaces/implementations/semantic_model.py index 94862ae9..26a368ac 100644 --- a/dbt_semantic_interfaces/implementations/semantic_model.py +++ b/dbt_semantic_interfaces/implementations/semantic_model.py @@ -1,5 +1,6 @@ from __future__ import annotations +from dataclasses import Field from typing import Any, List, Optional, Sequence from pydantic import validator @@ -29,7 +30,7 @@ class NodeRelation(HashableBaseModel): """Path object to where the data should be.""" alias: str - schema_name: str + schema_name: str = Field(alias="schema") database: Optional[str] = None relation_name: str = "" @@ -41,7 +42,7 @@ def __create_default_relation_name(cls, value: Any, values: Any) -> str: # type # Only build the relation_name if it was not present in config. return value - alias, schema, database = values.get("alias"), values.get("schema_name"), values.get("database") + alias, schema, database = values.get("alias"), values.get("schema"), values.get("database") if alias is None or schema is None: raise ValueError( f"Failed to build relation_name because alias and/or schema was None. schema: {schema}, alias: {alias}" diff --git a/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json b/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json index 0a73a7df..3edc7bab 100644 --- a/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json +++ b/dbt_semantic_interfaces/parsing/generated_json_schemas/default_explicit_schema.json @@ -338,13 +338,13 @@ "relation_name": { "type": "string" }, - "schema_name": { + "schema": { "type": "string" } }, "required": [ "alias", - "schema_name" + "schema" ], "type": "object" }, diff --git a/dbt_semantic_interfaces/parsing/schemas.py b/dbt_semantic_interfaces/parsing/schemas.py index da07fdec..c18e5003 100644 --- a/dbt_semantic_interfaces/parsing/schemas.py +++ b/dbt_semantic_interfaces/parsing/schemas.py @@ -222,12 +222,12 @@ "type": "object", "properties": { "alias": {"type": "string"}, - "schema_name": {"type": "string"}, + "schema": {"type": "string"}, "database": {"type": "string"}, "relation_name": {"type": "string"}, }, "additionalProperties": False, - "required": ["alias", "schema_name"], + "required": ["alias", "schema"], } diff --git a/dbt_semantic_interfaces/test_utils.py b/dbt_semantic_interfaces/test_utils.py index 9051bcc2..d0d45284 100644 --- a/dbt_semantic_interfaces/test_utils.py +++ b/dbt_semantic_interfaces/test_utils.py @@ -84,7 +84,7 @@ def base_semantic_manifest_file() -> YamlConfigFile: semantic_model: name: sample_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/accounts_source.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/accounts_source.yaml index 35f40a3c..c375ec8b 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/accounts_source.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/accounts_source.yaml @@ -4,7 +4,7 @@ semantic_model: description: accounts_source node_relation: - schema_name: $source_schema + schema: $source_schema alias: fct_accounts defaults: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/bookings_source.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/bookings_source.yaml index 075b5ddc..21c8dd2d 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/bookings_source.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/bookings_source.yaml @@ -4,7 +4,7 @@ semantic_model: description: bookings_source node_relation: - schema_name: $source_schema + schema: $source_schema alias: fct_bookings defaults: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/companies.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/companies.yaml index 45c94111..0b7da7cd 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/companies.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/companies.yaml @@ -4,7 +4,7 @@ semantic_model: description: If a user is a company / business, this defines the mapping. node_relation: - schema_name: $source_schema + schema: $source_schema alias: dim_companies dimensions: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/id_verifications.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/id_verifications.yaml index e6303afe..aa48fb7a 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/id_verifications.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/id_verifications.yaml @@ -4,7 +4,7 @@ semantic_model: description: id_verifications node_relation: - schema_name: $source_schema + schema: $source_schema alias: fct_id_verifications defaults: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/listings_latest.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/listings_latest.yaml index c1480005..2b76756a 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/listings_latest.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/listings_latest.yaml @@ -4,7 +4,7 @@ semantic_model: description: listings_latest node_relation: - schema_name: $source_schema + schema: $source_schema alias: dim_listings_latest defaults: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/lux_listing_mapping.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/lux_listing_mapping.yaml index 30dd2ab6..211d72e4 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/lux_listing_mapping.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/lux_listing_mapping.yaml @@ -4,7 +4,7 @@ semantic_model: description: lux_listing_mapping node_relation: - schema_name: $source_schema + schema: $source_schema alias: dim_lux_listing_id_mapping entities: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/revenue.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/revenue.yaml index b8dd0dd8..a8011559 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/revenue.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/revenue.yaml @@ -4,7 +4,7 @@ semantic_model: description: revenue node_relation: - schema_name: $source_schema + schema: $source_schema alias: fct_revenue defaults: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/user_sm_source.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/user_sm_source.yaml index e44f9bcd..a3eefef7 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/user_sm_source.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/user_sm_source.yaml @@ -4,7 +4,7 @@ semantic_model: description: users_ds_source node_relation: - schema_name: $source_schema + schema: $source_schema alias: dim_users defaults: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/users_latest.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/users_latest.yaml index d85c37b4..3591d5b6 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/users_latest.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/users_latest.yaml @@ -4,7 +4,7 @@ semantic_model: description: users_latest node_relation: - schema_name: $source_schema + schema: $source_schema alias: dim_users_latest dimensions: diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/views_source.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/views_source.yaml index a6cafa9a..29af12f0 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/views_source.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/semantic_models/views_source.yaml @@ -4,7 +4,7 @@ semantic_model: description: views_source node_relation: - schema_name: $source_schema + schema: $source_schema alias: fct_views defaults: diff --git a/tests/parsing/test_semantic_model_parsing.py b/tests/parsing/test_semantic_model_parsing.py index 442e6444..0a47d25b 100644 --- a/tests/parsing/test_semantic_model_parsing.py +++ b/tests/parsing/test_semantic_model_parsing.py @@ -23,7 +23,7 @@ def test_semantic_model_metadata_parsing() -> None: name: metadata_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema """ ) file = YamlConfigFile(filepath="test_dir/inline_for_test", contents=yaml_contents) @@ -40,7 +40,7 @@ def test_semantic_model_metadata_parsing() -> None: name: metadata_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema """ ) assert semantic_model.metadata.file_slice.content == expected_metadata_content @@ -54,7 +54,7 @@ def test_semantic_model_node_relation_parsing() -> None: name: sql_table_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema """ ) file = YamlConfigFile(filepath="inline_for_test", contents=yaml_contents) @@ -74,7 +74,7 @@ def test_semantic_model_entity_parsing() -> None: name: entity_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema entities: - name: example_entity type: primary @@ -104,7 +104,7 @@ def test_semantic_model_entity_metadata_parsing() -> None: name: entity_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema entities: - name: example_entity type: primary @@ -140,7 +140,7 @@ def test_semantic_model_measure_parsing() -> None: name: measure_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema measures: - name: example_measure agg: count_distinct @@ -169,7 +169,7 @@ def test_semantic_model_measure_metadata_parsing() -> None: name: measure_metadata_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema measures: - name: example_measure_with_metadata agg: count_distinct @@ -205,7 +205,7 @@ def test_semantic_model_create_metric_measure_parsing() -> None: name: measure_parsing_create_metric_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema measures: - name: example_measure agg: count_distinct @@ -231,7 +231,7 @@ def test_semantic_model_categorical_dimension_parsing() -> None: name: dimension_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema dimensions: - name: example_categorical_dimension type: categorical @@ -259,7 +259,7 @@ def test_semantic_model_partition_dimension_parsing() -> None: name: dimension_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema dimensions: - name: example_categorical_dimension type: categorical @@ -285,7 +285,7 @@ def test_semantic_model_time_dimension_parsing() -> None: name: dimension_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema dimensions: - name: example_time_dimension type: time @@ -314,7 +314,7 @@ def test_semantic_model_primary_time_dimension_parsing() -> None: name: dimension_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema dimensions: - name: example_time_dimension type: time @@ -342,7 +342,7 @@ def test_semantic_model_dimension_metadata_parsing() -> None: name: dimension_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema dimensions: - name: example_categorical_dimension type: categorical @@ -378,7 +378,7 @@ def test_semantic_model_dimension_validity_params_parsing() -> None: name: scd_parsing_test node_relation: alias: source_table - schema_name: some_schema + schema: some_schema dimensions: - name: start_time_dimension type: time diff --git a/tests/validations/test_entities.py b/tests/validations/test_entities.py index da4e2d97..e43736cc 100644 --- a/tests/validations/test_entities.py +++ b/tests/validations/test_entities.py @@ -74,7 +74,7 @@ def test_multiple_natural_entities() -> None: semantic_model: name: too_many_natural_entities node_relation: - schema_name: some_schema + schema: some_schema alias: natural_entity_table entities: - name: natural_key_one @@ -116,7 +116,7 @@ def test_natural_entity_used_in_wrong_context() -> None: semantic_model: name: random_natural_entity node_relation: - schema_name: some_schema + schema: some_schema alias: random_natural_entity_table entities: - name: natural_key diff --git a/tests/validations/test_measures.py b/tests/validations/test_measures.py index d01bf3fc..86028e0d 100644 --- a/tests/validations/test_measures.py +++ b/tests/validations/test_measures.py @@ -70,7 +70,7 @@ def test_measures_only_exist_in_one_semantic_model() -> None: # noqa: D semantic_model: name: sample_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity @@ -111,7 +111,7 @@ def test_measures_only_exist_in_one_semantic_model() -> None: # noqa: D semantic_model: name: sample_semantic_model_2 node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity_2 @@ -157,7 +157,7 @@ def test_invalid_non_additive_dimension_properties() -> None: semantic_model: name: sample_semantic_model_2 node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity @@ -238,7 +238,7 @@ def test_count_measure_missing_expr() -> None: semantic_model: name: sample_semantic_model_2 node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity @@ -291,7 +291,7 @@ def test_count_measure_with_distinct_expr() -> None: semantic_model: name: sample_semantic_model_2 node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity @@ -342,7 +342,7 @@ def test_percentile_measure_missing_agg_params() -> None: semantic_model: name: sample_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity @@ -411,7 +411,7 @@ def test_percentile_measure_bad_percentile_values() -> None: semantic_model: name: sample_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: source_table entities: - name: example_entity diff --git a/tests/validations/test_semantic_models.py b/tests/validations/test_semantic_models.py index 5a7783e4..8ad99f69 100644 --- a/tests/validations/test_semantic_models.py +++ b/tests/validations/test_semantic_models.py @@ -52,7 +52,7 @@ def test_semantic_model_defaults_invalid() -> None: # noqa: D semantic_model: name: semantic_model_name node_relation: - schema_name: some_schema + schema: some_schema alias: some_alias defaults: agg_time_dimension: doesnotexist diff --git a/tests/validations/test_validity_param_definitions.py b/tests/validations/test_validity_param_definitions.py index 8ce82e7b..cd0d0439 100644 --- a/tests/validations/test_validity_param_definitions.py +++ b/tests/validations/test_validity_param_definitions.py @@ -31,7 +31,7 @@ def test_validity_window_configuration() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -75,7 +75,7 @@ def test_validity_window_must_have_a_start() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -109,7 +109,7 @@ def test_validity_window_must_have_an_end() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -146,7 +146,7 @@ def test_validity_window_uses_two_dimensions() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -183,7 +183,7 @@ def test_two_dimension_validity_windows_must_not_overload_start_and_end() -> Non semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -224,7 +224,7 @@ def test_multiple_validity_windows_are_invalid() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -276,7 +276,7 @@ def test_empty_validity_windows_are_invalid() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -320,7 +320,7 @@ def test_measures_are_prevented() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -367,7 +367,7 @@ def test_validity_window_must_have_a_natural_key() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_key @@ -412,7 +412,7 @@ def test_validity_window_does_not_use_primary_key() -> None: semantic_model: name: scd_semantic_model node_relation: - schema_name: some_schema + schema: some_schema alias: scd_table entities: - name: scd_primary_key From 802179be66b2fa61823552dd59b55e81ad710a9b Mon Sep 17 00:00:00 2001 From: Peter Allen Webb Date: Tue, 11 Jul 2023 10:42:51 -0400 Subject: [PATCH 2/2] Add changelog entry --- .changes/unreleased/Under the Hood-20230711-103558.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20230711-103558.yaml diff --git a/.changes/unreleased/Under the Hood-20230711-103558.yaml b/.changes/unreleased/Under the Hood-20230711-103558.yaml new file mode 100644 index 00000000..05f814a1 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20230711-103558.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Alias NodeRelation.schema_name to simply 'schema' +time: 2023-07-11T10:35:58.001941-04:00 +custom: + Author: peterallenwebb + Issue: "106"