-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix: For measures using join_to_timespine
, apply filters after time spine join
#1056
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
52417b3
Changelog
courtneyholcomb aaecec1
Update DataFlow Plan to apply filters again after joining to time spine
courtneyholcomb 670538c
Write tests
courtneyholcomb 816696c
Update basic snapshots
courtneyholcomb a399940
Update snapshots for all engines
courtneyholcomb 312307b
Merge main
courtneyholcomb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
352 changes: 352 additions & 0 deletions
352
...s_with_rendering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...dering.py/SqlQueryPlan/BigQuery/test_join_to_time_spine_with_filters__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,52 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 | ||
FROM ( | ||
-- Constrain Output with WHERE | ||
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] | ||
SELECT | ||
metric_time__day | ||
, bookings | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
SELECT | ||
subq_19.metric_time__day AS metric_time__day | ||
, subq_18.bookings AS bookings | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
ds AS metric_time__day | ||
FROM ***************************.mf_time_spine subq_20 | ||
WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' | ||
) subq_19 | ||
LEFT OUTER JOIN ( | ||
-- Constrain Output with WHERE | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] | ||
-- Pass Only Elements: ['bookings', 'metric_time__day'] | ||
SELECT | ||
DATE_TRUNC(ds, day) AS metric_time__day | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_28000 | ||
WHERE DATE_TRUNC(ds, day) BETWEEN '2020-01-03' AND '2020-01-05' | ||
) subq_16 | ||
WHERE metric_time__day > '2020-01-01' | ||
GROUP BY | ||
metric_time__day | ||
) subq_18 | ||
ON | ||
subq_19.metric_time__day = subq_18.metric_time__day | ||
) subq_21 | ||
WHERE ( | ||
metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' | ||
) AND ( | ||
metric_time__day > '2020-01-01' | ||
) | ||
) subq_23 |
352 changes: 352 additions & 0 deletions
352
...with_rendering.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...ring.py/SqlQueryPlan/Databricks/test_join_to_time_spine_with_filters__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,52 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 | ||
FROM ( | ||
-- Constrain Output with WHERE | ||
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] | ||
SELECT | ||
metric_time__day | ||
, bookings | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
SELECT | ||
subq_19.metric_time__day AS metric_time__day | ||
, subq_18.bookings AS bookings | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
ds AS metric_time__day | ||
FROM ***************************.mf_time_spine subq_20 | ||
WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' | ||
) subq_19 | ||
LEFT OUTER JOIN ( | ||
-- Constrain Output with WHERE | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] | ||
-- Pass Only Elements: ['bookings', 'metric_time__day'] | ||
SELECT | ||
DATE_TRUNC('day', ds) AS metric_time__day | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_28000 | ||
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' | ||
) subq_16 | ||
WHERE metric_time__day > '2020-01-01' | ||
GROUP BY | ||
metric_time__day | ||
) subq_18 | ||
ON | ||
subq_19.metric_time__day = subq_18.metric_time__day | ||
) subq_21 | ||
WHERE ( | ||
metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' | ||
) AND ( | ||
metric_time__day > '2020-01-01' | ||
) | ||
) subq_23 |
352 changes: 352 additions & 0 deletions
352
...s_with_rendering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__plan0.sql
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...dering.py/SqlQueryPlan/Postgres/test_join_to_time_spine_with_filters__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,52 @@ | ||
-- Compute Metrics via Expressions | ||
SELECT | ||
metric_time__day | ||
, COALESCE(bookings, 0) AS bookings_fill_nulls_with_0 | ||
FROM ( | ||
-- Constrain Output with WHERE | ||
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] | ||
SELECT | ||
metric_time__day | ||
, bookings | ||
FROM ( | ||
-- Join to Time Spine Dataset | ||
SELECT | ||
subq_19.metric_time__day AS metric_time__day | ||
, subq_18.bookings AS bookings | ||
FROM ( | ||
-- Time Spine | ||
SELECT | ||
ds AS metric_time__day | ||
FROM ***************************.mf_time_spine subq_20 | ||
WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' | ||
) subq_19 | ||
LEFT OUTER JOIN ( | ||
-- Constrain Output with WHERE | ||
-- Aggregate Measures | ||
SELECT | ||
metric_time__day | ||
, SUM(bookings) AS bookings | ||
FROM ( | ||
-- Read Elements From Semantic Model 'bookings_source' | ||
-- Metric Time Dimension 'ds' | ||
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] | ||
-- Pass Only Elements: ['bookings', 'metric_time__day'] | ||
SELECT | ||
DATE_TRUNC('day', ds) AS metric_time__day | ||
, 1 AS bookings | ||
FROM ***************************.fct_bookings bookings_source_src_28000 | ||
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05' | ||
) subq_16 | ||
WHERE metric_time__day > '2020-01-01' | ||
GROUP BY | ||
metric_time__day | ||
) subq_18 | ||
ON | ||
subq_19.metric_time__day = subq_18.metric_time__day | ||
) subq_21 | ||
WHERE ( | ||
metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' | ||
) AND ( | ||
metric_time__day > '2020-01-01' | ||
) | ||
) subq_23 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an artifact of passing both a time constraint and a where filter on metric_time in the same query, right? Because if the filter in the query was
metric_time__day = '2020-01-01'
then this would return the empty set, but that's actually what the constraint combination would tell us to do.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I knew it was weird when I wrote this test case but I just wanted to make sure both filters got rendered 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also it won't return an empty dataset since
'2020-01-03'
through'2020-01-05'
is> '2020-01-01'
!