-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SQL engine snapshots for rendering tests
- Loading branch information
1 parent
b20f4e3
commit e2c1f0e
Showing
20 changed files
with
5,727 additions
and
0 deletions.
There are no files selected for viewing
461 changes: 461 additions & 0 deletions
461
...napshots/test_custom_granularity.py/SqlPlan/BigQuery/test_custom_offset_window__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
...est_custom_granularity.py/SqlPlan/BigQuery/test_custom_offset_window__plan0_optimized.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
481 changes: 481 additions & 0 deletions
481
...y.py/SqlPlan/BigQuery/test_custom_offset_window_with_granularity_and_date_part__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
...an/BigQuery/test_custom_offset_window_with_granularity_and_date_part__plan0_optimized.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.