Skip to content

Commit

Permalink
add a simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Aug 9, 2024
1 parent a249ccf commit b8179f1
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion posthog/hogql/test/test_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)")
Expand Down

0 comments on commit b8179f1

Please sign in to comment.