Skip to content

Commit

Permalink
Fix newly broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jan 30, 2024
1 parent f8bae3a commit b8f5c9b
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,7 @@ def test_cumulative_metric_no_window_with_time_constraint(
MetricFlowQuerySpec(
metric_specs=(MetricSpec(element_name="revenue_all_time"),),
dimension_specs=(),
time_dimension_specs=(
TimeDimensionSpec(
element_name="ds",
entity_links=(),
time_granularity=TimeGranularity.MONTH,
),
),
time_dimension_specs=(MTD_SPEC_MONTH,),
time_range_constraint=TimeRangeConstraint(
start_time=as_datetime("2020-01-01"), end_time=as_datetime("2020-01-01")
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,129 +1,187 @@
-- Compute Metrics via Expressions
SELECT
subq_4.ds__month
, subq_4.txn_revenue AS revenue_all_time
subq_8.metric_time__month
, subq_8.txn_revenue AS revenue_all_time
FROM (
-- Aggregate Measures
SELECT
subq_3.ds__month
, SUM(subq_3.txn_revenue) AS txn_revenue
subq_7.metric_time__month
, SUM(subq_7.txn_revenue) AS txn_revenue
FROM (
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
SELECT
subq_2.ds__month
, subq_2.txn_revenue
subq_6.metric_time__month
, subq_6.txn_revenue
FROM (
-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00]
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
SELECT
subq_1.ds__day
, subq_1.ds__week
, subq_1.ds__month
, subq_1.ds__quarter
, subq_1.ds__year
, subq_1.ds__extract_year
, subq_1.ds__extract_quarter
, subq_1.ds__extract_month
, subq_1.ds__extract_day
, subq_1.ds__extract_dow
, subq_1.ds__extract_doy
, subq_1.revenue_instance__ds__day
, subq_1.revenue_instance__ds__week
, subq_1.revenue_instance__ds__month
, subq_1.revenue_instance__ds__quarter
, subq_1.revenue_instance__ds__year
, subq_1.revenue_instance__ds__extract_year
, subq_1.revenue_instance__ds__extract_quarter
, subq_1.revenue_instance__ds__extract_month
, subq_1.revenue_instance__ds__extract_day
, subq_1.revenue_instance__ds__extract_dow
, subq_1.revenue_instance__ds__extract_doy
, subq_1.metric_time__day
, subq_1.metric_time__week
, subq_1.metric_time__month
, subq_1.metric_time__quarter
, subq_1.metric_time__year
, subq_1.metric_time__extract_year
, subq_1.metric_time__extract_quarter
, subq_1.metric_time__extract_month
, subq_1.metric_time__extract_day
, subq_1.metric_time__extract_dow
, subq_1.metric_time__extract_doy
, subq_1.user
, subq_1.revenue_instance__user
, subq_1.txn_revenue
subq_5.metric_time__month
, subq_5.txn_revenue
FROM (
-- Metric Time Dimension 'ds'
-- Join Self Over Time Range
SELECT
subq_0.ds__day
, subq_0.ds__week
, subq_0.ds__month
, subq_0.ds__quarter
, subq_0.ds__year
, subq_0.ds__extract_year
, subq_0.ds__extract_quarter
, subq_0.ds__extract_month
, subq_0.ds__extract_day
, subq_0.ds__extract_dow
, subq_0.ds__extract_doy
, subq_0.revenue_instance__ds__day
, subq_0.revenue_instance__ds__week
, subq_0.revenue_instance__ds__month
, subq_0.revenue_instance__ds__quarter
, subq_0.revenue_instance__ds__year
, subq_0.revenue_instance__ds__extract_year
, subq_0.revenue_instance__ds__extract_quarter
, subq_0.revenue_instance__ds__extract_month
, subq_0.revenue_instance__ds__extract_day
, subq_0.revenue_instance__ds__extract_dow
, subq_0.revenue_instance__ds__extract_doy
, subq_0.ds__day AS metric_time__day
, subq_0.ds__week AS metric_time__week
, subq_0.ds__month AS metric_time__month
, subq_0.ds__quarter AS metric_time__quarter
, subq_0.ds__year AS metric_time__year
, subq_0.ds__extract_year AS metric_time__extract_year
, subq_0.ds__extract_quarter AS metric_time__extract_quarter
, subq_0.ds__extract_month AS metric_time__extract_month
, subq_0.ds__extract_day AS metric_time__extract_day
, subq_0.ds__extract_dow AS metric_time__extract_dow
, subq_0.ds__extract_doy AS metric_time__extract_doy
, subq_0.user
, subq_0.revenue_instance__user
, subq_0.txn_revenue
subq_3.metric_time__month AS metric_time__month
, subq_2.ds__day AS ds__day
, subq_2.ds__week AS ds__week
, subq_2.ds__month AS ds__month
, subq_2.ds__quarter AS ds__quarter
, subq_2.ds__year AS ds__year
, subq_2.ds__extract_year AS ds__extract_year
, subq_2.ds__extract_quarter AS ds__extract_quarter
, subq_2.ds__extract_month AS ds__extract_month
, subq_2.ds__extract_day AS ds__extract_day
, subq_2.ds__extract_dow AS ds__extract_dow
, subq_2.ds__extract_doy AS ds__extract_doy
, subq_2.revenue_instance__ds__day AS revenue_instance__ds__day
, subq_2.revenue_instance__ds__week AS revenue_instance__ds__week
, subq_2.revenue_instance__ds__month AS revenue_instance__ds__month
, subq_2.revenue_instance__ds__quarter AS revenue_instance__ds__quarter
, subq_2.revenue_instance__ds__year AS revenue_instance__ds__year
, subq_2.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year
, subq_2.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter
, subq_2.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month
, subq_2.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day
, subq_2.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow
, subq_2.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy
, subq_2.metric_time__day AS metric_time__day
, subq_2.metric_time__week AS metric_time__week
, subq_2.metric_time__quarter AS metric_time__quarter
, subq_2.metric_time__year AS metric_time__year
, subq_2.metric_time__extract_year AS metric_time__extract_year
, subq_2.metric_time__extract_quarter AS metric_time__extract_quarter
, subq_2.metric_time__extract_month AS metric_time__extract_month
, subq_2.metric_time__extract_day AS metric_time__extract_day
, subq_2.metric_time__extract_dow AS metric_time__extract_dow
, subq_2.metric_time__extract_doy AS metric_time__extract_doy
, subq_2.user AS user
, subq_2.revenue_instance__user AS revenue_instance__user
, subq_2.txn_revenue AS txn_revenue
FROM (
-- Read Elements From Semantic Model 'revenue'
-- Time Spine
SELECT
revenue_src_10007.revenue AS txn_revenue
, DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
, DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
, DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
, DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
, DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
, EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
, EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
, EXTRACT(isodow FROM revenue_src_10007.created_at) AS ds__extract_dow
, EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
, DATE_TRUNC('day', revenue_src_10007.created_at) AS revenue_instance__ds__day
, DATE_TRUNC('week', revenue_src_10007.created_at) AS revenue_instance__ds__week
, DATE_TRUNC('month', revenue_src_10007.created_at) AS revenue_instance__ds__month
, DATE_TRUNC('quarter', revenue_src_10007.created_at) AS revenue_instance__ds__quarter
, DATE_TRUNC('year', revenue_src_10007.created_at) AS revenue_instance__ds__year
, EXTRACT(year FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_month
, EXTRACT(day FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_day
, EXTRACT(isodow FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_dow
, EXTRACT(doy FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_doy
, revenue_src_10007.user_id AS user
, revenue_src_10007.user_id AS revenue_instance__user
FROM ***************************.fct_revenue revenue_src_10007
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01'
) subq_2
) subq_3
DATE_TRUNC('month', subq_4.ds) AS metric_time__month
FROM ***************************.mf_time_spine subq_4
WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', subq_4.ds)
) subq_3
INNER JOIN (
-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00]
SELECT
subq_1.ds__day
, subq_1.ds__week
, subq_1.ds__month
, subq_1.ds__quarter
, subq_1.ds__year
, subq_1.ds__extract_year
, subq_1.ds__extract_quarter
, subq_1.ds__extract_month
, subq_1.ds__extract_day
, subq_1.ds__extract_dow
, subq_1.ds__extract_doy
, subq_1.revenue_instance__ds__day
, subq_1.revenue_instance__ds__week
, subq_1.revenue_instance__ds__month
, subq_1.revenue_instance__ds__quarter
, subq_1.revenue_instance__ds__year
, subq_1.revenue_instance__ds__extract_year
, subq_1.revenue_instance__ds__extract_quarter
, subq_1.revenue_instance__ds__extract_month
, subq_1.revenue_instance__ds__extract_day
, subq_1.revenue_instance__ds__extract_dow
, subq_1.revenue_instance__ds__extract_doy
, subq_1.metric_time__day
, subq_1.metric_time__week
, subq_1.metric_time__month
, subq_1.metric_time__quarter
, subq_1.metric_time__year
, subq_1.metric_time__extract_year
, subq_1.metric_time__extract_quarter
, subq_1.metric_time__extract_month
, subq_1.metric_time__extract_day
, subq_1.metric_time__extract_dow
, subq_1.metric_time__extract_doy
, subq_1.user
, subq_1.revenue_instance__user
, subq_1.txn_revenue
FROM (
-- Metric Time Dimension 'ds'
SELECT
subq_0.ds__day
, subq_0.ds__week
, subq_0.ds__month
, subq_0.ds__quarter
, subq_0.ds__year
, subq_0.ds__extract_year
, subq_0.ds__extract_quarter
, subq_0.ds__extract_month
, subq_0.ds__extract_day
, subq_0.ds__extract_dow
, subq_0.ds__extract_doy
, subq_0.revenue_instance__ds__day
, subq_0.revenue_instance__ds__week
, subq_0.revenue_instance__ds__month
, subq_0.revenue_instance__ds__quarter
, subq_0.revenue_instance__ds__year
, subq_0.revenue_instance__ds__extract_year
, subq_0.revenue_instance__ds__extract_quarter
, subq_0.revenue_instance__ds__extract_month
, subq_0.revenue_instance__ds__extract_day
, subq_0.revenue_instance__ds__extract_dow
, subq_0.revenue_instance__ds__extract_doy
, subq_0.ds__day AS metric_time__day
, subq_0.ds__week AS metric_time__week
, subq_0.ds__month AS metric_time__month
, subq_0.ds__quarter AS metric_time__quarter
, subq_0.ds__year AS metric_time__year
, subq_0.ds__extract_year AS metric_time__extract_year
, subq_0.ds__extract_quarter AS metric_time__extract_quarter
, subq_0.ds__extract_month AS metric_time__extract_month
, subq_0.ds__extract_day AS metric_time__extract_day
, subq_0.ds__extract_dow AS metric_time__extract_dow
, subq_0.ds__extract_doy AS metric_time__extract_doy
, subq_0.user
, subq_0.revenue_instance__user
, subq_0.txn_revenue
FROM (
-- Read Elements From Semantic Model 'revenue'
SELECT
revenue_src_10007.revenue AS txn_revenue
, DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
, DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
, DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
, DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
, DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
, EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
, EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
, EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
, EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
, EXTRACT(isodow FROM revenue_src_10007.created_at) AS ds__extract_dow
, EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
, DATE_TRUNC('day', revenue_src_10007.created_at) AS revenue_instance__ds__day
, DATE_TRUNC('week', revenue_src_10007.created_at) AS revenue_instance__ds__week
, DATE_TRUNC('month', revenue_src_10007.created_at) AS revenue_instance__ds__month
, DATE_TRUNC('quarter', revenue_src_10007.created_at) AS revenue_instance__ds__quarter
, DATE_TRUNC('year', revenue_src_10007.created_at) AS revenue_instance__ds__year
, EXTRACT(year FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_year
, EXTRACT(quarter FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_quarter
, EXTRACT(month FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_month
, EXTRACT(day FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_day
, EXTRACT(isodow FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_dow
, EXTRACT(doy FROM revenue_src_10007.created_at) AS revenue_instance__ds__extract_doy
, revenue_src_10007.user_id AS user
, revenue_src_10007.user_id AS revenue_instance__user
FROM ***************************.fct_revenue revenue_src_10007
) subq_0
) subq_1
WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01'
) subq_2
ON
(subq_2.metric_time__month <= subq_3.metric_time__month)
) subq_5
) subq_6
WHERE subq_6.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
) subq_7
GROUP BY
subq_3.ds__month
) subq_4
subq_7.metric_time__month
) subq_8
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
-- Read Elements From Semantic Model 'revenue'
-- Metric Time Dimension 'ds'
-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00]
-- Pass Only Elements: ['txn_revenue', 'ds__month']
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__month']
-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
DATE_TRUNC('month', created_at) AS ds__month
, SUM(revenue) AS revenue_all_time
FROM ***************************.fct_revenue revenue_src_10007
WHERE DATE_TRUNC('day', created_at) BETWEEN '2000-01-01' AND '2020-01-01'
subq_12.metric_time__month AS metric_time__month
, SUM(subq_11.txn_revenue) AS revenue_all_time
FROM (
-- Time Spine
SELECT
DATE_TRUNC('month', ds) AS metric_time__month
FROM ***************************.mf_time_spine subq_13
WHERE ds BETWEEN '2020-01-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', ds)
) subq_12
INNER JOIN (
-- Read Elements From Semantic Model 'revenue'
-- Metric Time Dimension 'ds'
-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00]
SELECT
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 '2000-01-01' AND '2020-01-01'
) subq_11
ON
(subq_11.metric_time__month <= subq_12.metric_time__month)
WHERE subq_12.metric_time__month BETWEEN '2020-01-01' AND '2020-01-01'
GROUP BY
DATE_TRUNC('month', created_at)
subq_12.metric_time__month

0 comments on commit b8f5c9b

Please sign in to comment.