Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/hogql-always-alias' into hogql-a…
Browse files Browse the repository at this point in the history
…lways-alias
  • Loading branch information
mariusandra committed Dec 15, 2023
2 parents 6d6962e + e013dde commit 5351bc0
Show file tree
Hide file tree
Showing 7 changed files with 562 additions and 548 deletions.
108 changes: 54 additions & 54 deletions posthog/api/test/__snapshots__/test_query.ambr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# name: TestQuery.test_event_property_filter
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -18,8 +18,8 @@
# name: TestQuery.test_event_property_filter.1
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -35,8 +35,8 @@
# name: TestQuery.test_event_property_filter.2
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -52,8 +52,8 @@
# name: TestQuery.test_event_property_filter_materialized
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -69,8 +69,8 @@
# name: TestQuery.test_event_property_filter_materialized.1
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -86,8 +86,8 @@
# name: TestQuery.test_event_property_filter_materialized.2
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -103,7 +103,7 @@
# name: TestQuery.test_events_query_all_time_date
'
/* user_id:0 request:_snapshot_ */
SELECT events.event
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2023-01-12 12:14:05.000000', 6, 'UTC')))
ORDER BY events.event ASC
Expand All @@ -116,7 +116,7 @@
# name: TestQuery.test_events_query_all_time_date.1
'
/* user_id:0 request:_snapshot_ */
SELECT events.event
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2022-01-12 12:14:00.000000', 6, 'UTC')))
ORDER BY events.event ASC
Expand All @@ -129,7 +129,7 @@
# name: TestQuery.test_events_query_all_time_date.2
'
/* user_id:0 request:_snapshot_ */
SELECT events.event
SELECT events.event AS event
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2022-01-01 00:00:00.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2019-01-12 12:14:00.000000', 6, 'UTC')))
ORDER BY events.event ASC
Expand All @@ -142,8 +142,8 @@
# name: TestQuery.test_full_hogql_query
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key
FROM events
WHERE equals(events.team_id, 2)
Expand All @@ -156,8 +156,8 @@
# name: TestQuery.test_full_hogql_query_materialized
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key
FROM events
WHERE equals(events.team_id, 2)
Expand All @@ -184,9 +184,9 @@
# name: TestQuery.test_full_hogql_query_view.1
'
/* user_id:0 request:_snapshot_ */
SELECT event_view.event,
event_view.distinct_id,
event_view.key
SELECT event_view.event AS event,
event_view.distinct_id AS distinct_id,
event_view.key AS key
FROM
(SELECT events.event AS event,
events.distinct_id AS distinct_id,
Expand All @@ -202,8 +202,8 @@
# name: TestQuery.test_hogql_property_filter
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -219,8 +219,8 @@
# name: TestQuery.test_hogql_property_filter.1
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -236,8 +236,8 @@
# name: TestQuery.test_hogql_property_filter.2
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -253,8 +253,8 @@
# name: TestQuery.test_hogql_property_filter.3
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -270,8 +270,8 @@
# name: TestQuery.test_hogql_property_filter_materialized
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -287,8 +287,8 @@
# name: TestQuery.test_hogql_property_filter_materialized.1
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -304,8 +304,8 @@
# name: TestQuery.test_hogql_property_filter_materialized.2
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -321,8 +321,8 @@
# name: TestQuery.test_hogql_property_filter_materialized.3
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -338,8 +338,8 @@
# name: TestQuery.test_person_property_filter
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
Expand All @@ -352,11 +352,11 @@
GROUP BY person_distinct_id2.distinct_id
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id)
INNER JOIN
(SELECT person.id,
(SELECT person.id AS id,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'email'), ''), 'null'), '^"|"$', '') AS properties___email
FROM person
WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version),
(SELECT person.id, max(person.version) AS version
(SELECT person.id AS id, max(person.version) AS version
FROM person
WHERE equals(person.team_id, 2)
GROUP BY person.id
Expand All @@ -372,8 +372,8 @@
# name: TestQuery.test_person_property_filter_materialized
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
SELECT events.event AS event,
events.distinct_id AS distinct_id,
nullIf(nullIf(events.mat_key, ''), 'null') AS key,
'a%sd',
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(nullIf(nullIf(events.mat_key, ''), 'null')), ''))
Expand All @@ -386,11 +386,11 @@
GROUP BY person_distinct_id2.distinct_id
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id)
INNER JOIN
(SELECT person.id,
(SELECT person.id AS id,
nullIf(nullIf(person.pmat_email, ''), 'null') AS properties___email
FROM person
WHERE and(equals(person.team_id, 2), ifNull(in(tuple(person.id, person.version),
(SELECT person.id, max(person.version) AS version
(SELECT person.id AS id, max(person.version) AS version
FROM person
WHERE equals(person.team_id, 2)
GROUP BY person.id
Expand Down Expand Up @@ -468,9 +468,9 @@
# name: TestQuery.test_select_event_person
'
/* user_id:0 request:_snapshot_ */
SELECT events.event,
events.distinct_id,
events.distinct_id
SELECT events.event AS event,
events.distinct_id AS distinct_id,
events.distinct_id AS distinct_id
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
ORDER BY events.event ASC
Expand All @@ -484,8 +484,8 @@
'
/* user_id:0 request:_snapshot_ */
SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '') AS key,
events.event,
events.distinct_id,
events.event AS event,
events.distinct_id AS distinct_id,
concat(ifNull(toString(events.event), ''), ' ', ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', '')), ''))
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
Expand All @@ -500,7 +500,7 @@
'
/* user_id:0 request:_snapshot_ */
SELECT tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC')),
events.event
events.event AS event
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
ORDER BY tuple(events.uuid, events.event, events.properties, toTimeZone(events.timestamp, 'UTC'), events.team_id, events.distinct_id, events.elements_chain, toTimeZone(events.created_at, 'UTC')) ASC
Expand All @@ -514,7 +514,7 @@
'
/* user_id:0 request:_snapshot_ */
SELECT count(),
events.event
events.event AS event
FROM events
WHERE and(equals(events.team_id, 2), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
GROUP BY events.event
Expand All @@ -529,7 +529,7 @@
'
/* user_id:0 request:_snapshot_ */
SELECT count(),
events.event
events.event AS event
FROM events
WHERE and(equals(events.team_id, 2), or(equals(events.event, 'sign up'), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'key'), ''), 'null'), '^"|"$', ''), '%val2'), 0)), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
GROUP BY events.event
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/test/__snapshots__/test_query.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@
FROM (
SELECT count(*) AS count, event
FROM events
WHERE equals(properties.random_uuid, '016f8cc0-2400-0017-1ec4-f9ee72932a04')
WHERE equals(properties.random_uuid, '016f8cc0-2400-0000-efde-64d93d4f4544')
GROUP BY event) AS c
GROUP BY count, event
LIMIT 100
Expand Down
28 changes: 14 additions & 14 deletions posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
FROM events LEFT JOIN (
SELECT cohortpeople.person_id AS person_id, 1 AS matched
FROM cohortpeople
WHERE and(equals(cohortpeople.team_id, 420), equals(cohortpeople.cohort_id, 10))
WHERE and(equals(cohortpeople.team_id, 420), equals(cohortpeople.cohort_id, 1))
GROUP BY cohortpeople.person_id, cohortpeople.cohort_id, cohortpeople.version
HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0)) AS in_cohort__10 ON equals(in_cohort__10.person_id, events.person_id)
WHERE and(equals(events.team_id, 420), ifNull(equals(in_cohort__10.matched, 1), 0), equals(events.event, %(hogql_val_0)s))
HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0)) AS in_cohort__1 ON equals(in_cohort__1.person_id, events.person_id)
WHERE and(equals(events.team_id, 420), ifNull(equals(in_cohort__1.matched, 1), 0), equals(events.event, %(hogql_val_0)s))
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1

Expand All @@ -19,10 +19,10 @@
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
FROM raw_cohort_people
WHERE equals(cohort_id, 10)
WHERE equals(cohort_id, 1)
GROUP BY person_id, cohort_id, version
HAVING greater(sum(sign), 0)) AS in_cohort__10 ON equals(in_cohort__10.person_id, person_id)
WHERE and(equals(in_cohort__10.matched, 1), equals(event, '018c6a03-e2f4-0000-1b43-0b8b068eedf9'))
HAVING greater(sum(sign), 0)) AS in_cohort__1 ON equals(in_cohort__1.person_id, person_id)
WHERE and(equals(in_cohort__1.matched, 1), equals(event, '018c6ca4-34e1-0000-d14a-902570c098a4'))
LIMIT 100
'
---
Expand All @@ -34,8 +34,8 @@
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS person_id, 1 AS matched
FROM person_static_cohort
WHERE and(equals(person_static_cohort.team_id, 420), equals(person_static_cohort.cohort_id, 11))) AS in_cohort__11 ON equals(in_cohort__11.person_id, events.person_id)
WHERE and(equals(events.team_id, 420), ifNull(equals(in_cohort__11.matched, 1), 0))
WHERE and(equals(person_static_cohort.team_id, 420), equals(person_static_cohort.cohort_id, 2))) AS in_cohort__2 ON equals(in_cohort__2.person_id, events.person_id)
WHERE and(equals(events.team_id, 420), ifNull(equals(in_cohort__2.matched, 1), 0))
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1

Expand All @@ -45,8 +45,8 @@
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
FROM static_cohort_people
WHERE equals(cohort_id, 11)) AS in_cohort__11 ON equals(in_cohort__11.person_id, person_id)
WHERE equals(in_cohort__11.matched, 1)
WHERE equals(cohort_id, 2)) AS in_cohort__2 ON equals(in_cohort__2.person_id, person_id)
WHERE equals(in_cohort__2.matched, 1)
LIMIT 100
'
---
Expand All @@ -58,8 +58,8 @@
FROM events LEFT JOIN (
SELECT person_static_cohort.person_id AS person_id, 1 AS matched
FROM person_static_cohort
WHERE and(equals(person_static_cohort.team_id, 420), equals(person_static_cohort.cohort_id, 12))) AS in_cohort__12 ON equals(in_cohort__12.person_id, events.person_id)
WHERE and(equals(events.team_id, 420), ifNull(equals(in_cohort__12.matched, 1), 0))
WHERE and(equals(person_static_cohort.team_id, 420), equals(person_static_cohort.cohort_id, 3))) AS in_cohort__3 ON equals(in_cohort__3.person_id, events.person_id)
WHERE and(equals(events.team_id, 420), ifNull(equals(in_cohort__3.matched, 1), 0))
LIMIT 100
SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1

Expand All @@ -69,8 +69,8 @@
FROM events LEFT JOIN (
SELECT person_id, 1 AS matched
FROM static_cohort_people
WHERE equals(cohort_id, 12)) AS in_cohort__12 ON equals(in_cohort__12.person_id, person_id)
WHERE equals(in_cohort__12.matched, 1)
WHERE equals(cohort_id, 3)) AS in_cohort__3 ON equals(in_cohort__3.person_id, person_id)
WHERE equals(in_cohort__3.matched, 1)
LIMIT 100
'
---
Loading

0 comments on commit 5351bc0

Please sign in to comment.