Skip to content

fix(modelling): Try any posthog table from modelling #31073

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

Merged
merged 3 commits into from
Apr 10, 2025

Conversation

Gilbert09
Copy link
Member

Problem

  • We can run modelling on queries that use the numbers table function

Changes

  • Change how we read posthog tables - moved this logic to be last after looking up saved views/warehouse tables as these tables will return from the same function too

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

Yes

How did you test this code?

Added a test

@Gilbert09 Gilbert09 requested a review from a team April 10, 2025 15:52
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds support for the numbers table function in PostHog's modeling system by changing how table validation works in the modeling framework.

  • Modified get_or_create_query_parent_paths() to check saved queries and warehouse tables first before falling back to PostHog tables
  • Changed PostHog table validation to use get_table() with exception handling instead of checking against a static list
  • Added a test case in test_modeling.py that verifies numbers(10) is correctly identified as a parent table
  • Added QueryError import from posthog.hogql.errors to properly handle table resolution exceptions
  • Improved robustness by using the actual table resolution mechanism rather than static list checks

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@@ -21,6 +21,7 @@
{"events"},
),
("select 1", set()),
("select * from numbers(10)", {"numbers"}),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may conflict with my earlier fix. But, by the way, this method will not fail on numbers as it just extracts the names, doesn't actually check that the table exists (see my earlier fix which includes numbers).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeep - just resolved these

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, but fyi, this test is not actually testing what this PR is fixing (as you can see by existing tests already covering numbers)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah i don't really understand how your test passed without my change 🤔

Copy link
Contributor

@tomasfarias tomasfarias Apr 10, 2025

Choose a reason for hiding this comment

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

Because the method in the test (get_parents_from_model_query) is not checking that the tables are valid names, just resolving the names.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I was looking at the wrong method 🤦 I'll fix

Copy link
Contributor

@tomasfarias tomasfarias left a comment

Choose a reason for hiding this comment

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

Looks good once conflicts are fixed

@Gilbert09 Gilbert09 enabled auto-merge (squash) April 10, 2025 15:55
@Gilbert09 Gilbert09 merged commit 99f2a7b into master Apr 10, 2025
94 checks passed
@Gilbert09 Gilbert09 deleted the tom/modelling-numbers-table branch April 10, 2025 16:55
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.

2 participants