8000 refactor(hogql): separate query and queryHogQL functions by thmsobrmlr · Pull Request #32611 · PostHog/posthog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor(hogql): separate query and queryHogQL functions #32611

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 10 commits into from
Jun 12, 2025

Conversation

thmsobrmlr
Copy link
Contributor
@thmsobrmlr thmsobrmlr commented May 23, 2025

Problem

I want to find all hard coded query nodes in our application for applying the latest version field to them with a helper function. Turns out that most of our calls to api.query are actually HogQLQuery nodes and we can version them in a central place.

Changes

  • Adds a separate api.queryHogQL util that takes a branded hogql template literal.
  • Uses a single options argument for api.query and api.queryHogQL.
    Before: await api.query(query, undefined, undefined, 'force_blocking')
    After: await api.queryHogQL(query, { refresh: 'force_blocking' })

How did you test this code?

CI run

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 introduces a new api.queryHogQL utility function that replaces direct HogQLQuery node construction across multiple components, aiming to centralize version management and improve type safety for HogQL queries.

  • Added branded HogQLQueryString type with template literal syntax for better type safety
  • Modified HogQLQueryResponse interface to support generic type parameter for flexible response types
  • Refactored query execution in components like authorizedUrlListLogic, metalyticsLogic, and versionCheckerLogic to use the new utility
  • Removed explicit NodeKind.HogQLQuery node construction in favor of the new template literal approach
  • Maintained existing query functionality while making implementation more concise and maintainable

14 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +99 to 107
const query = hogql`
SELECT distinct properties.$current_url AS urls
FROM events
WHERE timestamp >= now() - INTERVAL 7 DAY
AND timestamp <= now()
AND properties.$current_url like '%${hogql.identifier(values.browserSearchTerm)}%'
ORDER BY timestamp DESC
LIMIT 100`

Copy link
Contributor

Choose a reason for hiding this comment

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

style: SQL query indentation is inconsistent with the second query 8000 (lines 119-129). Consider standardizing the indentation style across all HogQL queries.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

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

Additional changes and improvements to the HogQL query refactor implementation, focusing on type safety and template literal handling.

  • Added error handling for type casting in sessionRecordingDataLogic.ts for concatenated queries to HogQLQueryString type
  • Introduced query response type parameter T in schema-general.ts for more precise typing of query results
  • Simplified query interface by dropping .query() in favor of direct .queryHogQL() in survey and heatmap logic components
  • Streamlined query versioning by centralizing version field application across all HogQL nodes
  • Improved maintainability by using consistent hogql template literals for better type inference

14 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

@thmsobrmlr thmsobrmlr removed the stale label Jun 10, 2025
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (wasn't pushed!)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Contributor
github-actions bot commented Jun 11, 2025

Size Change: +375 B (+0.02%)

Total Size: 1.83 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.83 MB +375 B (+0.02%)

compressed-size-action

@thmsobrmlr thmsobrmlr requested a review from a team June 11, 2025 12:30
@PostHog PostHog deleted a comment from posthog-bot Jun 11, 2025
@PostHog PostHog deleted a comment from posthog-bot Jun 11, 2025
@thmsobrmlr thmsobrmlr merged commit 29cab62 into master Jun 12, 2025
97 checks passed
@thmsobrmlr thmsobrmlr deleted the branded-hogql-tags branch June 12, 2025 08:07
@MarconLP MarconLP mentioned this pull request Jun 12, 2025
3 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
0