Skip to content

Commit

Permalink
Update tests for input metric filter scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 18, 2024
1 parent a11108f commit 33c9852
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def test_derived_metric_with_defined_metric_time_filter(
)


@pytest.mark.skip("Not working yet.")
def test_derived_metric_with_defined_metric_time_filter_on_input_metric(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MetricFlowQuerySpec(
FilterSpecResolution(
lookup_key=ResolvedSpecLookUpKey(
filter_location=WhereFilterLocation(
location_type=METRIC,
metric_references=(
MetricReference(
element_name='simple_metric_with_time_granularity_and_metric_time_filter',
Expand All @@ -23,9 +24,6 @@ MetricFlowQuerySpec(
PydanticWhereFilter(
where_sql_template="{{ TimeDimension('metric_time') }} > '2020-01-01'\n",
),
PydanticWhereFilter(
where_sql_template="{{ TimeDimension('metric_time') }} = '2020-01-01'",
),
],
),
resolved_linkable_element_set=LinkableElementSet(
Expand Down Expand Up @@ -74,6 +72,75 @@ MetricFlowQuerySpec(
),
object_builder_str="TimeDimension('metric_time')",
),
FilterSpecResolution(
lookup_key=ResolvedSpecLookUpKey(
filter_location=WhereFilterLocation(
location_type=INPUT_METRIC,
metric_references=(
MetricReference(
element_name='simple_metric_with_time_granularity_and_metric_time_filter',
),
),
),
call_parameter_set=TimeDimensionCallParameterSet(
time_dimension_reference=TimeDimensionReference(
element_name='metric_time',
),
),
),
where_filter_intersection=PydanticWhereFilterIntersection(
where_filters=[
PydanticWhereFilter(
where_sql_template="{{ TimeDimension('metric_time') }} = '2020-01-01'\n",
),
],
),
resolved_linkable_element_set=LinkableElementSet(
path_key_to_linkable_dimensions={
ElementPathKey(
element_name='metric_time',
element_type=TIME_DIMENSION,
time_granularity=YEAR,
): (
LinkableDimension(
defined_in_semantic_model=SemanticModelReference(
semantic_model_name='monthly_measures_source',
),
element_name='metric_time',
dimension_type=TIME,
join_path=SemanticModelJoinPath(
left_semantic_model_reference=SemanticModelReference(
semantic_model_name='monthly_measures_source',
),
),
properties=frozenset(
'DERIVED_TIME_GRANULARITY',
'METRIC_TIME',
),
time_granularity=YEAR,
),
),
},
),
spec_pattern=TimeDimensionPattern(
parameter_set=EntityLinkPatternParameterSet(
fields_to_compare=(
DATE_PART,
ELEMENT_NAME,
ENTITY_LINKS,
),
element_name='metric_time',
),
),
filter_location_path=MetricFlowQueryResolutionPath(
resolution_path_nodes=(
QueryGroupByItemResolutionNode(node_id=qr_1),
MetricGroupByItemResolutionNode(node_id=mtr_1),
MetricGroupByItemResolutionNode(node_id=mtr_0),
),
),
object_builder_str="TimeDimension('metric_time')",
),
),
),
min_max_only=False,
Expand Down
12 changes: 12 additions & 0 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2215,3 +2215,15 @@ integration_test:
GROUP BY {{ render_date_trunc("ds", TimeGranularity.DAY) }}
) a ON b.ds = a.ds
WHERE {{ render_between_time_constraint("b.ds", "2020-01-03", "2020-01-03") }}
---
integration_test:
name: metric_time_filter_on_input_metric
description: Test a metric with a filter defined on its input metric.
model: SIMPLE_MODEL
metrics: ["bookings_dec_19_2019"]
check_query: |
SELECT
SUM(1) AS bookings_dec_19_2019
FROM {{ source_schema }}.fct_bookings
WHERE ({{ render_date_trunc("ds", TimeGranularity.DAY) }} < '2012-12-20')
AND ({{ render_date_trunc("ds", TimeGranularity.WEEK) }} > '2019-12-18')

0 comments on commit 33c9852

Please sign in to comment.