Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE committed Mar 27, 2024
1 parent 1973539 commit f5dbc57
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion posthog/hogql/database/test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from posthog.models.organization import Organization
from posthog.models.team.team import Team
from posthog.test.base import BaseTest
from posthog.warehouse.models import DataWarehouseTable, DataWarehouseCredential
from posthog.warehouse.models import DataWarehouseTable, DataWarehouseCredential, DataWarehouseSavedQuery
from posthog.hogql.query import execute_hogql_query
from posthog.warehouse.models.join import DataWarehouseJoin

Expand Down Expand Up @@ -288,3 +288,29 @@ def test_database_warehouse_joins_persons_poe_v2(self):
assert poe.fields["some_field"] is not None

print_ast(parse_select("select person.some_field.key from events"), context, dialect="clickhouse")

def test_database_warehouse_joins_on_view(self):
DataWarehouseSavedQuery.objects.create(
team=self.team,
name="event_view",
query={"query": "SELECT event AS event from events"},
columns={"event": "String"},
)
DataWarehouseJoin.objects.create(
team=self.team,
source_table_name="event_view",
source_table_key="event",
joining_table_name="groups",
joining_table_key="key",
field_name="some_field",
)

db = create_hogql_database(team_id=self.team.pk)
context = HogQLContext(
team_id=self.team.pk,
enable_select_queries=True,
database=db,
)

sql = "select e.some_field.key from event_view as e"
print_ast(parse_select(sql), context, dialect="clickhouse")

0 comments on commit f5dbc57

Please sign in to comment.