Skip to content

Commit

Permalink
Update query snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 26, 2024
1 parent bc675e7 commit 7f1621d
Show file tree
Hide file tree
Showing 6 changed files with 1,235 additions and 481 deletions.
97 changes: 56 additions & 41 deletions ee/clickhouse/queries/test/__snapshots__/test_retention.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_0"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -63,7 +64,6 @@
# ---
# name: TestClickhouseRetention.test_groups_aggregating_person_on_events.1
'''

SELECT actor_id,
groupArray(actor_activity.intervals_from_base) AS appearances
FROM
Expand Down Expand Up @@ -98,9 +98,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_0"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand All @@ -116,7 +117,9 @@
OR breakdown_values = breakdown_values_filter)
AND (selected_interval is NULL
OR intervals_from_base = selected_interval) ) AS actor_activity
GROUP BY actor_id
GROUP BY actor_id -- make sure we have stable ordering/pagination
-- NOTE: relies on ids being monotonic

ORDER BY length(appearances) DESC, actor_id
LIMIT 100
OFFSET 0
Expand Down Expand Up @@ -156,9 +159,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_1"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -218,9 +222,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_0"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -248,7 +253,6 @@
# ---
# name: TestClickhouseRetention.test_groups_aggregating_person_on_events_materialized.1
'''

SELECT actor_id,
groupArray(actor_activity.intervals_from_base) AS appearances
FROM
Expand Down Expand Up @@ -283,9 +287,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_0"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand All @@ -301,7 +306,9 @@
OR breakdown_values = breakdown_values_filter)
AND (selected_interval is NULL
OR intervals_from_base = selected_interval) ) AS actor_activity
GROUP BY actor_id
GROUP BY actor_id -- make sure we have stable ordering/pagination
-- NOTE: relies on ids being monotonic

ORDER BY length(appearances) DESC, actor_id
LIMIT 100
OFFSET 0
Expand Down Expand Up @@ -341,9 +348,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_1"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -417,9 +425,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (has(['technology'], replaceRegexpAll(JSONExtractRaw(group_properties_0, 'industry'), '^"|"$', '')))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -493,9 +502,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (JSONHas(group_properties_0, 'industry'))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -595,9 +605,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-12 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-06-19 00:00:00', 'UTC')
AND (JSONHas(group_properties_0, 'industry'))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand Down Expand Up @@ -625,7 +636,6 @@
# ---
# name: TestClickhouseRetention.test_groups_in_period_person_on_events
'''

SELECT actor_id,
groupArray(actor_activity.intervals_from_base) AS appearances
FROM
Expand Down Expand Up @@ -660,9 +670,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_0"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand All @@ -678,15 +689,16 @@
OR breakdown_values = breakdown_values_filter)
AND (selected_interval is NULL
OR intervals_from_base = selected_interval) ) AS actor_activity
GROUP BY actor_id
GROUP BY actor_id -- make sure we have stable ordering/pagination
-- NOTE: relies on ids being monotonic

ORDER BY length(appearances) DESC, actor_id
LIMIT 100
OFFSET 0
'''
# ---
# name: TestClickhouseRetention.test_groups_in_period_person_on_events_materialized
'''

SELECT actor_id,
groupArray(actor_activity.intervals_from_base) AS appearances
FROM
Expand Down Expand Up @@ -721,9 +733,10 @@
AND toDateTime(e.timestamp) >= toDateTime('2020-06-07 00:00:00', 'UTC')
AND toDateTime(e.timestamp) <= toDateTime('2020-07-27 00:00:00', 'UTC')
AND (NOT has([''], "$group_0"))
AND notEmpty(e.person_id) ) SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
AND notEmpty(e.person_id) ) -- Wrap such that CTE is shared across both sides of the union
SELECT DISTINCT breakdown_values,
intervals_from_base,
actor_id
FROM
(SELECT target_event.breakdown_values AS breakdown_values,
datediff(period, target_event.event_date, returning_event.event_date) AS intervals_from_base,
Expand All @@ -739,7 +752,9 @@
OR breakdown_values = breakdown_values_filter)
AND (selected_interval is NULL
OR intervals_from_base = selected_interval) ) AS actor_activity
GROUP BY actor_id
GROUP BY actor_id -- make sure we have stable ordering/pagination
-- NOTE: relies on ids being monotonic

ORDER BY length(appearances) DESC, actor_id
LIMIT 100
OFFSET 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,36 @@
FROM
(SELECT *
FROM
(SELECT toUInt16(0) AS total,
ticks.day_start as day_start,
breakdown_value
(-- Create a table with 1 row for each interval for the requested date range
-- This acts as a method of zero filling, i.e. when there are no data points
-- for a given interval, we'll still have a row for the group by interval with
-- a 0 value.
--
-- It's essentially a cross product of graph "ticks" and breakdown values.
--
-- TODO: we're relying on num_intervals, seconds_int_interval etc. being passed
-- in as a parameter. To reduce the coupling between here and the
-- calling code, we could perform calculations for these within the query
-- itself based on date_to/date_from. We could also pass in the intervals
-- explicitly, although we'll be relying on the date handling between python
-- and ClickHouse to be the same.
--
-- NOTE: there is the ORDER BY ... WITH FILL Expression but I'm not sure how we'd
-- handle the edge cases:
--
-- https://clickhouse.com/docs/en/sql-reference/statements/select/order-by/#orderby-with-fill
--
SELECT toUInt16(0) AS total,
ticks.day_start as day_start,
breakdown_value
FROM
(SELECT toStartOfDay(toDateTime('2020-01-06 00:00:00', 'UTC')) - toIntervalDay(number) as day_start
(-- Generates all the intervals/ticks in the date range
-- NOTE: we build this range by including successive intervals back from the
-- upper bound, then including the lower bound in the query also.
SELECT toStartOfDay(toDateTime('2020-01-06 00:00:00', 'UTC')) - toIntervalDay(number) as day_start
FROM numbers(6)
UNION ALL SELECT toStartOfDay(toDateTime('2020-01-01 00:00:00', 'UTC')) as day_start) as ticks
UNION ALL SELECT toStartOfDay(toDateTime('2020-01-01 00:00:00', 'UTC')) as day_start) as ticks -- Zero fill for all values for the specified breakdown

CROSS JOIN
(SELECT breakdown_value
FROM
Expand Down
Loading

0 comments on commit 7f1621d

Please sign in to comment.