Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove error for date part with non-metric time dimension #813

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion metricflow/query/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,17 @@ 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 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,
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()
Expand Down
13 changes: 13 additions & 0 deletions metricflow/test/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down