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

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

merged 20 commits into from
Apr 2, 2024

Conversation

EDsCODE
Copy link
Member

@EDsCODE EDsCODE commented Mar 26, 2024

Problem

  • joins on views don't work because the view names get parsed into the queries without a trace

Changes

  • propogate a "view_name" on select queries so that they can be used to account for lazy joins
  • in selectview, if a view_name is present, use the view_name to resolve the field types being requested. It might include lazyjoins that aren't present on the selectquery itself but will be once lazy tables are joined
  • context: https://posthog.slack.com/archives/C019RAX2XBN/p1710868176668289

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?


def get_child(self, name: str, context: HogQLContext) -> Type:
if name == "*":
return AsteriskType(table_type=self)
if self.view_name:
field = context.database.get_table(self.view_name).get_field(name)
if isinstance(field, LazyJoin):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: this resolution logic is repeated from BaseTableType

Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it would work, but I wonder if this is inflating the responsibilities of SelectQueryAliasType just a bit? Seeing a view_type in that class doesn't tell me much about why it's there (and why it's not on e.g. SelectQueryType?).

This should either get a comment explaining its purpose... or alternatively I think a better approach is to create SelectViewType, either deriving from BaseTableType directly, or then as another entry in TableOrSelectType.

Note: this TableType could probably be renamed SelectTableType. TableAliasType to SelectTableAliasType, etc.

@EDsCODE EDsCODE marked this pull request as ready for review April 2, 2024 14:01
@EDsCODE EDsCODE merged commit d790ade into master Apr 2, 2024
76 checks passed
@EDsCODE EDsCODE deleted the dw-joins-on-views branch April 2, 2024 16:10
@EDsCODE EDsCODE mentioned this pull request Apr 2, 2024
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants