Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hogql): always provide an alias when printing out clickhouse #19342

Merged
merged 66 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
9eea1c9
feat(hogql): always provide an alias when printing out clickhouse
mariusandra Dec 14, 2023
55d8662
Update query snapshots
github-actions[bot] Dec 14, 2023
629bb0a
Update query snapshots
github-actions[bot] Dec 14, 2023
27efddf
Update query snapshots
github-actions[bot] Dec 14, 2023
20e9f2e
Update query snapshots
github-actions[bot] Dec 14, 2023
daa43c7
Update query snapshots
github-actions[bot] Dec 14, 2023
cf134a3
Update query snapshots
github-actions[bot] Dec 14, 2023
b148025
Update query snapshots
github-actions[bot] Dec 14, 2023
f375a17
Update query snapshots
github-actions[bot] Dec 14, 2023
33f68dd
Update query snapshots
github-actions[bot] Dec 14, 2023
d610de9
Update query snapshots
github-actions[bot] Dec 14, 2023
7307b02
Update query snapshots
github-actions[bot] Dec 14, 2023
92cb1cb
Update query snapshots
github-actions[bot] Dec 14, 2023
e4e492c
Update query snapshots
github-actions[bot] Dec 14, 2023
97fee96
Update query snapshots
github-actions[bot] Dec 14, 2023
c58fd85
Update query snapshots
github-actions[bot] Dec 14, 2023
be853b7
Update query snapshots
github-actions[bot] Dec 15, 2023
8f00943
Update query snapshots
github-actions[bot] Dec 15, 2023
fcd3d25
Update query snapshots
github-actions[bot] Dec 15, 2023
9a8bbca
Update query snapshots
github-actions[bot] Dec 15, 2023
64b9950
Update query snapshots
github-actions[bot] Dec 15, 2023
9223935
Update query snapshots
github-actions[bot] Dec 15, 2023
a4e3a59
Update query snapshots
github-actions[bot] Dec 15, 2023
13f7ac6
Update query snapshots
github-actions[bot] Dec 15, 2023
b72a63b
Update query snapshots
github-actions[bot] Dec 15, 2023
336b422
Update query snapshots
github-actions[bot] Dec 15, 2023
ca734ee
Update query snapshots
github-actions[bot] Dec 15, 2023
2c7d5cb
Update query snapshots
github-actions[bot] Dec 15, 2023
599317d
Update query snapshots
github-actions[bot] Dec 15, 2023
3e2de37
Update query snapshots
github-actions[bot] Dec 15, 2023
8da9f6a
Update query snapshots
github-actions[bot] Dec 15, 2023
d43df6a
Update query snapshots
github-actions[bot] Dec 15, 2023
cba1976
Update query snapshots
github-actions[bot] Dec 15, 2023
8f7e1e9
Update query snapshots
github-actions[bot] Dec 15, 2023
82f5726
Update query snapshots
github-actions[bot] Dec 15, 2023
7637021
Update query snapshots
github-actions[bot] Dec 15, 2023
c92ede2
Update query snapshots
github-actions[bot] Dec 15, 2023
cc7ee47
Update query snapshots
github-actions[bot] Dec 15, 2023
cb63bc0
Update query snapshots
github-actions[bot] Dec 15, 2023
05653f6
Update query snapshots
github-actions[bot] Dec 15, 2023
e599b38
Update query snapshots
github-actions[bot] Dec 15, 2023
968e1a1
Update query snapshots
github-actions[bot] Dec 15, 2023
6625626
Update query snapshots
github-actions[bot] Dec 15, 2023
6ed8dd4
Update query snapshots
github-actions[bot] Dec 15, 2023
0c19700
Update query snapshots
github-actions[bot] Dec 15, 2023
08b5a3f
Update query snapshots
github-actions[bot] Dec 15, 2023
3b87bde
Update query snapshots
github-actions[bot] Dec 15, 2023
a9aab38
Update query snapshots
github-actions[bot] Dec 15, 2023
d14f417
Update query snapshots
github-actions[bot] Dec 15, 2023
560da2e
Update query snapshots
github-actions[bot] Dec 15, 2023
3fa999c
Update query snapshots
github-actions[bot] Dec 15, 2023
8edc8cf
Update query snapshots
github-actions[bot] Dec 15, 2023
9d32e09
Update query snapshots
github-actions[bot] Dec 15, 2023
e4f0e38
Update query snapshots
github-actions[bot] Dec 15, 2023
7e2351d
Update query snapshots
github-actions[bot] Dec 15, 2023
4ab9680
Update query snapshots
github-actions[bot] Dec 15, 2023
e013dde
Update query snapshots
github-actions[bot] Dec 15, 2023
6d6962e
stable random
mariusandra Dec 15, 2023
5351bc0
Merge remote-tracking branch 'origin/hogql-always-alias' into hogql-a…
mariusandra Dec 15, 2023
1f43109
Update query snapshots
github-actions[bot] Dec 15, 2023
a7aa9e4
Merge branch 'master' into hogql-always-alias
mariusandra Dec 18, 2023
196fd6d
fix tests
mariusandra Dec 18, 2023
8a3b7f4
Update query snapshots
github-actions[bot] Dec 18, 2023
3a50745
Update query snapshots
github-actions[bot] Dec 18, 2023
8ba8aac
fix test
mariusandra Dec 18, 2023
56547f7
Merge remote-tracking branch 'origin/hogql-always-alias' into hogql-a…
mariusandra Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 5 additions & 5 deletions posthog/api/test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def test_full_hogql_query(self):
@patch("posthog.hogql.constants.DEFAULT_RETURNED_ROWS", 10)
@patch("posthog.hogql.constants.MAX_SELECT_RETURNED_ROWS", 15)
def test_full_hogql_query_limit(self, MAX_SELECT_RETURNED_ROWS=15, DEFAULT_RETURNED_ROWS=10):
random_uuid = str(UUIDT())
random_uuid = f"RANDOM_TEST_ID::{UUIDT()}"
with freeze_time("2020-01-10 12:00:00"):
for _ in range(20):
_create_event(
Expand All @@ -594,7 +594,7 @@ def test_full_hogql_query_limit(self, MAX_SELECT_RETURNED_ROWS=15, DEFAULT_RETUR
@patch("posthog.hogql.constants.DEFAULT_RETURNED_ROWS", 10)
@patch("posthog.hogql.constants.MAX_SELECT_RETURNED_ROWS", 15)
def test_full_hogql_query_limit_exported(self, MAX_SELECT_RETURNED_ROWS=15, DEFAULT_RETURNED_ROWS=10):
random_uuid = str(UUIDT())
random_uuid = f"RANDOM_TEST_ID::{UUIDT()}"
with freeze_time("2020-01-10 12:00:00"):
for _ in range(20):
_create_event(
Expand All @@ -619,7 +619,7 @@ def test_full_hogql_query_limit_exported(self, MAX_SELECT_RETURNED_ROWS=15, DEFA
@patch("posthog.hogql.constants.DEFAULT_RETURNED_ROWS", 10)
@patch("posthog.hogql.constants.MAX_SELECT_RETURNED_ROWS", 15)
def test_full_events_query_limit(self, MAX_SELECT_RETURNED_ROWS=15, DEFAULT_RETURNED_ROWS=10):
random_uuid = str(UUIDT())
random_uuid = f"RANDOM_TEST_ID::{UUIDT()}"
with freeze_time("2020-01-10 12:00:00"):
for _ in range(20):
_create_event(
Expand All @@ -645,7 +645,7 @@ def test_full_events_query_limit(self, MAX_SELECT_RETURNED_ROWS=15, DEFAULT_RETU
@patch("posthog.hogql.constants.DEFAULT_RETURNED_ROWS", 10)
@patch("posthog.hogql.constants.MAX_SELECT_RETURNED_ROWS", 15)
def test_full_events_query_limit_exported(self, MAX_SELECT_RETURNED_ROWS=15, DEFAULT_RETURNED_ROWS=10):
random_uuid = str(UUIDT())
random_uuid = f"RANDOM_TEST_ID::{UUIDT()}"
with freeze_time("2020-01-10 12:00:00"):
for _ in range(20):
_create_event(
Expand Down Expand Up @@ -764,7 +764,7 @@ def test_full_hogql_query_view(self):
)

def test_full_hogql_query_values(self):
random_uuid = str(UUIDT())
random_uuid = f"RANDOM_TEST_ID::{UUIDT()}"
with freeze_time("2020-01-10 12:00:00"):
for _ in range(20):
_create_event(
Expand Down
11 changes: 7 additions & 4 deletions posthog/hogql/database/test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_database_with_warehouse_tables(self, patch_execute):

self.assertEqual(
response.clickhouse,
f"SELECT whatever.id FROM s3Cluster('posthog', %(hogql_val_0_sensitive)s, %(hogql_val_3_sensitive)s, %(hogql_val_4_sensitive)s, %(hogql_val_1)s, %(hogql_val_2)s) AS whatever LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1",
f"SELECT whatever.id AS id FROM s3Cluster('posthog', %(hogql_val_0_sensitive)s, %(hogql_val_3_sensitive)s, %(hogql_val_4_sensitive)s, %(hogql_val_1)s, %(hogql_val_2)s) AS whatever LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1",
)

def test_database_group_type_mappings(self):
Expand Down Expand Up @@ -100,17 +100,20 @@ def test_database_expression_fields(self):
query = print_ast(parse_select(sql), context, dialect="clickhouse")
assert (
query
== "SELECT numbers.number, multiply(numbers.number, 2) AS double, plus(plus(1, 1), numbers.number) FROM numbers(2) AS numbers LIMIT 10000"
== "SELECT numbers.number AS number, multiply(numbers.number, 2) AS double, plus(plus(1, 1), numbers.number) FROM numbers(2) AS numbers LIMIT 10000"
), query

sql = "select double from (select double from numbers(2))"
query = print_ast(parse_select(sql), context, dialect="clickhouse")
assert (
query
== "SELECT double FROM (SELECT multiply(numbers.number, 2) AS double FROM numbers(2) AS numbers) LIMIT 10000"
== "SELECT double AS double FROM (SELECT multiply(numbers.number, 2) AS double FROM numbers(2) AS numbers) LIMIT 10000"
), query

# expression fields are not included in select *
sql = "select * from (select * from numbers(2))"
query = print_ast(parse_select(sql), context, dialect="clickhouse")
assert query == "SELECT number FROM (SELECT numbers.number FROM numbers(2) AS numbers) LIMIT 10000", query
assert (
query
== "SELECT number AS number FROM (SELECT numbers.number AS number FROM numbers(2) AS numbers) LIMIT 10000"
), query
Loading
Loading