Skip to content

Commit

Permalink
added test for different grains
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Oct 30, 2024
1 parent df85853 commit e1cc8f4
Show file tree
Hide file tree
Showing 6 changed files with 525 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,18 @@ metric:
entity: user
calculation: conversions
---
metric:
name: visit_buy_conversion_rate_with_monthly_conversion
description: conversion rate on visits-buys_month
type: conversion
type_params:
conversion_type_params:
base_measure: visits
conversion_measure: buys_month
entity: user
calculation: conversion_rate
window: 1 month
---
metric:
name: visit_buy_conversion_rate_by_session
description: conversion rate on visits-buys on a 7 day window held by a constant session_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ semantic_model:
- name: buys
expr: 1
agg: count
- name: buys_month
expr: 1
agg: count
agg_time_dimension: ds_month
- name: buyers
expr: user_id
agg: count_distinct
Expand All @@ -23,6 +27,10 @@ semantic_model:
type: time
type_params:
time_granularity: day
- name: ds_month
type: time
type_params:
time_granularity: month

primary_entity: buy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ table_snapshot:
column_definitions:
- name: ds
type: TIME
- name: ds_month
type: TIME
- name: user_id
type: STRING
- name: session_id
type: STRING
rows:
- ["2020-01-02", "u0004114", "s1"]
- ["2020-01-03", "u0042324", "s9"]
- ["2020-01-04", "u0005432", "s6"]
- ["2020-01-04", "u0003452", "s7"]
- ["2020-01-07", "u1612112", "s123"]
- ["2020-01-07", "u0004114", "s14"]
- ["2020-01-07", "u0003141", "s3"]
- ["2020-01-10", "u0004117", "s15"]
- ["2020-01-02", "2020-01-01", "u0004114", "s1"]
- ["2020-01-03", "2020-01-01", "u0042324", "s9"]
- ["2020-01-04", "2020-01-01", "u0005432", "s6"]
- ["2020-01-04", "2020-01-01", "u0003452", "s7"]
- ["2020-01-07", "2020-01-01", "u1612112", "s123"]
- ["2020-01-07", "2020-01-01", "u0004114", "s14"]
- ["2020-01-07", "2020-01-01", "u0003141", "s3"]
- ["2020-01-10", "2020-01-01", "u0004117", "s15"]
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,28 @@ def test_conversion_metric_with_filter_not_in_group_by(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=parsed_query.query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_conversion_metric_with_different_time_dimension_grains(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
create_source_tables: bool,
) -> None:
"""Test rendering a query against a conversion metric."""
parsed_query = query_parser.parse_and_validate_query(
metric_names=("visit_buy_conversion_rate_with_monthly_conversion",),
)

render_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=dataflow_to_sql_converter,
sql_client=sql_client,
dataflow_plan_builder=dataflow_plan_builder,
query_spec=parsed_query.query_spec,
)
Loading

0 comments on commit e1cc8f4

Please sign in to comment.