Skip to content

Commit

Permalink
Add new SQL rendering tests
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Oct 16, 2024
1 parent 62e9b85 commit 1477c7e
Show file tree
Hide file tree
Showing 14 changed files with 1,534 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,17 @@ metric:
filter: "{{ Dimension('booking__is_instant') }}"
filter: "{{ Entity('listing') }} IS NOT NULL"
---
metric:
name: bookings_join_to_time_spine_with_tiered_filters
description: simple metric that joins to timespine and has metric_time filters at both the measure and metric level
type: simple
type_params:
measure:
name: bookings
join_to_timespine: true
filter: "{{ TimeDimension('metric_time', 'day') }} >= '2020-01-02'"
filter: "{{ TimeDimension('metric_time', 'day') }} <= '2020-01-02'"
---
metric:
name: every_two_days_bookers_fill_nulls_with_0
description: cumulative metric filling 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@ metric:
measure:
name: archived_users
time_granularity: hour
---
metric:
name: archived_users_join_to_time_spine
description: subdaily metric joining to time spine
type: simple
type_params:
measure:
name: archived_users
join_to_timespine: true
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'listing__booking__listing__bookings_fill_nulls_with_0',
'listing__booking__listing__bookings_fill_nulls_with_0_without_time_spine',
'listing__booking__listing__bookings_join_to_time_spine',
'listing__booking__listing__bookings_join_to_time_spine_with_tiered_filters',
'listing__booking__listing__bookings_per_booker',
'listing__booking__listing__bookings_per_dollar',
'listing__booking__listing__derived_bookings_0',
Expand Down Expand Up @@ -58,6 +59,7 @@
'listing__bookings_fill_nulls_with_0',
'listing__bookings_fill_nulls_with_0_without_time_spine',
'listing__bookings_join_to_time_spine',
'listing__bookings_join_to_time_spine_with_tiered_filters',
'listing__bookings_per_booker',
'listing__bookings_per_dollar',
'listing__bookings_per_listing',
Expand Down Expand Up @@ -194,6 +196,7 @@
'user__archived_at__week',
'user__archived_at__year',
'user__archived_users',
'user__archived_users_join_to_time_spine',
'user__bio_added_ts__day',
'user__bio_added_ts__extract_day',
'user__bio_added_ts__extract_day',
Expand Down Expand Up @@ -430,6 +433,7 @@
'user__listing__user__bookings_fill_nulls_with_0',
'user__listing__user__bookings_fill_nulls_with_0_without_time_spine',
'user__listing__user__bookings_join_to_time_spine',
'user__listing__user__bookings_join_to_time_spine_with_tiered_filters',
'user__listing__user__bookings_per_booker',
'user__listing__user__bookings_per_dollar',
'user__listing__user__bookings_per_listing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Model Join-Path Entity Links
('listings_latest',) ("('listing',)", "('booking', 'listing')") bookings_fill_nulls_with_0 ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('booking', 'listing')") bookings_fill_nulls_with_0_without_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('booking', 'listing')") bookings_join_to_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('booking', 'listing')") bookings_join_to_time_spine_with_tiered_filters ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('booking', 'listing')") bookings_per_booker ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('booking', 'listing')") bookings_per_dollar ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('booking', 'listing')") derived_bookings_0 ['JOINED', 'METRIC']
Expand Down Expand Up @@ -82,6 +83,7 @@ Model Join-Path Entity Links
('listings_latest',) ("('listing',)", "('listing',)") bookings_fill_nulls_with_0 ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('listing',)") bookings_fill_nulls_with_0_without_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('listing',)") bookings_join_to_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('listing',)") bookings_join_to_time_spine_with_tiered_filters ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('listing',)") bookings_per_booker ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('listing',)") bookings_per_dollar ['JOINED', 'METRIC']
('listings_latest',) ("('listing',)", "('listing',)") bookings_per_listing ['JOINED', 'METRIC']
Expand Down Expand Up @@ -143,6 +145,7 @@ Model Join-Path Entity Links
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_fill_nulls_with_0 ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_fill_nulls_with_0_without_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_join_to_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_join_to_time_spine_with_tiered_filters ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_per_booker ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_per_dollar ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('listing', 'user')") bookings_per_listing ['JOINED', 'METRIC']
Expand Down Expand Up @@ -183,6 +186,7 @@ Model Join-Path Entity Links
('listings_latest',) ("('user',)", "('revenue_instance', 'user')") revenue_all_time ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") active_listings ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") archived_users ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") archived_users_join_to_time_spine ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") current_account_balance_by_user ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") identity_verifications ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") largest_listing ['JOINED', 'METRIC']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'company__listing__user__company__bookings_fill_nulls_with_0',
'company__listing__user__company__bookings_fill_nulls_with_0_without_time_spine',
'company__listing__user__company__bookings_join_to_time_spine',
'company__listing__user__company__bookings_join_to_time_spine_with_tiered_filters',
'company__listing__user__company__bookings_per_booker',
'company__listing__user__company__bookings_per_dollar',
'company__listing__user__company__bookings_per_view',
Expand Down Expand Up @@ -94,6 +95,7 @@
'company__user',
'company__user__company__active_listings',
'company__user__company__archived_users',
'company__user__company__archived_users_join_to_time_spine',
'company__user__company__current_account_balance_by_user',
'company__user__company__identity_verifications',
'company__user__company__largest_listing',
Expand Down Expand Up @@ -139,6 +141,7 @@
'guest__booking__guest__bookings_fill_nulls_with_0',
'guest__booking__guest__bookings_fill_nulls_with_0_without_time_spine',
'guest__booking__guest__bookings_join_to_time_spine',
'guest__booking__guest__bookings_join_to_time_spine_with_tiered_filters',
'guest__booking__guest__bookings_per_booker',
'guest__booking__guest__bookings_per_dollar',
'guest__booking__guest__derived_bookings_0',
Expand Down Expand Up @@ -173,6 +176,7 @@
'guest__bookings_fill_nulls_with_0',
'guest__bookings_fill_nulls_with_0_without_time_spine',
'guest__bookings_join_to_time_spine',
'guest__bookings_join_to_time_spine_with_tiered_filters',
'guest__bookings_per_booker',
'guest__bookings_per_dollar',
'guest__derived_bookings_0',
Expand Down Expand Up @@ -218,6 +222,7 @@
'host__booking__host__bookings_fill_nulls_with_0',
'host__booking__host__bookings_fill_nulls_with_0_without_time_spine',
'host__booking__host__bookings_join_to_time_spine',
'host__booking__host__bookings_join_to_time_spine_with_tiered_filters',
'host__booking__host__bookings_per_booker',
'host__booking__host__bookings_per_dollar',
'host__booking__host__derived_bookings_0',
Expand Down Expand Up @@ -252,6 +257,7 @@
'host__bookings_fill_nulls_with_0',
'host__bookings_fill_nulls_with_0_without_time_spine',
'host__bookings_join_to_time_spine',
'host__bookings_join_to_time_spine_with_tiered_filters',
'host__bookings_per_booker',
'host__bookings_per_dollar',
'host__derived_bookings_0',
Expand Down Expand Up @@ -298,6 +304,7 @@
'listing__booking__listing__bookings_fill_nulls_with_0',
'listing__booking__listing__bookings_fill_nulls_with_0_without_time_spine',
'listing__booking__listing__bookings_join_to_time_spine',
'listing__booking__listing__bookings_join_to_time_spine_with_tiered_filters',
'listing__booking__listing__bookings_per_booker',
'listing__booking__listing__bookings_per_dollar',
'listing__booking__listing__derived_bookings_0',
Expand Down Expand Up @@ -333,6 +340,7 @@
'listing__bookings_fill_nulls_with_0',
'listing__bookings_fill_nulls_with_0_without_time_spine',
'listing__bookings_join_to_time_spine',
'listing__bookings_join_to_time_spine_with_tiered_filters',
'listing__bookings_per_booker',
'listing__bookings_per_dollar',
'listing__bookings_per_listing',
Expand Down Expand Up @@ -405,6 +413,7 @@
'lux_listing__listing__lux_listing__bookings_fill_nulls_with_0',
'lux_listing__listing__lux_listing__bookings_fill_nulls_with_0_without_time_spine',
'lux_listing__listing__lux_listing__bookings_join_to_time_spine',
'lux_listing__listing__lux_listing__bookings_join_to_time_spine_with_tiered_filters',
'lux_listing__listing__lux_listing__bookings_per_booker',
'lux_listing__listing__lux_listing__bookings_per_dollar',
'lux_listing__listing__lux_listing__bookings_per_listing',
Expand Down Expand Up @@ -471,6 +480,7 @@
'user__archived_at__extract_year',
'user__archived_at__hour',
'user__archived_users',
'user__archived_users_join_to_time_spine',
'user__bio_added_ts__extract_day',
'user__bio_added_ts__extract_dow',
'user__bio_added_ts__extract_doy',
Expand Down Expand Up @@ -546,6 +556,7 @@
'user__listing__user__bookings_fill_nulls_with_0',
'user__listing__user__bookings_fill_nulls_with_0_without_time_spine',
'user__listing__user__bookings_join_to_time_spine',
'user__listing__user__bookings_join_to_time_spine_with_tiered_filters',
'user__listing__user__bookings_per_booker',
'user__listing__user__bookings_per_dollar',
'user__listing__user__bookings_per_listing',
Expand Down
111 changes: 111 additions & 0 deletions tests_metricflow/query_rendering/test_fill_nulls_with_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,114 @@ def test_join_to_time_spine_with_filters( # noqa: D103
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_join_to_time_spine_with_filter_not_in_group_by( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
) -> None:
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings_join_to_time_spine_with_tiered_filters",),
group_by_names=("metric_time__day",),
where_constraints=[
PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'month') }} > '2020-01-01'")
],
).query_spec

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=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_join_to_time_spine_with_filter_smaller_than_group_by( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
) -> None:
query_spec = query_parser.parse_and_validate_query(
metric_names=("archived_users_join_to_time_spine",),
group_by_names=("metric_time__day",),
where_constraints=[
PydanticWhereFilter(
where_sql_template="{{ TimeDimension('metric_time', 'hour') }} > '2020-01-01 00:09:00'"
),
PydanticWhereFilter(where_sql_template="{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'"),
],
).query_spec

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=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
) -> None:
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings_join_to_time_spine_with_tiered_filters",),
group_by_names=("booking__ds__day",),
where_constraints=[
PydanticWhereFilter(where_sql_template="{{ TimeDimension('booking__ds', 'month') }} > '2020-01-01'")
],
).query_spec

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=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
) -> None:
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings_join_to_time_spine_with_tiered_filters",),
group_by_names=("metric_time__day",),
where_constraints=[
PydanticWhereFilter(where_sql_template="{{ TimeDimension('booking__ds', 'month') }} > '2020-01-01'")
],
).query_spec

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=query_spec,
)
Loading

0 comments on commit 1477c7e

Please sign in to comment.