-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8a3d58
commit 0938ede
Showing
5 changed files
with
384 additions
and
2 deletions.
There are no files selected for viewing
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
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
88 changes: 88 additions & 0 deletions
88
..._dataflow_to_sql_plan.py/SqlPlan/DuckDB/test_offset_by_custom_granularity_node__plan0.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,88 @@ | ||
test_name: test_offset_by_custom_granularity_node | ||
test_filename: test_dataflow_to_sql_plan.py | ||
sql_engine: DuckDB | ||
--- | ||
-- Apply Requested Granularities | ||
SELECT | ||
subq_3.ds__day | ||
, DATE_TRUNC('month', subq_3.ds__day__lead) AS metric_time__month | ||
FROM ( | ||
-- Offset Base Granularity By Custom Granularity Period(s) | ||
WITH cte_0 AS ( | ||
-- Get Custom Granularity Bounds | ||
SELECT | ||
time_spine_src_28006.ds AS ds__day | ||
, DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week | ||
, DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month | ||
, DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter | ||
, DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year | ||
, EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year | ||
, EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter | ||
, EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month | ||
, EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day | ||
, EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow | ||
, EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy | ||
, time_spine_src_28006.martian_day AS ds__martian_day | ||
, FIRST_VALUE(subq_0.ds__day) OVER ( | ||
PARTITION BY subq_0.ds__martian_day | ||
ORDER BY subq_0.ds__day | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS ds__martian_day__first_value | ||
, LAST_VALUE(subq_0.ds__day) OVER ( | ||
PARTITION BY subq_0.ds__martian_day | ||
ORDER BY subq_0.ds__day | ||
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | ||
) AS ds__martian_day__last_value | ||
, ROW_NUMBER() OVER ( | ||
PARTITION BY subq_0.ds__martian_day | ||
ORDER BY subq_0.ds__day | ||
) AS ds__day__row_number | ||
FROM ( | ||
-- Read From Time Spine 'mf_time_spine' | ||
SELECT | ||
time_spine_src_28006.ds AS ds__day | ||
, DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week | ||
, DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month | ||
, DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter | ||
, DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year | ||
, EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year | ||
, EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter | ||
, EXTRACT(month FROM time_spine_src_28006.ds) AS ds__extract_month | ||
, EXTRACT(day FROM time_spine_src_28006.ds) AS ds__extract_day | ||
, EXTRACT(isodow FROM time_spine_src_28006.ds) AS ds__extract_dow | ||
, EXTRACT(doy FROM time_spine_src_28006.ds) AS ds__extract_doy | ||
, time_spine_src_28006.martian_day AS ds__martian_day | ||
FROM ***************************.mf_time_spine time_spine_src_28006 | ||
) subq_0 | ||
) | ||
|
||
SELECT | ||
cte_0.ds__day AS ds__day | ||
, CASE | ||
WHEN subq_2.ds__martian_day__first_value__lead + INTERVAL (cte_0.ds__day__row_number - 1) day <= subq_2.ds__martian_day__last_value__lead | ||
THEN subq_2.ds__martian_day__first_value__lead + INTERVAL (cte_0.ds__day__row_number - 1) day | ||
ELSE NULL | ||
END AS ds__day__lead | ||
FROM cte_0 cte_0 | ||
INNER JOIN ( | ||
-- Offset Custom Granularity Bounds | ||
SELECT | ||
subq_1.ds__martian_day | ||
, LEAD(subq_1.ds__martian_day__first_value, 3) OVER (ORDER BY subq_1.ds__martian_day) AS ds__martian_day__first_value__lead | ||
, LEAD(subq_1.ds__martian_day__last_value, 3) OVER (ORDER BY subq_1.ds__martian_day) AS ds__martian_day__last_value__lead | ||
FROM ( | ||
-- Get Unique Rows for Custom Granularity Bounds | ||
SELECT | ||
cte_0.ds__martian_day | ||
, cte_0.ds__martian_day__first_value | ||
, cte_0.ds__martian_day__last_value | ||
FROM cte_0 cte_0 | ||
GROUP BY | ||
cte_0.ds__martian_day | ||
, cte_0.ds__martian_day__first_value | ||
, cte_0.ds__martian_day__last_value | ||
) subq_1 | ||
) subq_2 | ||
ON | ||
cte_0.ds__martian_day = subq_2.ds__martian_day | ||
) subq_3 |
56 changes: 56 additions & 0 deletions
56
...to_sql_plan.py/SqlPlan/DuckDB/test_offset_by_custom_granularity_node__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,56 @@ | ||
test_name: test_offset_by_custom_granularity_node | ||
test_filename: test_dataflow_to_sql_plan.py | ||
sql_engine: DuckDB | ||
--- | ||
-- Apply Requested Granularities | ||
SELECT | ||
ds__day | ||
, DATE_TRUNC('month', ds__day__lead) AS metric_time__month | ||
FROM ( | ||
-- Offset Base Granularity By Custom Granularity Period(s) | ||
WITH cte_2 AS ( | ||
-- Read From Time Spine 'mf_time_spine' | ||
-- Get Custom Granularity Bounds | ||
SELECT | ||
ds AS ds__day | ||
, 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 | ||
cte_2.ds__day AS ds__day | ||
, CASE | ||
WHEN LEAD(subq_5.ds__martian_day__first_value, 3) OVER (ORDER BY subq_5.ds__martian_day) + INTERVAL (cte_2.ds__day__row_number - 1) day <= LEAD(subq_5.ds__martian_day__last_value, 3) OVER (ORDER BY subq_5.ds__martian_day) | ||
THEN LEAD(subq_5.ds__martian_day__first_value, 3) OVER (ORDER BY subq_5.ds__martian_day) + INTERVAL (cte_2.ds__day__row_number - 1) day | ||
ELSE NULL | ||
END AS ds__day__lead | ||
FROM cte_2 cte_2 | ||
INNER JOIN ( | ||
-- Get Unique Rows for Custom Granularity Bounds | ||
SELECT | ||
ds__martian_day | ||
, ds__martian_day__first_value | ||
, ds__martian_day__last_value | ||
FROM cte_2 cte_2 | ||
GROUP BY | ||
ds__martian_day | ||
, ds__martian_day__first_value | ||
, ds__martian_day__last_value | ||
) subq_5 | ||
ON | ||
cte_2.ds__martian_day = subq_5.ds__martian_day | ||
) subq_7 |
Oops, something went wrong.