From b8179f1283bbb10a1dbfbe242070c6c29ab7838f Mon Sep 17 00:00:00 2001 From: Ted Kaemming <65315+tkaemming@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:02:22 -0700 Subject: [PATCH] add a simple test --- posthog/hogql/test/test_printer.py | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/posthog/hogql/test/test_printer.py b/posthog/hogql/test/test_printer.py index 800557e780a41b..ea03d71d460795 100644 --- a/posthog/hogql/test/test_printer.py +++ b/posthog/hogql/test/test_printer.py @@ -13,7 +13,7 @@ from posthog.hogql.printer import print_ast, to_printed_hogql, prepare_ast_for_printing, print_prepared_ast from posthog.models import PropertyDefinition from posthog.models.team.team import WeekStartDay -from posthog.schema import HogQLQueryModifiers, PersonsArgMaxVersion, PersonsOnEventsMode +from posthog.schema import HogQLQueryModifiers, MaterializationMode, PersonsArgMaxVersion, PersonsOnEventsMode from posthog.test.base import BaseTest @@ -323,6 +323,35 @@ def test_materialized_fields_and_properties(self): "nullIf(nullIf(events.`mat_$browser_______`, ''), 'null')", ) + def test_property_groups(self): + context = HogQLContext( + team_id=self.team.pk, + modifiers=HogQLQueryModifiers( + materializationMode=MaterializationMode.AUTO, + usePropertyGroups=True, + ), + ) + + self.assertEqual( + self._expr("properties['foo']", context), + "has(events.properties_group_custom, %(hogql_val_0)s) ? events.properties_group_custom[%(hogql_val_0)s] : null", + ) + self.assertEqual(context.values["hogql_val_0"], "foo") + + try: + from ee.clickhouse.materialized_columns.analyze import materialize + except ModuleNotFoundError: + return + + # Properties that are materialized as columns should take precedence over the values in the group's map column. + # NOTE: Ideally this would test the same property key before and after materialization, but that state currently + # leaks over test runs - this is easier for now. + materialize("events", "foo_materialized") + self.assertEqual( + self._expr("properties['foo_materialized']"), + "nullIf(nullIf(events.mat_foo_materialized, ''), 'null')", + ) + def test_methods(self): self.assertEqual(self._expr("count()"), "count()") self.assertEqual(self._expr("count(distinct event)"), "count(DISTINCT events.event)")