From 61db5525b70be8834b5680ce46a8e8d5f69cf57b Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 16 Oct 2023 17:38:17 -0700 Subject: [PATCH 1/3] Remove error for date part with non-metric time dimension --- metricflow/query/query_parser.py | 2 ++ .../test/integration/test_cases/itest_metrics.yaml | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/metricflow/query/query_parser.py b/metricflow/query/query_parser.py index 95607e63ea..7fe1fc7eae 100644 --- a/metricflow/query/query_parser.py +++ b/metricflow/query/query_parser.py @@ -816,6 +816,8 @@ def _get_invalid_linkable_specs( # Because the metric time dimension is a virtual dimension that's not in the model, it won't be included # in valid_linkable_specs. and time_dimension_spec.reference != DataSet.metric_time_dimension_reference() + # TODO: remove line below & add date_part specs to validation paths. + and not time_dimension_spec.date_part ): invalid_linkable_specs.append(time_dimension_spec) diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml index d88ed9d83c..6e1205f1c4 100644 --- a/metricflow/test/integration/test_cases/itest_metrics.yaml +++ b/metricflow/test/integration/test_cases/itest_metrics.yaml @@ -1057,6 +1057,19 @@ integration_test: FROM {{ source_schema }}.fct_bookings GROUP BY {{ render_extract("ds", DatePart.YEAR) }}; --- +integration_test: + name: simple_query_with_date_part_not_metric_time + description: Test query using date_part + model: SIMPLE_MODEL + metrics: ["bookings"] + group_by_objs: [{"name": "booking__ds", "date_part": "year"}] + check_query: | + SELECT + SUM(1) AS bookings + , {{ render_extract("ds", DatePart.YEAR) }} AS booking__ds__extract_year + FROM {{ source_schema }}.fct_bookings + GROUP BY {{ render_extract("ds", DatePart.YEAR) }}; +--- integration_test: name: simple_query_with_multiple_date_parts description: Test query using multiple date_parts From d4f77494cadbe8ffd0d50d183dfe51a812fc2c69 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 16 Oct 2023 17:52:53 -0700 Subject: [PATCH 2/3] Still verify everything except date part --- metricflow/query/query_parser.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/metricflow/query/query_parser.py b/metricflow/query/query_parser.py index 7fe1fc7eae..16f3029a74 100644 --- a/metricflow/query/query_parser.py +++ b/metricflow/query/query_parser.py @@ -811,13 +811,20 @@ def _get_invalid_linkable_specs( invalid_linkable_specs.append(entity_spec) for time_dimension_spec in time_dimension_specs: + time_dimension_spec_without_date_part = time_dimension_spec + if time_dimension_spec.date_part: + # TODO: remove line below & add date_part specs to validation paths. + time_dimension_spec_without_date_part = TimeDimensionSpec( + element_name=time_dimension_spec.element_name, + entity_links=time_dimension_spec.entity_links, + time_granularity=time_dimension_spec.time_granularity, + aggregation_state=time_dimension_spec.aggregation_state, + ) if ( - time_dimension_spec not in valid_linkable_specs + time_dimension_spec_without_date_part not in valid_linkable_specs # Because the metric time dimension is a virtual dimension that's not in the model, it won't be included # in valid_linkable_specs. and time_dimension_spec.reference != DataSet.metric_time_dimension_reference() - # TODO: remove line below & add date_part specs to validation paths. - and not time_dimension_spec.date_part ): invalid_linkable_specs.append(time_dimension_spec) From afb25c06905c49efa936b9d266af8dd19cc48a9a Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 16 Oct 2023 17:55:58 -0700 Subject: [PATCH 3/3] Update comment --- metricflow/query/query_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metricflow/query/query_parser.py b/metricflow/query/query_parser.py index 16f3029a74..fab4a80734 100644 --- a/metricflow/query/query_parser.py +++ b/metricflow/query/query_parser.py @@ -813,7 +813,7 @@ def _get_invalid_linkable_specs( for time_dimension_spec in time_dimension_specs: time_dimension_spec_without_date_part = time_dimension_spec if time_dimension_spec.date_part: - # TODO: remove line below & add date_part specs to validation paths. + # TODO: remove this workaround & add date_part specs to validation paths. time_dimension_spec_without_date_part = TimeDimensionSpec( element_name=time_dimension_spec.element_name, entity_links=time_dimension_spec.entity_links,