-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2d706d
commit fdc4f10
Showing
3 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ def test_query(self): | |
"select count(), event from events where properties.random_uuid = {random_uuid} group by event", | ||
placeholders={"random_uuid": ast.Constant(value=random_uuid)}, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [(2, "random event")]) | ||
|
@@ -77,6 +78,7 @@ def test_subquery(self): | |
"select count, event from (select count() as count, event from events where properties.random_uuid = {random_uuid} group by event) group by count, event", | ||
placeholders={"random_uuid": ast.Constant(value=random_uuid)}, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [(2, "random event")]) | ||
|
@@ -90,6 +92,7 @@ def test_subquery_alias(self): | |
"select count, event from (select count(*) as count, event from events where properties.random_uuid = {random_uuid} group by event) as c group by count, event", | ||
placeholders={"random_uuid": ast.Constant(value=random_uuid)}, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [(2, "random event")]) | ||
|
@@ -103,6 +106,7 @@ def test_query_distinct(self): | |
"select distinct properties.sneaky_mail from persons where properties.random_uuid = {random_uuid}", | ||
placeholders={"random_uuid": ast.Constant(value=random_uuid)}, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [("[email protected]",)]) | ||
|
@@ -114,6 +118,7 @@ def test_query_person_distinct_ids(self): | |
response = execute_hogql_query( | ||
f"select distinct person_id, distinct_id from person_distinct_ids", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertTrue(len(response.results) > 0) | ||
|
@@ -125,6 +130,7 @@ def test_query_timings(self): | |
"select count(), event from events where properties.random_uuid = {random_uuid} group by event", | ||
placeholders={"random_uuid": ast.Constant(value=random_uuid)}, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertTrue(isinstance(response.timings, list) and len(response.timings) > 0) | ||
self.assertTrue(isinstance(response.timings[0], QueryTiming)) | ||
|
@@ -145,6 +151,7 @@ def test_query_joins_simple(self): | |
ON p.id = pdi.person_id | ||
""", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -169,6 +176,7 @@ def test_query_joins_pdi(self): | |
ON e.distinct_id = pdi.distinct_id | ||
""", | ||
self.team, | ||
pretty=False, | ||
) | ||
|
||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
|
@@ -182,6 +190,7 @@ def test_query_joins_events_pdi(self): | |
response = execute_hogql_query( | ||
"SELECT event, timestamp, pdi.distinct_id, pdi.person_id FROM events LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -196,6 +205,7 @@ def test_query_joins_events_e_pdi(self): | |
response = execute_hogql_query( | ||
"SELECT event, e.timestamp, e.pdi.distinct_id, pdi.person_id FROM events e LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.hogql, | ||
|
@@ -214,6 +224,7 @@ def test_query_joins_pdi_persons(self): | |
response = execute_hogql_query( | ||
"SELECT pdi.distinct_id, pdi.person.created_at FROM person_distinct_ids pdi LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.hogql, | ||
|
@@ -234,6 +245,7 @@ def test_query_joins_pdi_person_properties(self): | |
response = execute_hogql_query( | ||
"SELECT pdi.distinct_id, pdi.person.properties.sneaky_mail FROM person_distinct_ids pdi LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.hogql, | ||
|
@@ -251,6 +263,7 @@ def test_query_joins_events_pdi_person(self): | |
response = execute_hogql_query( | ||
"SELECT event, timestamp, pdi.distinct_id, pdi.person.id FROM events LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -266,6 +279,7 @@ def test_query_joins_events_pdi_person_properties(self): | |
response = execute_hogql_query( | ||
"SELECT event, timestamp, pdi.distinct_id, pdi.person.properties.sneaky_mail FROM events LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -280,6 +294,7 @@ def test_query_joins_events_pdi_e_person_properties(self): | |
response = execute_hogql_query( | ||
"SELECT event, e.timestamp, pdi.distinct_id, e.pdi.person.properties.sneaky_mail FROM events e LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -294,6 +309,7 @@ def test_query_joins_events_person_properties(self): | |
response = execute_hogql_query( | ||
"SELECT event, e.timestamp, e.pdi.person.properties.sneaky_mail FROM events e LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -306,6 +322,7 @@ def test_query_joins_events_person_properties_in_aggregration(self): | |
response = execute_hogql_query( | ||
"SELECT s.pdi.person.properties.sneaky_mail, count() FROM events s GROUP BY s.pdi.person.properties.sneaky_mail LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "[email protected]") | ||
|
@@ -317,6 +334,7 @@ def test_select_person_on_events(self): | |
response = execute_hogql_query( | ||
"SELECT poe.properties.sneaky_mail, count() FROM events s GROUP BY poe.properties.sneaky_mail LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "[email protected]") | ||
|
@@ -330,6 +348,7 @@ def test_query_select_person_with_joins_without_poe(self): | |
response = execute_hogql_query( | ||
"SELECT event, timestamp, person.id, person.properties.sneaky_mail FROM events LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -345,6 +364,7 @@ def test_query_select_person_with_poe_without_joins(self): | |
response = execute_hogql_query( | ||
"SELECT event, timestamp, person.id, person.properties.sneaky_mail FROM events LIMIT 10", | ||
self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results[0][0], "random event") | ||
|
@@ -403,6 +423,7 @@ def test_prop_cohort_basic(self): | |
self.team, | ||
) | ||
}, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [("$pageview", 2)]) | ||
|
@@ -417,6 +438,7 @@ def test_prop_cohort_basic(self): | |
self.team, | ||
) | ||
}, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [("$pageview", 2)]) | ||
|
@@ -460,6 +482,7 @@ def test_prop_cohort_static(self): | |
self.team, | ||
) | ||
}, | ||
pretty=False, | ||
) | ||
self.assertEqual(response.results, [("$pageview", 1)]) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
|
@@ -474,6 +497,7 @@ def test_prop_cohort_static(self): | |
self.team, | ||
) | ||
}, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
self.assertEqual(response.results, [("$pageview", 1)]) | ||
|
@@ -508,6 +532,7 @@ def test_join_with_property_materialized_session_id(self): | |
response = execute_hogql_query( | ||
"select e.event, s.session_id from events e left join session_replay_events s on s.session_id = e.properties.$session_id where e.properties.$session_id is not null limit 10", | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot | ||
|
@@ -516,6 +541,7 @@ def test_join_with_property_materialized_session_id(self): | |
response = execute_hogql_query( | ||
"select e.event, s.session_id from session_replay_events s left join events e on e.properties.$session_id = s.session_id where e.properties.$session_id is not null limit 10", | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot | ||
|
@@ -551,6 +577,7 @@ def test_join_with_property_not_materialized(self): | |
response = execute_hogql_query( | ||
"select e.event, s.session_id from events e left join session_replay_events s on s.session_id = e.properties.$$$session_id where e.properties.$$$session_id is not null limit 10", | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot | ||
|
@@ -559,6 +586,7 @@ def test_join_with_property_not_materialized(self): | |
response = execute_hogql_query( | ||
"select e.event, s.session_id from session_replay_events s left join events e on e.properties.$$$session_id = s.session_id where e.properties.$$$session_id is not null limit 10", | ||
team=self.team, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot | ||
|
@@ -570,6 +598,7 @@ def test_hogql_lambdas(self): | |
response = execute_hogql_query( | ||
"SELECT arrayMap(x -> x * 2, [1, 2, 3]), 1", | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual(response.results, [([2, 4, 6], 1)]) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
|
@@ -580,6 +609,7 @@ def test_hogql_arrays(self): | |
response = execute_hogql_query( | ||
"SELECT [1, 2, 3], [10,11,12][1]", | ||
team=self.team, | ||
pretty=False, | ||
) | ||
# Following SQL tradition, ClickHouse array indexes start at 1, not from zero. | ||
self.assertEqual(response.results, [([1, 2, 3], 10)]) | ||
|
@@ -607,6 +637,7 @@ def test_tuple_access(self): | |
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.results, | ||
|
@@ -871,6 +902,7 @@ def test_with_pivot_table_1_level(self): | |
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.results, | ||
|
@@ -910,6 +942,7 @@ def test_with_pivot_table_2_levels(self): | |
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.results, | ||
|
@@ -955,7 +988,11 @@ def test_property_access_with_arrays(self): | |
] | ||
columns = ",".join(alternatives) | ||
query = f"SELECT {columns} FROM events WHERE properties.string = '{random_uuid}'" | ||
response = execute_hogql_query(query, team=self.team) | ||
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.clickhouse, | ||
f"SELECT " | ||
|
@@ -1143,6 +1180,7 @@ def test_regex_functions(self): | |
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
|
||
self.assertEqual( | ||
|
@@ -1332,13 +1370,25 @@ def test_hogql_query_filters(self): | |
properties=[EventPropertyFilter(key="index", operator="exact", value="4", type="event")] | ||
) | ||
placeholders = {"distinct_id": ast.Constant(value=random_uuid)} | ||
response = execute_hogql_query(query, team=self.team, filters=filters, placeholders=placeholders) | ||
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
filters=filters, | ||
placeholders=placeholders, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot | ||
self.assertEqual(len(response.results), 1) | ||
|
||
filters.dateRange = DateRange(date_from="2020-01-01", date_to="2020-01-02") | ||
response = execute_hogql_query(query, team=self.team, filters=filters, placeholders=placeholders) | ||
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
filters=filters, | ||
placeholders=placeholders, | ||
pretty=False, | ||
) | ||
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot | ||
assert pretty_print_in_tests(response.hogql, self.team.pk) == self.snapshot | ||
self.assertEqual(len(response.results), 0) | ||
|
@@ -1349,7 +1399,11 @@ def test_hogql_query_filters(self): | |
|
||
def test_hogql_query_filters_empty_true(self): | ||
query = "SELECT event from events where {filters}" | ||
response = execute_hogql_query(query, team=self.team) | ||
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual(response.hogql, "SELECT event FROM events WHERE true LIMIT 100") | ||
|
||
def test_hogql_query_filters_double_error(self): | ||
|
@@ -1380,7 +1434,12 @@ def test_hogql_query_filters_alias(self): | |
) | ||
] | ||
) | ||
response = execute_hogql_query(query, team=self.team, filters=filters) | ||
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
filters=filters, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.hogql, | ||
f"SELECT event, distinct_id FROM events AS e WHERE equals(properties.random_uuid, '{random_uuid}') LIMIT 100", | ||
|
@@ -1391,7 +1450,11 @@ def test_hogql_query_filters_alias(self): | |
@pytest.mark.usefixtures("unittest_snapshot") | ||
def test_hogql_union_all_limits(self): | ||
query = "SELECT event FROM events UNION ALL SELECT event FROM events" | ||
response = execute_hogql_query(query, team=self.team) | ||
response = execute_hogql_query( | ||
query, | ||
team=self.team, | ||
pretty=False, | ||
) | ||
self.assertEqual( | ||
response.hogql, | ||
f"SELECT event FROM events LIMIT 100 UNION ALL SELECT event FROM events LIMIT 100", | ||
|