Skip to content

Commit

Permalink
fix: set snapshot dates
Browse files Browse the repository at this point in the history
  • Loading branch information
skoob13 committed Jan 15, 2025
1 parent 335ea23 commit 42ea56d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
WHERE equals(person.team_id, 99999)
GROUP BY person.id
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-06 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-14 20:58:59', 6, 'UTC'))))
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-08 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-16 00:10:59', 6, 'UTC'))))
GROUP BY id
ORDER BY trace_timestamp DESC
LIMIT 5
Expand Down Expand Up @@ -118,7 +118,7 @@
WHERE equals(person.team_id, 99999)
GROUP BY person.id
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-06 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-14 20:58:59', 6, 'UTC'))))
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-08 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-16 00:10:59', 6, 'UTC'))))
GROUP BY id
ORDER BY trace_timestamp DESC
LIMIT 5
Expand Down Expand Up @@ -162,7 +162,7 @@
WHERE equals(person.team_id, 99999)
GROUP BY person.id
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-06 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-14 20:58:59', 6, 'UTC'))))
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-08 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-16 00:10:59', 6, 'UTC'))))
GROUP BY id
ORDER BY trace_timestamp DESC
LIMIT 5
Expand Down Expand Up @@ -206,7 +206,7 @@
WHERE equals(person.team_id, 99999)
GROUP BY person.id
HAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0)))), 0)) SETTINGS optimize_aggregation_in_order=1) AS events__person ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), events__person.id)
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-06 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-14 20:58:59', 6, 'UTC'))), ifNull(equals(id, 'trace1'), 0))
WHERE and(equals(events.team_id, 99999), equals(events.event, '$ai_generation'), greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-08 23:50:00', 6, 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2025-01-16 00:10:59', 6, 'UTC'))), ifNull(equals(id, 'trace1'), 0))
GROUP BY id
ORDER BY trace_timestamp DESC
LIMIT 101
Expand Down
5 changes: 4 additions & 1 deletion posthog/hogql_queries/ai/test/test_traces_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def test_field_mapping(self):
},
)

@freeze_time("2025-01-16T00:00:00Z")
@snapshot_clickhouse_queries
def test_trace_id_filter(self):
_create_person(distinct_ids=["person1"], team=self.team)
Expand All @@ -252,6 +253,7 @@ def test_trace_id_filter(self):
self.assertEqual(len(response.results), 1)
self.assertEqual(response.results[0].id, "trace1")

@freeze_time("2025-01-16T00:00:00Z")
@snapshot_clickhouse_queries
def test_pagination(self):
_create_person(distinct_ids=["person1"], team=self.team)
Expand All @@ -261,8 +263,8 @@ def test_pagination(self):
distinct_id="person1" if i % 2 == 0 else "person2",
team=self.team,
trace_id=f"trace_{i}",
timestamp=datetime(2025, 1, 15, i),
)

response = TracesQueryRunner(team=self.team, query=TracesQuery(limit=4, offset=0)).calculate()
self.assertEqual(response.hasMore, True)
self.assertEqual(len(response.results), 5)
Expand All @@ -286,6 +288,7 @@ def test_pagination(self):
self.assertEqual(len(response.results), 1)
self.assertEqual(response.results[0].id, "trace_0")

@freeze_time("2025-01-16T00:00:00Z")
def test_maps_all_fields(self):
_create_person(distinct_ids=["person1"], team=self.team)
_create_ai_generation_event(
Expand Down

0 comments on commit 42ea56d

Please sign in to comment.