From 6b0b04454e6b407ee6b72810cf774e28a7b787d7 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Fri, 26 Jan 2024 09:37:18 +0100 Subject: [PATCH] feat(insights): pretty print more sql (#19963) --- posthog/hogql/database/test/test_database.py | 13 +++- posthog/hogql/functions/test/test_cohort.py | 3 + .../hogql/functions/test/test_sparkline.py | 2 +- posthog/hogql/printer.py | 2 +- posthog/hogql/query.py | 6 +- .../test/__snapshots__/test_printer.ambr | 3 +- posthog/hogql/test/test_modifiers.py | 5 ++ posthog/hogql/test/test_query.py | 75 +++++++++++++++++-- .../hogql/transforms/test/test_in_cohort.py | 10 +++ 9 files changed, 107 insertions(+), 12 deletions(-) diff --git a/posthog/hogql/database/test/test_database.py b/posthog/hogql/database/test/test_database.py index c0817ee2c9861..fae4a5c88928e 100644 --- a/posthog/hogql/database/test/test_database.py +++ b/posthog/hogql/database/test/test_database.py @@ -39,14 +39,22 @@ def test_can_select_from_each_table_at_all(self, poe_enabled: bool) -> None: serialized_database = serialize_database(create_hogql_database(team_id=self.team.pk)) for table, possible_columns in serialized_database.items(): if table == "numbers": - execute_hogql_query("SELECT number FROM numbers(10) LIMIT 100", self.team) + execute_hogql_query( + "SELECT number FROM numbers(10) LIMIT 100", + self.team, + pretty=False, + ) else: columns = [ x["key"] for x in possible_columns if "table" not in x and "chain" not in x and "fields" not in x ] - execute_hogql_query(f"SELECT {','.join(columns)} FROM {table}", team=self.team) + execute_hogql_query( + f"SELECT {','.join(columns)} FROM {table}", + team=self.team, + pretty=False, + ) @patch("posthog.hogql.query.sync_execute", return_value=(None, None)) @pytest.mark.usefixtures("unittest_snapshot") @@ -66,6 +74,7 @@ def test_database_with_warehouse_tables(self, patch_execute): response = execute_hogql_query( "select * from whatever", team=self.team, + pretty=False, ) self.assertEqual( diff --git a/posthog/hogql/functions/test/test_cohort.py b/posthog/hogql/functions/test/test_cohort.py index 1c5460bc9176d..427cf0db342cd 100644 --- a/posthog/hogql/functions/test/test_cohort.py +++ b/posthog/hogql/functions/test/test_cohort.py @@ -49,6 +49,7 @@ def test_in_cohort_dynamic(self): f"SELECT event FROM events WHERE person_id IN COHORT {cohort.pk} AND event='{random_uuid}'", self.team, modifiers=HogQLQueryModifiers(inCohortVia="subquery"), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot self.assertEqual(len(response.results), 1) @@ -65,6 +66,7 @@ def test_in_cohort_static(self): f"SELECT event FROM events WHERE person_id IN COHORT {cohort.pk}", self.team, modifiers=HogQLQueryModifiers(inCohortVia="subquery"), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot @@ -80,6 +82,7 @@ def test_in_cohort_strings(self): f"SELECT event FROM events WHERE person_id IN COHORT 'my cohort'", self.team, modifiers=HogQLQueryModifiers(inCohortVia="subquery"), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot diff --git a/posthog/hogql/functions/test/test_sparkline.py b/posthog/hogql/functions/test/test_sparkline.py index 2a5c24d90b1af..74a00392e9c8d 100644 --- a/posthog/hogql/functions/test/test_sparkline.py +++ b/posthog/hogql/functions/test/test_sparkline.py @@ -5,7 +5,7 @@ class TestSparkline(BaseTest): def test_sparkline(self): - response = execute_hogql_query("select sparkline([1,2,3])", self.team) + response = execute_hogql_query("select sparkline([1,2,3])", self.team, pretty=False) self.assertEqual( response.clickhouse, f"SELECT tuple(%(hogql_val_0)s, %(hogql_val_1)s, %(hogql_val_2)s, [1, 2, 3]) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1", diff --git a/posthog/hogql/printer.py b/posthog/hogql/printer.py index 650d53b366026..74341e76b6839 100644 --- a/posthog/hogql/printer.py +++ b/posthog/hogql/printer.py @@ -304,7 +304,7 @@ def visit_select_query(self, node: ast.SelectQuery): clauses = [ f"SELECT{space}{'DISTINCT ' if node.distinct else ''}{comma.join(columns)}", - f"FROM{space}{' '.join(joined_tables)}" if len(joined_tables) > 0 else None, + f"FROM{space}{space.join(joined_tables)}" if len(joined_tables) > 0 else None, array_join if array_join else None, f"PREWHERE{space}" + prewhere if prewhere else None, f"WHERE{space}" + where if where else None, diff --git a/posthog/hogql/query.py b/posthog/hogql/query.py index 34706606f3753..42ba19eaa9618 100644 --- a/posthog/hogql/query.py +++ b/posthog/hogql/query.py @@ -37,6 +37,7 @@ def execute_hogql_query( limit_context: Optional[LimitContext] = LimitContext.QUERY, timings: Optional[HogQLTimings] = None, explain: Optional[bool] = False, + pretty: Optional[bool] = True, ) -> HogQLQueryResponse: if timings is None: timings = HogQLTimings() @@ -95,7 +96,9 @@ def execute_hogql_query( ) with timings.measure("print_ast"): - hogql = print_prepared_ast(select_query_hogql, hogql_query_context, "hogql") + hogql = print_prepared_ast( + select_query_hogql, hogql_query_context, "hogql", pretty=pretty if pretty is not None else True + ) print_columns = [] columns_query = ( select_query_hogql.select_queries[0] @@ -133,6 +136,7 @@ def execute_hogql_query( context=clickhouse_context, dialect="clickhouse", settings=settings, + pretty=pretty if pretty is not None else True, ) timings_dict = timings.to_dict() diff --git a/posthog/hogql/test/__snapshots__/test_printer.ambr b/posthog/hogql/test/__snapshots__/test_printer.ambr index ee6947efb744f..cf8678d33ca0d 100644 --- a/posthog/hogql/test/__snapshots__/test_printer.ambr +++ b/posthog/hogql/test/__snapshots__/test_printer.ambr @@ -19,7 +19,8 @@ (SELECT minus(dateTrunc('day', assumeNotNull(toDateTime('2023-10-19 23:59:59'))), toIntervalDay(number)) AS start_of_period FROM - numbers(dateDiff('day', dateTrunc('day', assumeNotNull(toDateTime('2023-09-19 00:00:00'))), dateTrunc('day', plus(assumeNotNull(toDateTime('2023-10-19 23:59:59')), toIntervalDay(1))))) AS numbers) AS periods CROSS JOIN (SELECT + numbers(dateDiff('day', dateTrunc('day', assumeNotNull(toDateTime('2023-09-19 00:00:00'))), dateTrunc('day', plus(assumeNotNull(toDateTime('2023-10-19 23:59:59')), toIntervalDay(1))))) AS numbers) AS periods + CROSS JOIN (SELECT status FROM (SELECT diff --git a/posthog/hogql/test/test_modifiers.py b/posthog/hogql/test/test_modifiers.py index fc31cfe99eea8..eba1f5195ab3d 100644 --- a/posthog/hogql/test/test_modifiers.py +++ b/posthog/hogql/test/test_modifiers.py @@ -81,6 +81,7 @@ def test_modifiers_persons_on_events_mode_mapping(self): query, team=self.team, modifiers=HogQLQueryModifiers(personsOnEventsMode=mode), + pretty=False, ) assert f"SELECT {', '.join(expected)} FROM" in response.clickhouse, f"PoE mode: {mode}" @@ -158,6 +159,7 @@ def test_modifiers_materialization_mode(self): "SELECT properties.$browser FROM events", team=self.team, modifiers=HogQLQueryModifiers(materializationMode=MaterializationMode.auto), + pretty=False, ) assert ( "SELECT nullIf(nullIf(events.`mat_$browser`, ''), 'null') AS `$browser` FROM events" in response.clickhouse @@ -167,6 +169,7 @@ def test_modifiers_materialization_mode(self): "SELECT properties.$browser FROM events", team=self.team, modifiers=HogQLQueryModifiers(materializationMode=MaterializationMode.legacy_null_as_null), + pretty=False, ) assert ( "SELECT nullIf(nullIf(events.`mat_$browser`, ''), 'null') AS `$browser` FROM events" in response.clickhouse @@ -176,6 +179,7 @@ def test_modifiers_materialization_mode(self): "SELECT properties.$browser FROM events", team=self.team, modifiers=HogQLQueryModifiers(materializationMode=MaterializationMode.legacy_null_as_string), + pretty=False, ) assert "SELECT nullIf(events.`mat_$browser`, '') AS `$browser` FROM events" in response.clickhouse @@ -183,6 +187,7 @@ def test_modifiers_materialization_mode(self): "SELECT properties.$browser FROM events", team=self.team, modifiers=HogQLQueryModifiers(materializationMode=MaterializationMode.disabled), + pretty=False, ) assert ( "SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^\"|\"$', '') AS `$browser` FROM events" diff --git a/posthog/hogql/test/test_query.py b/posthog/hogql/test/test_query.py index 3c1969d3198cb..ef81e32ae1836 100644 --- a/posthog/hogql/test/test_query.py +++ b/posthog/hogql/test/test_query.py @@ -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, [("tim@posthog.com",)]) @@ -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], "tim@posthog.com") @@ -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], "tim@posthog.com") @@ -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", diff --git a/posthog/hogql/transforms/test/test_in_cohort.py b/posthog/hogql/transforms/test/test_in_cohort.py index 2fe6b6cc16c13..25e847d70cbc1 100644 --- a/posthog/hogql/transforms/test/test_in_cohort.py +++ b/posthog/hogql/transforms/test/test_in_cohort.py @@ -49,6 +49,7 @@ def test_in_cohort_dynamic(self): f"SELECT event FROM events WHERE person_id IN COHORT {cohort.pk} AND event='{random_uuid}'", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot # type: ignore self.assertEqual(len(response.results or []), 1) @@ -65,6 +66,7 @@ def test_in_cohort_static(self): f"SELECT event FROM events WHERE person_id IN COHORT {cohort.pk}", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot # type: ignore @@ -80,6 +82,7 @@ def test_in_cohort_strings(self): f"SELECT event FROM events WHERE person_id IN COHORT 'my cohort'", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot # type: ignore @@ -91,6 +94,7 @@ def test_in_cohort_error(self): f"SELECT event FROM events WHERE person_id IN COHORT true", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.subquery), + pretty=False, ) self.assertEqual(str(e.exception), "cohort() takes exactly one string or integer argument") @@ -99,6 +103,7 @@ def test_in_cohort_error(self): f"SELECT event FROM events WHERE person_id IN COHORT 'blabla'", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.subquery), + pretty=False, ) self.assertEqual(str(e.exception), "Could not find a cohort with the name 'blabla'") @@ -114,6 +119,7 @@ def test_in_cohort_conjoined_string(self): f"SELECT event FROM events WHERE person_id IN COHORT 'my cohort'", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin_conjoined), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot # type: ignore @@ -128,6 +134,7 @@ def test_in_cohort_conjoined_int(self): f"SELECT event FROM events WHERE person_id IN COHORT {cohort.pk}", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin_conjoined), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot # type: ignore @@ -144,6 +151,7 @@ def test_in_cohort_conjoined_dynamic(self): f"SELECT event FROM events WHERE person_id IN COHORT {cohort.pk} AND event='{random_uuid}'", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin_conjoined), + pretty=False, ) assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot # type: ignore self.assertEqual(len(response.results or []), 1) @@ -157,6 +165,7 @@ def test_in_cohort_conjoined_error(self): f"SELECT event FROM events WHERE person_id IN COHORT true", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin_conjoined), + pretty=False, ) self.assertEqual(str(e.exception), "cohort() takes exactly one string or integer argument") @@ -165,5 +174,6 @@ def test_in_cohort_conjoined_error(self): f"SELECT event FROM events WHERE person_id IN COHORT 'blabla'", self.team, modifiers=HogQLQueryModifiers(inCohortVia=InCohortVia.leftjoin_conjoined), + pretty=False, ) self.assertEqual(str(e.exception), "Could not find a cohort with the name 'blabla'")