Skip to content

Commit

Permalink
Update SQL engine snapshots for rendering tests
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Dec 19, 2024
1 parent b20f4e3 commit e2c1f0e
Show file tree
Hide file tree
Showing 20 changed files with 5,727 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
test_name: test_custom_offset_window
test_filename: test_custom_granularity.py
sql_engine: BigQuery
---
-- Compute Metrics via Expressions
WITH cgb_1_cte AS (
-- Read From Time Spine 'mf_time_spine'
-- Calculate Custom Granularity Bounds
SELECT
martian_day AS ds__martian_day
, FIRST_VALUE(ds) OVER (
PARTITION BY martian_day
ORDER BY ds
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__martian_day__first_value
, LAST_VALUE(ds) OVER (
PARTITION BY martian_day
ORDER BY ds
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__martian_day__last_value
, ROW_NUMBER() OVER (
PARTITION BY martian_day
ORDER BY ds
) AS ds__day__row_number
FROM ***************************.mf_time_spine time_spine_src_28006
)

SELECT
metric_time__day AS metric_time__day
, bookings AS bookings_offset_one_martian_day
FROM (
-- Join to Time Spine Dataset
-- Pass Only Elements: ['bookings', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_26.metric_time__day AS metric_time__day
, SUM(subq_17.bookings) AS bookings
FROM (
-- Offset Base Granularity By Custom Granularity Period(s)
-- Apply Requested Granularities
-- Pass Only Elements: ['metric_time__day',]
SELECT
CASE
WHEN DATE_ADD(CAST(LAG(subq_21.ds__martian_day__first_value, 1) OVER (ORDER BY subq_21.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day) <= LAG(subq_21.ds__martian_day__last_value, 1) OVER (ORDER BY subq_21.ds__martian_day)
THEN DATE_ADD(CAST(LAG(subq_21.ds__martian_day__first_value, 1) OVER (ORDER BY subq_21.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day)
ELSE LAG(subq_21.ds__martian_day__last_value, 1) OVER (ORDER BY subq_21.ds__martian_day)
END AS metric_time__day
FROM cgb_1_cte cgb_1_cte
INNER JOIN (
-- Read From CTE For node_id=cgb_1
-- Pass Only Elements: ['ds__martian_day', 'ds__martian_day__first_value', 'ds__martian_day__last_value']
SELECT
ds__martian_day__first_value
, ds__martian_day__last_value
, ds__martian_day
FROM cgb_1_cte cgb_1_cte
GROUP BY
ds__martian_day__first_value
, ds__martian_day__last_value
, ds__martian_day
) subq_21
ON
cgb_1_cte.ds__martian_day = subq_21.ds__martian_day
) subq_26
INNER JOIN (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_17
ON
subq_26.metric_time__day = subq_17.metric_time__day
GROUP BY
metric_time__day
) subq_30

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
test_name: test_custom_offset_window_with_granularity_and_date_part
test_filename: test_custom_granularity.py
sql_engine: BigQuery
---
-- Compute Metrics via Expressions
WITH cgb_1_cte AS (
-- Read From Time Spine 'mf_time_spine'
-- Calculate Custom Granularity Bounds
SELECT
martian_day AS ds__martian_day
, FIRST_VALUE(ds) OVER (
PARTITION BY martian_day
ORDER BY ds
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__martian_day__first_value
, LAST_VALUE(ds) OVER (
PARTITION BY martian_day
ORDER BY ds
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS ds__martian_day__last_value
, ROW_NUMBER() OVER (
PARTITION BY martian_day
ORDER BY ds
) AS ds__day__row_number
FROM ***************************.mf_time_spine time_spine_src_28006
)

SELECT
metric_time__martian_day AS metric_time__martian_day
, booking__ds__month AS booking__ds__month
, metric_time__extract_year AS metric_time__extract_year
, bookings AS bookings_offset_one_martian_day
FROM (
-- Join to Time Spine Dataset
-- Join to Custom Granularity Dataset
-- Pass Only Elements: ['bookings', 'booking__ds__month', 'metric_time__extract_year', 'metric_time__martian_day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
subq_28.martian_day AS metric_time__martian_day
, subq_27.booking__ds__month AS booking__ds__month
, subq_27.metric_time__extract_year AS metric_time__extract_year
, SUM(subq_18.bookings) AS bookings
FROM (
-- Offset Base Granularity By Custom Granularity Period(s)
-- Apply Requested Granularities
-- Pass Only Elements: ['booking__ds__month', 'metric_time__extract_year', 'metric_time__day']
SELECT
DATETIME_TRUNC(CASE
WHEN DATE_ADD(CAST(LAG(subq_22.ds__martian_day__first_value, 1) OVER (ORDER BY subq_22.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day) <= LAG(subq_22.ds__martian_day__last_value, 1) OVER (ORDER BY subq_22.ds__martian_day)
THEN DATE_ADD(CAST(LAG(subq_22.ds__martian_day__first_value, 1) OVER (ORDER BY subq_22.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day)
ELSE LAG(subq_22.ds__martian_day__last_value, 1) OVER (ORDER BY subq_22.ds__martian_day)
END, month) AS booking__ds__month
, EXTRACT(year FROM CASE
WHEN DATE_ADD(CAST(LAG(subq_22.ds__martian_day__first_value, 1) OVER (ORDER BY subq_22.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day) <= LAG(subq_22.ds__martian_day__last_value, 1) OVER (ORDER BY subq_22.ds__martian_day)
THEN DATE_ADD(CAST(LAG(subq_22.ds__martian_day__first_value, 1) OVER (ORDER BY subq_22.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day)
ELSE LAG(subq_22.ds__martian_day__last_value, 1) OVER (ORDER BY subq_22.ds__martian_day)
END) AS metric_time__extract_year
, CASE
WHEN DATE_ADD(CAST(LAG(subq_22.ds__martian_day__first_value, 1) OVER (ORDER BY subq_22.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day) <= LAG(subq_22.ds__martian_day__last_value, 1) OVER (ORDER BY subq_22.ds__martian_day)
THEN DATE_ADD(CAST(LAG(subq_22.ds__martian_day__first_value, 1) OVER (ORDER BY subq_22.ds__martian_day) AS DATETIME), INTERVAL SqlExpressionRenderResult(sql='cgb_1_cte.ds__day__row_number - 1', bind_parameter_set=SqlBindParameterSet(param_items=())) day)
ELSE LAG(subq_22.ds__martian_day__last_value, 1) OVER (ORDER BY subq_22.ds__martian_day)
END AS metric_time__day
FROM cgb_1_cte cgb_1_cte
INNER JOIN (
-- Read From CTE For node_id=cgb_1
-- Pass Only Elements: ['ds__martian_day', 'ds__martian_day__first_value', 'ds__martian_day__last_value']
SELECT
ds__martian_day__first_value
, ds__martian_day__last_value
, ds__martian_day
FROM cgb_1_cte cgb_1_cte
GROUP BY
ds__martian_day__first_value
, ds__martian_day__last_value
, ds__martian_day
) subq_22
ON
cgb_1_cte.ds__martian_day = subq_22.ds__martian_day
) subq_27
INNER JOIN (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
SELECT
DATETIME_TRUNC(ds, day) AS metric_time__day
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
) subq_18
ON
subq_27.metric_time__day = subq_18.metric_time__day
LEFT OUTER JOIN
***************************.mf_time_spine subq_28
ON
subq_27.metric_time__day = subq_28.ds
GROUP BY
metric_time__martian_day
, booking__ds__month
, metric_time__extract_year
) subq_32
Loading

0 comments on commit e2c1f0e

Please sign in to comment.