From 18d0d53a00c9490a4ad0e9fca19aa68efcfb7318 Mon Sep 17 00:00:00 2001 From: Alexander Spicer Date: Fri, 25 Oct 2024 12:23:47 -0700 Subject: [PATCH] test cleanup --- posthog/hogql/test/_test_parser.py | 34 ++++++++++++++++++++++++++++++ posthog/hogql/test/test_printer.py | 28 +++++++++--------------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/posthog/hogql/test/_test_parser.py b/posthog/hogql/test/_test_parser.py index c870f5f340425..b86fca986a963 100644 --- a/posthog/hogql/test/_test_parser.py +++ b/posthog/hogql/test/_test_parser.py @@ -22,6 +22,7 @@ Dict, VariableDeclaration, SelectSetNode, + SelectSetQuery, ) from posthog.hogql.parser import parse_program @@ -1394,6 +1395,39 @@ def test_select_union_all(self): ), ) + def test_nested_selects(self): + self.assertEqual( + self._select("(select 1 intersect select 2) union all (select 3 except select 4)"), + SelectSetQuery( + initial_select_query=SelectSetQuery( + initial_select_query=SelectQuery(select=[Constant(value=1)]), + subsequent_select_queries=[ + SelectSetNode( + select_query=SelectQuery( + select=[Constant(value=2)], + ), + set_operator="INTERSECT", + ) + ], + ), + subsequent_select_queries=[ + SelectSetNode( + select_query=SelectSetQuery( + initial_select_query=SelectQuery( + select=[Constant(value=3)], + ), + subsequent_select_queries=[ + SelectSetNode( + select_query=SelectQuery(select=[Constant(value=4)]), set_operator="EXCEPT" + ) + ], + ), + set_operator="UNION ALL", + ) + ], + ), + ) + def test_sample_clause(self): self.assertEqual( self._select("select 1 from events sample 1/10 offset 999"), diff --git a/posthog/hogql/test/test_printer.py b/posthog/hogql/test/test_printer.py index 3d44599509dc3..52eb95c673d45 100644 --- a/posthog/hogql/test/test_printer.py +++ b/posthog/hogql/test/test_printer.py @@ -115,7 +115,7 @@ def test_to_printed_hogql(self): ) def test_intersect(self): - expr = parse_select("""select 1 as id intersect select 2 as id""", backend="python") + expr = parse_select("""select 1 as id intersect select 2 as id""") response = to_printed_hogql(expr, self.team) self.assertEqual( response, @@ -123,7 +123,7 @@ def test_intersect(self): ) def test_except(self): - expr = parse_select("""select 1 as id except select 2 as id""", backend="python") + expr = parse_select("""select 1 as id except select 2 as id""") response = to_printed_hogql(expr, self.team) self.assertEqual( response, @@ -132,13 +132,10 @@ def test_except(self): # these share the same priority, should stay in order def test_except_and_union(self): - exprs = [ - parse_select("""select 1 as id except select 2 as id union all select 3 as id""", backend=backend) - for backend in ("python", "cpp") - ] - responses = [to_printed_hogql(expr, self.team) for expr in exprs] + expr = parse_select("""select 1 as id except select 2 as id union all select 3 as id""") + response = to_printed_hogql(expr, self.team) self.assertEqual( - responses[0], + response, ( "SELECT\n" " 1 AS id\n" @@ -153,16 +150,12 @@ def test_except_and_union(self): "LIMIT 50000" ), ) - self.assertEqual(responses[0], responses[1]) def test_union_and_except(self): - exprs = [ - parse_select("""select 1 as id union all select 2 as id except select 3 as id""", backend=backend) - for backend in ("python", "cpp") - ] - responses = [to_printed_hogql(expr, self.team) for expr in exprs] + expr = parse_select("""select 1 as id union all select 2 as id except select 3 as id""") + response = to_printed_hogql(expr, self.team) self.assertEqual( - responses[0], + response, ( "SELECT\n" " 1 AS id\n" @@ -177,10 +170,9 @@ def test_union_and_except(self): "LIMIT 50000" ), ) - self.assertEqual(responses[0], responses[1]) def test_intersect3(self): - expr = parse_select("""select 1 as id intersect select 2 as id intersect select 3 as id""", backend="python") + expr = parse_select("""select 1 as id intersect select 2 as id intersect select 3 as id""") response = to_printed_hogql(expr, self.team) self.assertEqual( response, @@ -198,7 +190,7 @@ def test_intersect3(self): ) def test_union3(self): - expr = parse_select("""select 1 as id union all select 2 as id union all select 3 as id""", backend="python") + expr = parse_select("""select 1 as id union all select 2 as id union all select 3 as id""") response = to_printed_hogql(expr, self.team) self.assertEqual( response,