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

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

Closed
2 tasks done
courtneyholcomb opened this issue Dec 5, 2023 · 1 comment · Fixed by #932
Closed
2 tasks done
Assignees
Labels
bug Something isn't working linear triage Tasks that need to be triaged Urgent Created by Linear-GitHub Sync

Comments

@courtneyholcomb
Copy link
Contributor

courtneyholcomb commented Dec 5, 2023

Is this a new bug in metricflow?

  • I believe this is a new bug in metricflow
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

In time offset queries, the time constraint is applied to both the time spine subquery and the metric subquery. Here's the current SQL:

-- Compute Metrics via Expressions
SELECT
  metric_time__day
  , bookings_2_weeks_ago AS bookings_2_weeks_ago
FROM (
  -- Join to Time Spine Dataset
  -- Pass Only Elements:
  --   ['bookings', 'metric_time__day']
  -- Aggregate Measures
  -- Compute Metrics via Expressions
  SELECT
    subq_12.metric_time__day AS metric_time__day
    , SUM(subq_11.bookings) AS bookings_2_weeks_ago
  FROM (
    -- Date Spine
    SELECT
      ds AS metric_time__day
    FROM ***************************.mf_time_spine subq_13
    WHERE ds BETWEEN '2020-01-01' AND '2020-01-01'
  ) subq_12
  INNER JOIN (
    -- Read Elements From Semantic Model 'bookings_source'
    -- Metric Time Dimension 'ds'
    -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
    SELECT
      DATE_TRUNC('day', ds) AS metric_time__day
      , 1 AS bookings
    FROM ***************************.fct_bookings bookings_source_src_10001
    WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-01'
  ) subq_11
  ON
    subq_12.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day
  GROUP BY
    subq_12.metric_time__day
) subq_17

Expected Behavior

Since the metric dates will be offset, the time constraint should not be applied in that subquery. The inner join to the time spine query will effectively apply that time constraint, instead.

-- Compute Metrics via Expressions
SELECT
  metric_time__day
  , bookings_2_weeks_ago AS bookings_2_weeks_ago
FROM (
  -- Join to Time Spine Dataset
  -- Pass Only Elements:
  --   ['bookings', 'metric_time__day']
  -- Aggregate Measures
  -- Compute Metrics via Expressions
  SELECT
    subq_12.metric_time__day AS metric_time__day
    , SUM(subq_11.bookings) AS bookings_2_weeks_ago
  FROM (
    -- Date Spine
    SELECT
      ds AS metric_time__day
    FROM ***************************.mf_time_spine subq_13
    WHERE ds BETWEEN '2020-01-01' AND '2020-01-01'
  ) subq_12
  INNER JOIN (
    -- Read Elements From Semantic Model 'bookings_source'
    -- Metric Time Dimension 'ds'
    -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
    SELECT
      DATE_TRUNC('day', ds) AS metric_time__day
      , 1 AS bookings
    FROM ***************************.fct_bookings bookings_source_src_10001
  ) subq_11
  ON
    subq_12.metric_time__day - INTERVAL 14 day = subq_11.metric_time__day
  GROUP BY
    subq_12.metric_time__day
) subq_17

Steps To Reproduce

Query a time offset metric with a time constraint.

Relevant log output

No response

Environment

- OS:
- Python:
- dbt:
- metricflow:

Which database are you using?

No response

Additional Context

No response

SL-1357

@courtneyholcomb courtneyholcomb added bug Something isn't working triage Tasks that need to be triaged labels Dec 5, 2023
@courtneyholcomb courtneyholcomb changed the title [Bug] Time constraint should be removed in metric subquery for time offset metrics [SL-1357] [Bug] Time constraint should be removed in metric subquery for time offset metrics Dec 5, 2023
@courtneyholcomb courtneyholcomb added linear Metricflow Created by Linear-GitHub Sync High priority Created by Linear-GitHub Sync labels Dec 5, 2023
@courtneyholcomb courtneyholcomb self-assigned this Dec 5, 2023
@courtneyholcomb courtneyholcomb added Urgent Created by Linear-GitHub Sync and removed High priority Created by Linear-GitHub Sync labels Dec 6, 2023
@courtneyholcomb courtneyholcomb removed the Metricflow Created by Linear-GitHub Sync label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linear triage Tasks that need to be triaged Urgent Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant