Skip to content

Commit

Permalink
Update snapshots & test SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Nov 3, 2023
1 parent fab0350 commit 7aa4682
Show file tree
Hide file tree
Showing 31 changed files with 188 additions and 356 deletions.
4 changes: 2 additions & 2 deletions metricflow/dataflow/builder/dataflow_plan_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ def _build_metrics_output_node(
f"For {metric.type} metric: {metric_spec}, needed metrics are:\n"
f"{pformat_big_objects(metric_input_specs=metric_input_specs)}"
)

join_type = SqlJoinType.FULL_OUTER if metric.type is MetricType.DERIVED else SqlJoinType.INNER
compute_metrics_node = ComputeMetricsNode(
parent_node=self._build_metrics_output_node(
metric_specs=metric_input_specs,
queried_linkable_specs=queried_linkable_specs,
where_constraint=where_constraint,
time_range_constraint=time_range_constraint,
combine_metrics_join_type=SqlJoinType.FULL_OUTER if MetricType.DERIVED else SqlJoinType.INNER,
combine_metrics_join_type=join_type,
),
metric_specs=[metric_spec],
)
Expand Down
28 changes: 14 additions & 14 deletions metricflow/test/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ integration_test:
FROM {{source_schema}}.fct_bookings
GROUP BY ds
) b
JOIN (
FULL OUTER JOIN (
SELECT
SUM(1) AS views
, ds
Expand Down Expand Up @@ -519,7 +519,7 @@ integration_test:
GROUP BY
ds
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
SUM(1) AS lux_listings
, created_at AS metric_time__day
Expand Down Expand Up @@ -654,7 +654,7 @@ integration_test:
ON a.listing_id = b.listing_id
GROUP BY 2
) bk
INNER JOIN (
FULL OUTER JOIN (
SELECT
SUM(1) AS views
,d.is_lux
Expand Down Expand Up @@ -683,7 +683,7 @@ integration_test:
GROUP BY
metric_time__day
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
c.ds AS metric_time__day
, d.bookings_2_weeks_ago AS bookings_2_weeks_ago
Expand Down Expand Up @@ -718,7 +718,7 @@ integration_test:
GROUP BY
metric_time__day
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
c.ds AS metric_time__day
, d.bookings_at_start_of_month AS bookings_at_start_of_month
Expand Down Expand Up @@ -760,7 +760,7 @@ integration_test:
) f
ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
c.ds AS metric_time__day
, d.bookings AS month_start_bookings
Expand Down Expand Up @@ -808,7 +808,7 @@ integration_test:
check_query: |
SELECT
booking_value - instant_booking_value AS booking_value_sub_instant
, a.metric_time__day
, COALESCE(a.metric_time__day, b.metric_time__day) AS metric_time__day
FROM (
SELECT
SUM(booking_value) AS instant_booking_value
Expand All @@ -818,7 +818,7 @@ integration_test:
GROUP BY
ds
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
SUM(booking_value) AS booking_value
, ds AS metric_time__day
Expand All @@ -843,7 +843,7 @@ integration_test:
FROM (
SELECT
booking_value - instant_booking_value AS booking_value_sub_instant
, a.metric_time__day AS metric_time__day
, COALESCE(a.metric_time__day, b.metric_time__day) AS metric_time__day
FROM (
SELECT
SUM(booking_value) AS instant_booking_value
Expand All @@ -853,7 +853,7 @@ integration_test:
GROUP BY
ds
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
SUM(booking_value) AS booking_value
, ds AS metric_time__day
Expand Down Expand Up @@ -901,7 +901,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
GROUP BY metric_time__week
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
{{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} AS metric_time__week
, SUM(d.bookings_at_start_of_month) AS bookings_at_start_of_month
Expand Down Expand Up @@ -944,7 +944,7 @@ integration_test:
ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day
GROUP BY metric_time__year
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
{{ render_date_trunc("c.ds", TimeGranularity.YEAR) }} AS metric_time__year
, SUM(d.bookings) AS month_start_bookings
Expand Down Expand Up @@ -1024,7 +1024,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
GROUP BY metric_time__week, metric_time__month
) a
INNER JOIN (
FULL OUTER JOIN (
SELECT
{{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} AS metric_time__week
, {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} AS metric_time__month
Expand Down Expand Up @@ -1290,7 +1290,7 @@ integration_test:
) subq_3
ON subq_5.ds = subq_3.metric_time__day
) subq_7
INNER JOIN (
FULL OUTER JOIN (
SELECT
subq_11.ds AS metric_time__day
, SUM(subq_9.bookings) AS bookings_2_weeks_ago
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<CombineMetricsNode>
<!-- description = Combine Metrics -->
<!-- node_id = cbm_0 -->
<!-- join type = SqlJoinType.INNER -->
<!-- join type = SqlJoinType.FULL_OUTER -->
<!-- de-duplication method = post-join aggregation across all dimensions -->
<ComputeMetricsNode>
<!-- description = Compute Metrics via Expressions -->
<!-- node_id = cm_0 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<CombineMetricsNode>
<!-- description = Combine Metrics -->
<!-- node_id = cbm_0 -->
<!-- join type = SqlJoinType.INNER -->
<!-- join type = SqlJoinType.FULL_OUTER -->
<!-- de-duplication method = post-join aggregation across all dimensions -->
<ComputeMetricsNode>
<!-- description = Compute Metrics via Expressions -->
<!-- node_id = cm_0 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<CombineMetricsNode>
<!-- description = Combine Metrics -->
<!-- node_id = cbm_0 -->
<!-- join type = SqlJoinType.INNER -->
<!-- join type = SqlJoinType.FULL_OUTER -->
<!-- de-duplication method = post-join aggregation across all dimensions -->
<ComputeMetricsNode>
<!-- description = Compute Metrics via Expressions -->
<!-- node_id = cm_0 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM (
-- Combine Metrics
SELECT
COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day
, subq_4.ref_bookings AS ref_bookings
, subq_9.bookings AS bookings
, MAX(subq_4.ref_bookings) AS ref_bookings
, MAX(subq_9.bookings) AS bookings
FROM (
-- Compute Metrics via Expressions
SELECT
Expand Down Expand Up @@ -224,7 +224,7 @@ FROM (
subq_2.metric_time__day
) subq_3
) subq_4
INNER JOIN (
FULL OUTER JOIN (
-- Compute Metrics via Expressions
SELECT
subq_8.metric_time__day
Expand Down Expand Up @@ -441,13 +441,7 @@ FROM (
) subq_8
) subq_9
ON
(
subq_4.metric_time__day = subq_9.metric_time__day
) OR (
(
subq_4.metric_time__day IS NULL
) AND (
subq_9.metric_time__day IS NULL
)
)
subq_4.metric_time__day = subq_9.metric_time__day
GROUP BY
COALESCE(subq_4.metric_time__day, subq_9.metric_time__day)
) subq_10
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM (
-- Combine Metrics
SELECT
COALESCE(subq_15.metric_time__day, subq_20.metric_time__day) AS metric_time__day
, subq_15.ref_bookings AS ref_bookings
, subq_20.bookings AS bookings
, MAX(subq_15.ref_bookings) AS ref_bookings
, MAX(subq_20.bookings) AS bookings
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
Expand All @@ -27,7 +27,7 @@ FROM (
GROUP BY
metric_time__day
) subq_15
INNER JOIN (
FULL OUTER JOIN (
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
Expand All @@ -47,13 +47,7 @@ FROM (
metric_time__day
) subq_20
ON
(
subq_15.metric_time__day = subq_20.metric_time__day
) OR (
(
subq_15.metric_time__day IS NULL
) AND (
subq_20.metric_time__day IS NULL
)
)
subq_15.metric_time__day = subq_20.metric_time__day
GROUP BY
COALESCE(subq_15.metric_time__day, subq_20.metric_time__day)
) subq_21
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM (
-- Combine Metrics
SELECT
COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day
, subq_4.bookings AS bookings
, subq_12.bookings_at_start_of_month AS bookings_at_start_of_month
, MAX(subq_4.bookings) AS bookings
, MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month
FROM (
-- Compute Metrics via Expressions
SELECT
Expand Down Expand Up @@ -224,7 +224,7 @@ FROM (
subq_2.metric_time__day
) subq_3
) subq_4
INNER JOIN (
FULL OUTER JOIN (
-- Compute Metrics via Expressions
SELECT
subq_11.metric_time__day
Expand Down Expand Up @@ -541,13 +541,7 @@ FROM (
) subq_11
) subq_12
ON
(
subq_4.metric_time__day = subq_12.metric_time__day
) OR (
(
subq_4.metric_time__day IS NULL
) AND (
subq_12.metric_time__day IS NULL
)
)
subq_4.metric_time__day = subq_12.metric_time__day
GROUP BY
COALESCE(subq_4.metric_time__day, subq_12.metric_time__day)
) subq_13
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM (
-- Combine Metrics
SELECT
COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day
, subq_18.bookings AS bookings
, subq_26.bookings_at_start_of_month AS bookings_at_start_of_month
, MAX(subq_18.bookings) AS bookings
, MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
Expand All @@ -27,7 +27,7 @@ FROM (
GROUP BY
metric_time__day
) subq_18
INNER JOIN (
FULL OUTER JOIN (
-- Join to Time Spine Dataset
-- Pass Only Elements:
-- ['bookings', 'metric_time__day']
Expand All @@ -51,13 +51,7 @@ FROM (
subq_22.ds
) subq_26
ON
(
subq_18.metric_time__day = subq_26.metric_time__day
) OR (
(
subq_18.metric_time__day IS NULL
) AND (
subq_26.metric_time__day IS NULL
)
)
subq_18.metric_time__day = subq_26.metric_time__day
GROUP BY
COALESCE(subq_18.metric_time__day, subq_26.metric_time__day)
) subq_27
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM (
-- Combine Metrics
SELECT
COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) AS metric_time__week
, subq_4.bookings AS bookings
, subq_12.bookings_at_start_of_month AS bookings_at_start_of_month
, MAX(subq_4.bookings) AS bookings
, MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month
FROM (
-- Compute Metrics via Expressions
SELECT
Expand Down Expand Up @@ -224,7 +224,7 @@ FROM (
subq_2.metric_time__week
) subq_3
) subq_4
INNER JOIN (
FULL OUTER JOIN (
-- Compute Metrics via Expressions
SELECT
subq_11.metric_time__week
Expand Down Expand Up @@ -542,13 +542,7 @@ FROM (
) subq_11
) subq_12
ON
(
subq_4.metric_time__week = subq_12.metric_time__week
) OR (
(
subq_4.metric_time__week IS NULL
) AND (
subq_12.metric_time__week IS NULL
)
)
subq_4.metric_time__week = subq_12.metric_time__week
GROUP BY
COALESCE(subq_4.metric_time__week, subq_12.metric_time__week)
) subq_13
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM (
-- Combine Metrics
SELECT
COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) AS metric_time__week
, subq_18.bookings AS bookings
, subq_26.bookings_at_start_of_month AS bookings_at_start_of_month
, MAX(subq_18.bookings) AS bookings
, MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month
FROM (
-- Aggregate Measures
-- Compute Metrics via Expressions
Expand All @@ -27,7 +27,7 @@ FROM (
GROUP BY
metric_time__week
) subq_18
INNER JOIN (
FULL OUTER JOIN (
-- Join to Time Spine Dataset
-- Pass Only Elements:
-- ['bookings', 'metric_time__week']
Expand All @@ -52,13 +52,7 @@ FROM (
DATE_TRUNC('week', subq_22.ds)
) subq_26
ON
(
subq_18.metric_time__week = subq_26.metric_time__week
) OR (
(
subq_18.metric_time__week IS NULL
) AND (
subq_26.metric_time__week IS NULL
)
)
subq_18.metric_time__week = subq_26.metric_time__week
GROUP BY
COALESCE(subq_18.metric_time__week, subq_26.metric_time__week)
) subq_27
Loading

0 comments on commit 7aa4682

Please sign in to comment.