Skip to content

Commit

Permalink
chore(trends): sorts out some dead code in the trends tests (#18887)
Browse files Browse the repository at this point in the history
* Sorts out some dead code in the trends tests

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Gilbert09 and github-actions[bot] authored Nov 24, 2023
1 parent 4387429 commit 984bef9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@
WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 13:01:01', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), ifNull(in(e__pdi.person_id,
(SELECT cohortpeople.person_id
FROM cohortpeople
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 35))
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 37))
GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version
HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0))), 0)))
GROUP BY value
Expand Down Expand Up @@ -1607,7 +1607,7 @@
WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 13:01:01', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), ifNull(in(e__pdi.person_id,
(SELECT cohortpeople.person_id
FROM cohortpeople
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 35))
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 37))
GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version
HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0))), 0)), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', ''), 'value'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', ''), 'other_value'), 0)))
GROUP BY day_start,
Expand Down Expand Up @@ -1652,7 +1652,7 @@
WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 13:01:01', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), in(e.person_id,
(SELECT cohortpeople.person_id
FROM cohortpeople
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 36))
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 38))
GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version
HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0)))))
GROUP BY value
Expand Down Expand Up @@ -1692,7 +1692,7 @@
WHERE and(equals(e.team_id, 2), greaterOrEquals(toTimeZone(e.timestamp, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2019-12-28 13:01:01', 6, 'UTC')))), lessOrEquals(toTimeZone(e.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-04 23:59:59', 6, 'UTC'))), and(equals(e.event, 'sign up'), in(e.person_id,
(SELECT cohortpeople.person_id
FROM cohortpeople
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 36))
WHERE and(equals(cohortpeople.team_id, 2), equals(cohortpeople.cohort_id, 38))
GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version
HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0)))), or(isNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', '')), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', ''), 'value'), 0), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$some_property'), ''), 'null'), '^"|"$', ''), 'other_value'), 0)))
GROUP BY day_start,
Expand Down
51 changes: 23 additions & 28 deletions posthog/hogql_queries/insights/trends/test/test_trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ def convert_filter_to_trends_query(filter: Filter) -> TrendsQuery:
kind="TrendsQuery",
filterTestAccounts=filter.filter_test_accounts,
dateRange=DateRange(date_from=filter_as_dict.get("date_from"), date_to=filter_as_dict.get("date_to")),
# dateRange=DateRange(
# date_from=filter.date_from.isoformat() if filter.date_from is not None else "all",
# date_to=filter.date_to.isoformat() if filter.date_to is not None else None,
# ),
samplingFactor=filter.sampling_factor,
aggregation_group_type_index=filter.aggregation_group_type_index,
breakdown=BreakdownFilter(
Expand Down Expand Up @@ -4423,34 +4419,33 @@ def test_breakdown_by_person_property_pie_with_event_dau_filter(self):
self.assertDictContainsSubset({"breakdown_value": "person1", "aggregated_value": 1}, event_response[0])
self.assertDictContainsSubset({"breakdown_value": "person2", "aggregated_value": 1}, event_response[1])

# TODO: test_account_filters conversion
# @also_test_with_materialized_columns(person_properties=["name"])
# def test_filter_test_accounts_cohorts(self):
# self._create_person(team_id=self.team.pk, distinct_ids=["person_1"], properties={"name": "John"})
# self._create_person(team_id=self.team.pk, distinct_ids=["person_2"], properties={"name": "Jane"})
@also_test_with_materialized_columns(person_properties=["name"])
def test_filter_test_accounts_cohorts(self):
self._create_person(team_id=self.team.pk, distinct_ids=["person_1"], properties={"name": "John"})
self._create_person(team_id=self.team.pk, distinct_ids=["person_2"], properties={"name": "Jane"})

# self._create_event(event="event_name", team=self.team, distinct_id="person_1")
# self._create_event(event="event_name", team=self.team, distinct_id="person_2")
# self._create_event(event="event_name", team=self.team, distinct_id="person_2")
self._create_event(event="event_name", team=self.team, distinct_id="person_1")
self._create_event(event="event_name", team=self.team, distinct_id="person_2")
self._create_event(event="event_name", team=self.team, distinct_id="person_2")

# cohort = _create_cohort(
# team=self.team,
# name="cohort1",
# groups=[{"properties": [{"key": "name", "value": "Jane", "type": "person"}]}],
# )
# self.team.test_account_filters = [{"key": "id", "value": cohort.pk, "type": "cohort"}]
# self.team.save()
cohort = _create_cohort(
team=self.team,
name="cohort1",
groups=[{"properties": [{"key": "name", "value": "Jane", "type": "person"}]}],
)
self.team.test_account_filters = [{"key": "id", "value": cohort.pk, "type": "cohort"}]
self.team.save()

# response = self._run(
# Filter(
# data={"events": [{"id": "event_name"}], "filter_test_accounts": True},
# team=self.team,
# ),
# self.team,
# )
response = self._run(
Filter(
data={"events": [{"id": "event_name"}], "filter_test_accounts": True},
team=self.team,
),
self.team,
)

# self.assertEqual(response[0]["count"], 2)
# self.assertEqual(response[0]["data"][-1], 2)
self.assertEqual(response[0]["count"], 2)
self.assertEqual(response[0]["data"][-1], 2)

def test_filter_by_precalculated_cohort(self):
self._create_person(team_id=self.team.pk, distinct_ids=["person_1"], properties={"name": "John"})
Expand Down

0 comments on commit 984bef9

Please sign in to comment.