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

feat(hogql): refactor macros and asterisks into "resolver" #15175

Merged
merged 10 commits into from
Apr 25, 2023

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Apr 20, 2023

Still draft

Problem

Expanding macros and * fields in a separate step from the resolver was causing maintainability issues. We had 3 stages in parallel: expand_macros, resolve_types, expand_asterisks. For a good implementation, we'd need to call all 3 in parallel when adding something new in any of these steps --> new column added in expand_asterisks --> run all 3 again on the new node.

Changes

  • Now that all three visitors (expand_macros, resolve_types, expand_asterisks) use CloningVisitor, they're easy to merge.
  • Merges all expansion and resolving steps into resolver.py.
  • Move transforms/asterisk.py and transforms/macros.py into resolver.py, adapt as needed
  • Paves way for feat(hogql): custom SQL columns #15180

How did you test this code?

  • All old tests work.
  • Added some new ones.

Base automatically changed from hogql-immutable-resolver to master April 20, 2023 21:06
Comment on lines +334 to +335
if len(node.chain) > 1:
raise ResolverException(f"Cannot access fields on macro {macro.name} yet.")
Copy link
Collaborator Author

@mariusandra mariusandra Apr 21, 2023

Choose a reason for hiding this comment

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

This will be is already fixed in #15180

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Makes sense and looks good, there's just one thing I'm still not sure about: why we don't just use the standard "common table expression" for this? As this already is familiar in SQL world – definitely more than Lisp macros

@mariusandra
Copy link
Collaborator Author

That is a good question. We definitely could swap out the logic from "extract macros from WITH" to "embrace the WITH CTE-s". I initially embraced the macro approach since there were some ClickHouse limitations (e.g. no recursion) that I wanted to overcome.

I'm willing to give this another look, and have added "Do we want to keep extracting macros from the WITH clause, or embrace CTE-s?" as a checkbox to tick. I'd leave that refactor for another PR though :).

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Makes sense, let's get this in

@mariusandra
Copy link
Collaborator Author

Thanks! Very much related, when working on this - #15244 - any additional duplication of properties.foo such as if(properties.foo, properties.foo, elseMoo) resulted in a slowdown of the query. I didn't try it out, but could aliasing the repeating part into a WITH expression work as some kind of optimisation?

@mariusandra mariusandra merged commit c728544 into master Apr 25, 2023
@mariusandra mariusandra deleted the hogql-move-macros branch April 25, 2023 22:10
fuziontech added a commit that referenced this pull request Apr 25, 2023
* master:
  feat(hogql): refactor macros and asterisks into "resolver" (#15175)
fuziontech added a commit that referenced this pull request Apr 27, 2023
* master: (37 commits)
  fix: fix sprint planning issue template (#15271)
  fix: player skip buttons only ever showed right (#15269)
  chore: bump vm2 due to CVE (#15268)
  fix(person-query): don't query persons twice if we don't need to (#15265)
  fix(ch): stop running delete jobs while clickhouse is on an older version (#15239)
  chore(recordings): use cooperative-sticky rebalance strategy (#15260)
  fix: SESSION_RECORDING_BLOB_PROCESSING_TEAMS config handling (#15247)
  fix(flags): Some UX inconsistencies (#15255)
  fix: Recording share button (#15256)
  chore(deps): Update posthog-js to 1.54.0 (#15257)
  style(3000): Support keyboard navigation in sidebar (#15237)
  feat: Add support for opening bug report via URL (#15251)
  feat: Hedgebar (#14934)
  Fixed undefined default for window select (#15249)
  fix(data-exploration): prevent leave confirmation safeguard (#15250)
  chore: remove readonly setting defaults for hogql (#15246)
  feat(hogql): refactor macros and asterisks into "resolver" (#15175)
  feat(hogql): swap out toDateTime function (#15226)
  fix(insight-timeout-state): centralize query ID (#15240)
  Fix/forgot ingestion fixes (#15238)
  ...
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