Skip to content

Commit

Permalink
fix(insights): hogql stickiness interval ranges (#20190)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra authored Feb 8, 2024
1 parent 438d31c commit 82064e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions posthog/hogql_queries/insights/stickiness_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def to_query(self) -> List[ast.SelectQuery]: # type: ignore

interval_addition = ast.Call(
name=f"toInterval{date_range.interval_name.capitalize()}",
args=[ast.Constant(value=0 if date_range.interval_name == "week" else 1)],
args=[ast.Constant(value=1)],
)

select_query = parse_select(
Expand All @@ -146,7 +146,7 @@ def to_query(self) -> List[ast.SelectQuery]: # type: ignore
SELECT sum(aggregation_target) as aggregation_target, num_intervals
FROM (
SELECT 0 as aggregation_target, (number + 1) as num_intervals
FROM numbers(dateDiff({interval}, {date_from}, {date_to} + {interval_addition}))
FROM numbers(dateDiff({interval}, {date_from_start_of_interval}, {date_to_start_of_interval} + {interval_addition}))
UNION ALL
{events_query}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ def test_interval_week(self):
assert result["days"] == [1, 2, 3]
assert result["data"] == [0, 0, 2]

def test_interval_full_weeks(self):
self._create_test_events()

with freeze_time("2020-01-23T12:00:00Z"):
response = self._run_query(interval=IntervalType.week, date_from="-30d", date_to="now")

result = response.results[0]

assert result["label"] == "$pageview"
assert result["labels"] == ["1 week", "2 weeks", "3 weeks", "4 weeks", "5 weeks"]
assert result["days"] == [1, 2, 3, 4, 5]
assert result["data"] == [0, 0, 2, 0, 0]

def test_interval_month(self):
self._create_test_events()

Expand Down

0 comments on commit 82064e9

Please sign in to comment.