Skip to content

Commit

Permalink
Update snapshots for other SQL engines.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Nov 14, 2024
1 parent 84e6c71 commit 10af148
Show file tree
Hide file tree
Showing 396 changed files with 19,886 additions and 14,216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,60 @@ docstring:
Test querying a derived metric with a cumulative input metric using non-default grains.
sql_engine: BigQuery
---
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Re-aggregate Metric via Group By
-- Read From CTE For node_id=cm_5
WITH cm_4_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, txn_revenue AS t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
SELECT
subq_13.ds AS metric_time__day
, DATETIME_TRUNC(subq_13.ds, isoweek) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_13.ds
) AND (
DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 2 month)
)
GROUP BY
metric_time__day
, metric_time__week
) subq_16
)

, cm_5_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Compute Metrics via Expressions
-- Window Function for Metric Re-aggregation
-- Re-aggregate Metric via Group By
SELECT
metric_time__week
, AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr
, t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
-- Read From CTE For node_id=cm_4
-- Window Function for Metric Re-aggregation
SELECT
subq_13.ds AS metric_time__day
, DATETIME_TRUNC(subq_13.ds, isoweek) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATETIME_TRUNC(revenue_src_28000.created_at, day) <= subq_13.ds
) AND (
DATETIME_TRUNC(revenue_src_28000.created_at, day) > DATE_SUB(CAST(subq_13.ds AS DATETIME), INTERVAL 2 month)
)
GROUP BY
metric_time__day
, metric_time__week
) subq_16
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
metric_time__week
, AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr
FROM cm_4_cte cm_4_cte
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
)

SELECT
metric_time__week AS metric_time__week
, trailing_2_months_revenue_sub_10 AS trailing_2_months_revenue_sub_10
FROM cm_5_cte cm_5_cte
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,60 @@ docstring:
Test querying a derived metric with a cumulative input metric using non-default grains.
sql_engine: Databricks
---
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Re-aggregate Metric via Group By
-- Read From CTE For node_id=cm_5
WITH cm_4_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, txn_revenue AS t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
SELECT
subq_13.ds AS metric_time__day
, DATE_TRUNC('week', subq_13.ds) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds
) AND (
DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds)
)
GROUP BY
subq_13.ds
, DATE_TRUNC('week', subq_13.ds)
) subq_16
)

, cm_5_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Compute Metrics via Expressions
-- Window Function for Metric Re-aggregation
-- Re-aggregate Metric via Group By
SELECT
metric_time__week
, AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr
, t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
-- Read From CTE For node_id=cm_4
-- Window Function for Metric Re-aggregation
SELECT
subq_13.ds AS metric_time__day
, DATE_TRUNC('week', subq_13.ds) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds
) AND (
DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds)
)
GROUP BY
subq_13.ds
, DATE_TRUNC('week', subq_13.ds)
) subq_16
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
metric_time__week
, AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr
FROM cm_4_cte cm_4_cte
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
)

SELECT
metric_time__week AS metric_time__week
, trailing_2_months_revenue_sub_10 AS trailing_2_months_revenue_sub_10
FROM cm_5_cte cm_5_cte
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,60 @@ docstring:
Test querying a derived metric with a cumulative input metric using non-default grains.
sql_engine: Postgres
---
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Re-aggregate Metric via Group By
-- Read From CTE For node_id=cm_5
WITH cm_4_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, txn_revenue AS t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
SELECT
subq_13.ds AS metric_time__day
, DATE_TRUNC('week', subq_13.ds) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds
) AND (
DATE_TRUNC('day', revenue_src_28000.created_at) > subq_13.ds - MAKE_INTERVAL(months => 2)
)
GROUP BY
subq_13.ds
, DATE_TRUNC('week', subq_13.ds)
) subq_16
)

, cm_5_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Compute Metrics via Expressions
-- Window Function for Metric Re-aggregation
-- Re-aggregate Metric via Group By
SELECT
metric_time__week
, AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr
, t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
-- Read From CTE For node_id=cm_4
-- Window Function for Metric Re-aggregation
SELECT
subq_13.ds AS metric_time__day
, DATE_TRUNC('week', subq_13.ds) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds
) AND (
DATE_TRUNC('day', revenue_src_28000.created_at) > subq_13.ds - MAKE_INTERVAL(months => 2)
)
GROUP BY
subq_13.ds
, DATE_TRUNC('week', subq_13.ds)
) subq_16
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
metric_time__week
, AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr
FROM cm_4_cte cm_4_cte
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
)

SELECT
metric_time__week AS metric_time__week
, trailing_2_months_revenue_sub_10 AS trailing_2_months_revenue_sub_10
FROM cm_5_cte cm_5_cte
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,60 @@ docstring:
Test querying a derived metric with a cumulative input metric using non-default grains.
sql_engine: Redshift
---
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Re-aggregate Metric via Group By
-- Read From CTE For node_id=cm_5
WITH cm_4_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, txn_revenue AS t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
SELECT
subq_13.ds AS metric_time__day
, DATE_TRUNC('week', subq_13.ds) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds
) AND (
DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds)
)
GROUP BY
subq_13.ds
, DATE_TRUNC('week', subq_13.ds)
) subq_16
)

, cm_5_cte AS (
-- Compute Metrics via Expressions
SELECT
metric_time__week
, t2mr
, t2mr - 10 AS trailing_2_months_revenue_sub_10
FROM (
-- Compute Metrics via Expressions
-- Window Function for Metric Re-aggregation
-- Re-aggregate Metric via Group By
SELECT
metric_time__week
, AVG(txn_revenue) OVER (PARTITION BY metric_time__week) AS t2mr
, t2mr
FROM (
-- Join Self Over Time Range
-- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day']
-- Aggregate Measures
-- Read From CTE For node_id=cm_4
-- Window Function for Metric Re-aggregation
SELECT
subq_13.ds AS metric_time__day
, DATE_TRUNC('week', subq_13.ds) AS metric_time__week
, SUM(revenue_src_28000.revenue) AS txn_revenue
FROM ***************************.mf_time_spine subq_13
INNER JOIN
***************************.fct_revenue revenue_src_28000
ON
(
DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds
) AND (
DATE_TRUNC('day', revenue_src_28000.created_at) > DATEADD(month, -2, subq_13.ds)
)
GROUP BY
subq_13.ds
, DATE_TRUNC('week', subq_13.ds)
) subq_16
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
metric_time__week
, AVG(t2mr) OVER (PARTITION BY metric_time__week) AS t2mr
FROM cm_4_cte cm_4_cte
) subq_18
GROUP BY
metric_time__week
, t2mr
) subq_19
)

SELECT
metric_time__week AS metric_time__week
, trailing_2_months_revenue_sub_10 AS trailing_2_months_revenue_sub_10
FROM cm_5_cte cm_5_cte
Loading

0 comments on commit 10af148

Please sign in to comment.