Skip to content

Commit

Permalink
Add printer tests for the new clickhouse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Dec 11, 2023
1 parent a4d1eb5 commit 9f72ff3
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions posthog/hogql/test/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,3 +1375,111 @@ def test_lookup_domain_type(self):
),
printed,
)

def test_lookup_paid_domain_type(self):
query = parse_select("select hogql_lookupPaidDomainType('www.google.com') from events")
printed = print_ast(
query,
HogQLContext(team_id=self.team.pk, enable_select_queries=True),
dialect="clickhouse",
settings=HogQLGlobalSettings(max_execution_time=10),
)
self.assertEqual(
(
"SELECT dictGetOrNull('channel_definition_dict', 'type_if_paid', "
"(cutToFirstSignificantSubdomain(coalesce(%(hogql_val_0)s, '')), 'source')) "
f"FROM events WHERE equals(events.team_id, {self.team.pk}) LIMIT 10000 SETTINGS "
"readonly=2, max_execution_time=10, allow_experimental_object_type=1"
),
printed,
)

def test_lookup_paid_source_type(self):
query = parse_select("select hogql_lookupPaidSourceType('google') from events")
printed = print_ast(
query,
HogQLContext(team_id=self.team.pk, enable_select_queries=True),
dialect="clickhouse",
settings=HogQLGlobalSettings(max_execution_time=10),
)
self.assertEqual(
(
"SELECT dictGetOrNull('channel_definition_dict', 'type_if_paid', "
"(coalesce(%(hogql_val_0)s, ''), 'source')) "
f"FROM events WHERE equals(events.team_id, {self.team.pk}) LIMIT 10000 SETTINGS "
"readonly=2, max_execution_time=10, allow_experimental_object_type=1"
),
printed,
)

def test_lookup_paid_medium_type(self):
query = parse_select("select hogql_lookupPaidMediumType('social') from events")
printed = print_ast(
query,
HogQLContext(team_id=self.team.pk, enable_select_queries=True),
dialect="clickhouse",
settings=HogQLGlobalSettings(max_execution_time=10),
)
self.assertEqual(
(
"SELECT dictGetOrNull('channel_definition_dict', 'type_if_paid', "
"(coalesce(%(hogql_val_0)s, ''), 'medium')) "
f"FROM events WHERE equals(events.team_id, {self.team.pk}) LIMIT 10000 SETTINGS "
"readonly=2, max_execution_time=10, allow_experimental_object_type=1"
),
printed,
)

def test_lookup_organic_domain_type(self):
query = parse_select("select hogql_lookupOrganicDomainType('www.google.com') from events")
printed = print_ast(
query,
HogQLContext(team_id=self.team.pk, enable_select_queries=True),
dialect="clickhouse",
settings=HogQLGlobalSettings(max_execution_time=10),
)
self.assertEqual(
(
"SELECT dictGetOrNull('channel_definition_dict', 'type_if_organic', "
"(cutToFirstSignificantSubdomain(coalesce(%(hogql_val_0)s, '')), 'source')) "
f"FROM events WHERE equals(events.team_id, {self.team.pk}) LIMIT 10000 SETTINGS "
"readonly=2, max_execution_time=10, allow_experimental_object_type=1"
),
printed,
)

def test_lookup_organic_source_type(self):
query = parse_select("select hogql_lookupOrganicSourceType('google') from events")
printed = print_ast(
query,
HogQLContext(team_id=self.team.pk, enable_select_queries=True),
dialect="clickhouse",
settings=HogQLGlobalSettings(max_execution_time=10),
)
self.assertEqual(
(
"SELECT dictGetOrNull('channel_definition_dict', 'type_if_organic', "
"(coalesce(%(hogql_val_0)s, ''), 'source')) "
f"FROM events WHERE equals(events.team_id, {self.team.pk}) LIMIT 10000 SETTINGS "
"readonly=2, max_execution_time=10, allow_experimental_object_type=1"
),
printed,
)

def test_lookup_organic_medium_type(self):
query = parse_select("select hogql_lookupOrganicMediumType('social') from events")
printed = print_ast(
query,
HogQLContext(team_id=self.team.pk, enable_select_queries=True),
dialect="clickhouse",
settings=HogQLGlobalSettings(max_execution_time=10),
)
self.assertEqual(
(
"SELECT dictGetOrNull('channel_definition_dict', 'type_if_organic', "
"(coalesce(%(hogql_val_0)s, ''), 'medium')) "
f"FROM events WHERE equals(events.team_id, {self.team.pk}) LIMIT 10000 SETTINGS "
"readonly=2, max_execution_time=10, allow_experimental_object_type=1"
),
printed,
)

0 comments on commit 9f72ff3

Please sign in to comment.