From 85d9c6282e1e778ea38c1c6603b6303d8162a9fe Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 1 Oct 2024 13:03:57 -0700 Subject: [PATCH 1/3] Bug fix: case-sensitive validation warning for filter granularity --- dbt_semantic_interfaces/validations/metrics.py | 4 ++-- .../simple_semantic_manifest/saved_queries.yaml | 4 ++-- tests/parsing/test_object_builder_item_description.py | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dbt_semantic_interfaces/validations/metrics.py b/dbt_semantic_interfaces/validations/metrics.py index 3ef10e37..41649c2d 100644 --- a/dbt_semantic_interfaces/validations/metrics.py +++ b/dbt_semantic_interfaces/validations/metrics.py @@ -273,13 +273,13 @@ def _validate_time_granularity_names( issues: List[ValidationIssue] = [] valid_granularity_names = [ - standard_granularity.name for standard_granularity in TimeGranularity + standard_granularity.value for standard_granularity in TimeGranularity ] + custom_granularity_names for _, parameter_set in filter_expression_parameter_sets: for time_dim_call_parameter_set in parameter_set.time_dimension_call_parameter_sets: if not time_dim_call_parameter_set.time_granularity_name: continue - if time_dim_call_parameter_set.time_granularity_name not in valid_granularity_names: + if time_dim_call_parameter_set.time_granularity_name.lower() not in valid_granularity_names: issues.append( ValidationWarning( context=context, diff --git a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml index a8fa65ec..36af31d6 100644 --- a/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml +++ b/tests/fixtures/semantic_manifest_yamls/simple_semantic_manifest/saved_queries.yaml @@ -25,12 +25,12 @@ saved_query: metrics: - listings group_by: - - TimeDimension('metric_time', 'DAY') + - TimeDimension('metric_time', 'day') where: - "{{ Metric('bookings', group_by=['listing', 'metric_time']) }} > 5" order_by: - Metric('listings').descending(True) - - TimeDimension('metric_time', 'DAY') + - TimeDimension('metric_time', 'day') limit: 10 exports: diff --git a/tests/parsing/test_object_builder_item_description.py b/tests/parsing/test_object_builder_item_description.py index 10ef925e..ec28b624 100644 --- a/tests/parsing/test_object_builder_item_description.py +++ b/tests/parsing/test_object_builder_item_description.py @@ -24,6 +24,8 @@ def test_valid_object_builder_items() -> None: # noqa: D "Entity('listing__created_at', entity_path=['host'])", "Metric('bookings', group_by=['listing__created_at'])", "TimeDimension('metric_time', time_granularity_name='martian_year')", + "TimeDimension('metric_time', time_granularity_name='month')", + "TimeDimension('metric_time', time_granularity_name='MONTH')", ) for valid_item in valid_items: logger.info(f"Checking {valid_item=}") From b4d2e3acb2832fa94afcdd0eb15134ddf3981567 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 1 Oct 2024 13:04:25 -0700 Subject: [PATCH 2/3] Bump prod version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 97553646..2fc2a9af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dbt-semantic-interfaces" -version = "0.7.2" +version = "0.7.3" description = 'The shared semantic layer definitions that dbt-core and MetricFlow use' readme = "README.md" requires-python = ">=3.8" From 05bdd3d0b985e26dd1967f1b4100dc47fa8bf206 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 1 Oct 2024 13:07:12 -0700 Subject: [PATCH 3/3] One more test --- tests/validations/test_metrics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/validations/test_metrics.py b/tests/validations/test_metrics.py index eba08083..5439331f 100644 --- a/tests/validations/test_metrics.py +++ b/tests/validations/test_metrics.py @@ -469,7 +469,11 @@ def test_where_filter_validations_invalid_granularity( # noqa: D assert metric.type_params.metrics is not None input_metric = metric.type_params.metrics[0] input_metric.filter = PydanticWhereFilterIntersection( - where_filters=[PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'cool') }}")] + where_filters=[ + PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'cool') }}"), + PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'month') }}"), + PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'MONTH') }}"), + ] ) validator = SemanticManifestValidator[PydanticSemanticManifest]([WhereFiltersAreParseable()]) issues = validator.validate_semantic_manifest(manifest)