Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Oct 25, 2024
1 parent 29e2ab6 commit 403773c
Show file tree
Hide file tree
Showing 15 changed files with 3,808 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,31 @@ def test_conversion_metric_with_filter(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=parsed_query.query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_conversion_metric_with_filter_not_in_group_by(
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_conversions",),
where_constraints=(
PydanticWhereFilter(where_sql_template=("{{ Dimension('visit__referrer_id') }} = 'ref_id_01'")),
),
)

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
-- Combine Aggregated Outputs
-- Compute Metrics via Expressions
SELECT
COALESCE(MAX(subq_34.buys), 0) AS visit_buy_conversions
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits',]
-- Aggregate Measures
SELECT
SUM(visits) AS visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['visits', 'visit__referrer_id']
SELECT
referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_20
WHERE visit__referrer_id = 'ref_id_01'
) subq_23
CROSS JOIN (
-- Find conversions for user within the range of 7 day
-- Pass Only Elements: ['buys',]
-- Aggregate Measures
SELECT
SUM(buys) AS buys
FROM (
-- Dedupe the fanout with mf_internal_uuid in the conversion data set
SELECT DISTINCT
FIRST_VALUE(subq_27.visits) OVER (
PARTITION BY
subq_30.user
, subq_30.ds__day
, subq_30.mf_internal_uuid
ORDER BY subq_27.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visits
, FIRST_VALUE(subq_27.visit__referrer_id) OVER (
PARTITION BY
subq_30.user
, subq_30.ds__day
, subq_30.mf_internal_uuid
ORDER BY subq_27.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS visit__referrer_id
, FIRST_VALUE(subq_27.ds__day) OVER (
PARTITION BY
subq_30.user
, subq_30.ds__day
, subq_30.mf_internal_uuid
ORDER BY subq_27.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__day
, FIRST_VALUE(subq_27.user) OVER (
PARTITION BY
subq_30.user
, subq_30.ds__day
, subq_30.mf_internal_uuid
ORDER BY subq_27.ds__day DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS user
, subq_30.mf_internal_uuid AS mf_internal_uuid
, subq_30.buys AS buys
FROM (
-- Constrain Output with WHERE
-- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user']
SELECT
ds__day
, subq_25.user
, visit__referrer_id
, visits
FROM (
-- Read Elements From Semantic Model 'visits_source'
-- Metric Time Dimension 'ds'
SELECT
DATETIME_TRUNC(ds, day) AS ds__day
, user_id AS user
, referrer_id AS visit__referrer_id
, 1 AS visits
FROM ***************************.fct_visits visits_source_src_28000
) subq_25
WHERE visit__referrer_id = 'ref_id_01'
) subq_27
INNER JOIN (
-- Read Elements From Semantic Model 'buys_source'
-- Metric Time Dimension 'ds'
-- Add column with generated UUID
SELECT
DATETIME_TRUNC(ds, day) AS ds__day
, user_id AS user
, 1 AS buys
, GENERATE_UUID() AS mf_internal_uuid
FROM ***************************.fct_buys buys_source_src_28000
) subq_30
ON
(
subq_27.user = subq_30.user
) AND (
(
subq_27.ds__day <= subq_30.ds__day
) AND (
subq_27.ds__day > DATE_SUB(CAST(subq_30.ds__day AS DATETIME), INTERVAL 7 day)
)
)
) subq_31
) subq_34
Loading

0 comments on commit 403773c

Please sign in to comment.