Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 18, 2024
1 parent 099ea5a commit 5c31d3a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ metric:
type: derived
time_granularity: year
type_params:
expr: simple_metric_with_time_granularity_and_metric_time_filter * 2
expr: simple_metric_with_time_granularity * 2
metrics:
- name: simple_metric_with_time_granularity_and_metric_time_filter
- name: simple_metric_with_time_granularity
filter: |
{{ TimeDimension('metric_time') }} = '2020-01-01'
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,14 @@ metric:
name: listings
filter: "{{ Metric('views', ['listing']) }} > 10"
time_granularity: week
---
metric:
name: bookings_starting_2020
description: Bookings starting in 2020. Used to test a metric with an ambiguous filter in on its input metric.
type: derived
type_params:
expr: bookings
metrics:
- name: bookings
filter: "{{ TimeDimension('metric_time') }} >= '2020-01-01'"
time_granularity: week
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_derived_metric_with_defined_metric_time_filter_on_input_metric(
query_spec = ambiguous_resolution_query_parser.parse_and_validate_query(
metric_names=["derived_metric_with_time_granularity_and_inner_metric_time_filter"]
).query_spec
assert 0, "this don't werk"

assert_object_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MetricFlowQuerySpec(
filter_location=WhereFilterLocation(
metric_references=(
MetricReference(
element_name='simple_metric_with_time_granularity_and_metric_time_filter',
element_name='simple_metric_with_time_granularity',
),
),
),
Expand All @@ -21,10 +21,7 @@ MetricFlowQuerySpec(
where_filter_intersection=PydanticWhereFilterIntersection(
where_filters=[
PydanticWhereFilter(
where_sql_template="{{ TimeDimension('metric_time') }} > '2020-01-01'\n",
),
PydanticWhereFilter(
where_sql_template="{{ TimeDimension('metric_time') }} = '2020-01-01'",
where_sql_template="{{ TimeDimension('metric_time') }} = '2020-01-01'\n",
),
],
),
Expand All @@ -33,7 +30,7 @@ MetricFlowQuerySpec(
ElementPathKey(
element_name='metric_time',
element_type=TIME_DIMENSION,
time_granularity=QUARTER,
time_granularity=YEAR,
): (
LinkableDimension(
defined_in_semantic_model=SemanticModelReference(
Expand All @@ -50,7 +47,7 @@ MetricFlowQuerySpec(
'DERIVED_TIME_GRANULARITY',
'METRIC_TIME',
),
time_granularity=QUARTER,
time_granularity=YEAR,
),
),
},
Expand Down
11 changes: 11 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,14 @@ 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_starting_2020"]
check_query: |
SELECT
SUM(1) AS bookings_starting_2020
FROM {{ source_schema }}.fct_bookings
WHERE {{ render_date_trunc("ds", TimeGranularity.WEEK) }} >= '2020-01-01'

0 comments on commit 5c31d3a

Please sign in to comment.