Skip to content

Commit

Permalink
Update test cases for trailing_2_months_revenue
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jan 24, 2024
1 parent 645227e commit 0e4820a
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def test_cumulative_metric_with_window( # noqa: D
MetricFlowQuerySpec(
metric_specs=(MetricSpec(element_name="trailing_2_months_revenue"),),
dimension_specs=(),
time_dimension_specs=(MTD_SPEC_MONTH,),
time_dimension_specs=(MTD_SPEC_DAY,),
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_cumulative_metric(
TimeDimensionSpec(
element_name="ds",
entity_links=(),
time_granularity=TimeGranularity.MONTH,
time_granularity=TimeGranularity.DAY,
),
),
)
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_cumulative_metric_with_time_constraint(
TimeDimensionSpec(
element_name="metric_time",
entity_links=(),
time_granularity=TimeGranularity.MONTH,
time_granularity=TimeGranularity.DAY,
),
),
time_range_constraint=TimeRangeConstraint(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- Compute Metrics via Expressions
SELECT
subq_3.ds__month
subq_3.ds__day
, subq_3.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_2.ds__month
subq_2.ds__day
, SUM(subq_2.txn_revenue) AS txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
SELECT
subq_1.ds__month
subq_1.ds__day
, subq_1.txn_revenue
FROM (
-- Metric Time Dimension 'ds'
Expand Down Expand Up @@ -84,5 +84,5 @@ FROM (
) subq_1
) subq_2
GROUP BY
ds__month
ds__day
) subq_3
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Read Elements From Semantic Model 'revenue'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
DATE_TRUNC(created_at, month) AS ds__month
DATE_TRUNC(created_at, day) AS ds__day
, SUM(revenue) AS trailing_2_months_revenue
FROM ***************************.fct_revenue revenue_src_10007
GROUP BY
ds__month
ds__day
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
-- Compute Metrics via Expressions
SELECT
subq_8.metric_time__month
subq_8.metric_time__day
, subq_8.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_7.metric_time__month
subq_7.metric_time__day
, SUM(subq_7.txn_revenue) AS txn_revenue
FROM (
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
SELECT
subq_6.metric_time__month
subq_6.metric_time__day
, subq_6.txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Pass Only Elements: ['txn_revenue', 'metric_time__day']
SELECT
subq_5.metric_time__month
subq_5.metric_time__day
, subq_5.txn_revenue
FROM (
-- Join Self Over Time Range
Expand Down Expand Up @@ -182,8 +182,8 @@ FROM (
)
) subq_5
) subq_6
WHERE subq_6.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_7
GROUP BY
metric_time__month
metric_time__day
) subq_8
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Pass Only Elements: ['txn_revenue', 'metric_time__day']
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_11.metric_time__month AS metric_time__month
subq_12.metric_time__day AS metric_time__day
, SUM(subq_11.txn_revenue) AS trailing_2_months_revenue
FROM (
-- Time Spine
Expand All @@ -19,7 +19,6 @@ INNER JOIN (
-- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00]
SELECT
DATE_TRUNC(created_at, day) AS metric_time__day
, DATE_TRUNC(created_at, month) AS metric_time__month
, revenue AS txn_revenue
FROM ***************************.fct_revenue revenue_src_10007
WHERE DATE_TRUNC(created_at, day) BETWEEN '2019-11-01' AND '2020-01-01'
Expand All @@ -30,6 +29,6 @@ ON
) AND (
subq_11.metric_time__day > DATE_SUB(CAST(subq_12.metric_time__day AS DATETIME), INTERVAL 2 month)
)
WHERE subq_11.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
WHERE subq_12.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
GROUP BY
metric_time__month
metric_time__day
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- Compute Metrics via Expressions
SELECT
subq_3.ds__month
subq_3.ds__day
, subq_3.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_2.ds__month
subq_2.ds__day
, SUM(subq_2.txn_revenue) AS txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
SELECT
subq_1.ds__month
subq_1.ds__day
, subq_1.txn_revenue
FROM (
-- Metric Time Dimension 'ds'
Expand Down Expand Up @@ -84,5 +84,5 @@ FROM (
) subq_1
) subq_2
GROUP BY
subq_2.ds__month
subq_2.ds__day
) subq_3
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Read Elements From Semantic Model 'revenue'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
DATE_TRUNC('month', created_at) AS ds__month
DATE_TRUNC('day', created_at) AS ds__day
, SUM(revenue) AS trailing_2_months_revenue
FROM ***************************.fct_revenue revenue_src_10007
GROUP BY
DATE_TRUNC('month', created_at)
DATE_TRUNC('day', created_at)
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
-- Compute Metrics via Expressions
SELECT
subq_8.metric_time__month
subq_8.metric_time__day
, subq_8.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_7.metric_time__month
subq_7.metric_time__day
, SUM(subq_7.txn_revenue) AS txn_revenue
FROM (
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
SELECT
subq_6.metric_time__month
subq_6.metric_time__day
, subq_6.txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Pass Only Elements: ['txn_revenue', 'metric_time__day']
SELECT
subq_5.metric_time__month
subq_5.metric_time__day
, subq_5.txn_revenue
FROM (
-- Join Self Over Time Range
Expand Down Expand Up @@ -182,8 +182,8 @@ FROM (
)
) subq_5
) subq_6
WHERE subq_6.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_7
GROUP BY
subq_7.metric_time__month
subq_7.metric_time__day
) subq_8
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Pass Only Elements: ['txn_revenue', 'metric_time__day']
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_11.metric_time__month AS metric_time__month
subq_12.metric_time__day AS metric_time__day
, SUM(subq_11.txn_revenue) AS trailing_2_months_revenue
FROM (
-- Time Spine
Expand All @@ -19,7 +19,6 @@ INNER JOIN (
-- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00]
SELECT
DATE_TRUNC('day', created_at) AS metric_time__day
, DATE_TRUNC('month', created_at) AS metric_time__month
, revenue AS txn_revenue
FROM ***************************.fct_revenue revenue_src_10007
WHERE DATE_TRUNC('day', created_at) BETWEEN '2019-11-01' AND '2020-01-01'
Expand All @@ -30,6 +29,6 @@ ON
) AND (
subq_11.metric_time__day > subq_12.metric_time__day - INTERVAL 2 month
)
WHERE subq_11.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
WHERE subq_12.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
GROUP BY
subq_11.metric_time__month
subq_12.metric_time__day
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- Compute Metrics via Expressions
SELECT
subq_3.ds__month
subq_3.ds__day
, subq_3.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_2.ds__month
subq_2.ds__day
, SUM(subq_2.txn_revenue) AS txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
SELECT
subq_1.ds__month
subq_1.ds__day
, subq_1.txn_revenue
FROM (
-- Metric Time Dimension 'ds'
Expand Down Expand Up @@ -84,5 +84,5 @@ FROM (
) subq_1
) subq_2
GROUP BY
subq_2.ds__month
subq_2.ds__day
) subq_3
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Read Elements From Semantic Model 'revenue'
-- Metric Time Dimension 'ds'
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
DATE_TRUNC('month', created_at) AS ds__month
DATE_TRUNC('day', created_at) AS ds__day
, SUM(revenue) AS trailing_2_months_revenue
FROM ***************************.fct_revenue revenue_src_10007
GROUP BY
DATE_TRUNC('month', created_at)
DATE_TRUNC('day', created_at)
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
-- Compute Metrics via Expressions
SELECT
subq_8.metric_time__month
subq_8.metric_time__day
, subq_8.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_7.metric_time__month
subq_7.metric_time__day
, SUM(subq_7.txn_revenue) AS txn_revenue
FROM (
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
SELECT
subq_6.metric_time__month
subq_6.metric_time__day
, subq_6.txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Pass Only Elements: ['txn_revenue', 'metric_time__day']
SELECT
subq_5.metric_time__month
subq_5.metric_time__day
, subq_5.txn_revenue
FROM (
-- Join Self Over Time Range
Expand Down Expand Up @@ -182,8 +182,8 @@ FROM (
)
) subq_5
) subq_6
WHERE subq_6.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
) subq_7
GROUP BY
subq_7.metric_time__month
subq_7.metric_time__day
) subq_8
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Pass Only Elements: ['txn_revenue', 'metric_time__day']
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_11.metric_time__month AS metric_time__month
subq_12.metric_time__day AS metric_time__day
, SUM(subq_11.txn_revenue) AS trailing_2_months_revenue
FROM (
-- Time Spine
Expand All @@ -19,7 +19,6 @@ INNER JOIN (
-- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00]
SELECT
DATE_TRUNC('day', created_at) AS metric_time__day
, DATE_TRUNC('month', created_at) AS metric_time__month
, revenue AS txn_revenue
FROM ***************************.fct_revenue revenue_src_10007
WHERE DATE_TRUNC('day', created_at) BETWEEN '2019-11-01' AND '2020-01-01'
Expand All @@ -30,6 +29,6 @@ ON
) AND (
subq_11.metric_time__day > DATEADD(month, -2, subq_12.metric_time__day)
)
WHERE subq_11.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
WHERE subq_12.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01'
GROUP BY
subq_11.metric_time__month
subq_12.metric_time__day
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- Compute Metrics via Expressions
SELECT
subq_3.ds__month
subq_3.ds__day
, subq_3.txn_revenue AS trailing_2_months_revenue
FROM (
-- Aggregate Measures
SELECT
subq_2.ds__month
subq_2.ds__day
, SUM(subq_2.txn_revenue) AS txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Pass Only Elements: ['txn_revenue', 'ds__day']
SELECT
subq_1.ds__month
subq_1.ds__day
, subq_1.txn_revenue
FROM (
-- Metric Time Dimension 'ds'
Expand Down Expand Up @@ -84,5 +84,5 @@ FROM (
) subq_1
) subq_2
GROUP BY
subq_2.ds__month
subq_2.ds__day
) subq_3
Loading

0 comments on commit 0e4820a

Please sign in to comment.