Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(data-warehouse): joins on views #21151

Merged
merged 20 commits into from
Apr 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
EDsCODE committed Mar 27, 2024
commit f5dbc57654a884fa1dee620fc4906140a0765b51
28 changes: 27 additions & 1 deletion posthog/hogql/database/test/test_database.py
Original file line number Diff line number Diff line change
@@ -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

@@ -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")