Skip to content
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: incorrect time constraint for time offset metrics #932

Merged
merged 6 commits into from
Dec 15, 2023

Conversation

courtneyholcomb
Copy link
Contributor

Resolves SL-1357
Resolves #925

Description

Fixes time constraint issues with time offset metrics. The time constraint was being applied in several places:

  1. In the time spine subquery
  2. In the input metric subquery
  3. After joining the two subqueries
  4. In the outer query for the outer derived metric

This PR removes 2 and 4.
2 is incorrect because the input metric subquery has not had the time offset applied yet, so the constrained values will be incorrect. Plus, one the input metric subquery is joined to the time spine subquery, the time constraint will effectively be applied since the queries use INNER JOIN on the time constraint column.
3 is not incorrect, it's just redundant.
4 may appear redundant for cases when all input metrics have offsets, but in the case when one input metric is offset and another is not, it is necessary.

@courtneyholcomb courtneyholcomb requested review from tlento and plypaul and removed request for tlento December 7, 2023 22:51
@cla-bot cla-bot bot added the cla:yes label Dec 7, 2023
Copy link
Contributor

@tlento tlento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

I'm a little wary of these changes because the inlined special casing is hard to reason about. Looking at the snapshots it seems ok, but I think future readers will struggle.

That said, it seems like a lot of this is going to conflict with the approach @plypaul is using in his recent PRs, so some coordination seems in order there. In theory it should be straightforward to control when these time constraint filters get applied using the resolvers, but I don't know if all of the relevant handlers are built out for time constraints specifically.

Comment on lines +30 to +38
ON
(
DATE_TRUNC(bookings_source_src_10001.ds, day) <= subq_15.ds
) AND (
DATE_TRUNC(bookings_source_src_10001.ds, day) > DATE_SUB(CAST(subq_15.ds AS DATETIME), INTERVAL 2 day)
)
) subq_16
ON
DATE_SUB(CAST(subq_17.metric_time__day AS DATETIME), INTERVAL 2 day) = subq_16.metric_time__day
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all makes my head hurt, but I think it is correct - we query everything with a 2 day expansion at the start window, then we offset everything by 2 days and use the INNER JOIN to constrain the output times. And also have a where clause for that, but that's fine.

@courtneyholcomb courtneyholcomb merged commit edbd6e9 into main Dec 15, 2023
9 checks passed
@courtneyholcomb courtneyholcomb deleted the court/time-offset-time-constraint branch December 15, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SL-1357] [Bug] Time constraint should be removed in metric subquery for time offset metrics
3 participants