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): local evaluation (HogVM part 2) #16275

Merged
merged 16 commits into from
Jun 28, 2023
Merged

feat(hogql): local evaluation (HogVM part 2) #16275

merged 16 commits into from
Jun 28, 2023

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Jun 27, 2023

Problem

The HogQL local evaluation PR (aka HogVM) is getting out of control. I'll split it into at least threefour. This is part two, and it contains the HogVM local evaluation engine. Part 3 will add cohort support. Part 4 will connect this to actions.

Changes

  • introduces a over-the-wire HogQL "bytecode" format, which is easy to execute and parse on the client side. This is intended for action matching in the plugin server, and can be adopted by feature flags in the near future.
  • implements code to convert a HogQL AST into this bytecode format
  • implements two VMs ("HogVMs") to execute said bytecode. One in Python, one in TypeScript

---> View the README for HogVM for more details. <---

Next steps

  • The next feature I want to add is a feedback loop with the caller, so the VM could ask for more info. Specifically to get in cohort working. The VM shouldn't know about our data model, but just ask the lightweight wrapper around it for an async answer to is 'Timmy' in cohort 2.

How did you test this code?

Added tests.

@mariusandra mariusandra marked this pull request as ready for review June 28, 2023 07:31
Base automatically changed from hogql-regex to master June 28, 2023 08:56
Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

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

All seems well!

describe('HogQL Bytecode', () => {
test('execution results', () => {
const fields = { properties: { foo: 'bar' } }
expect(executeHogQLBytecode(['_h', op.INTEGER, 2, op.INTEGER, 1, op.PLUS], fields)).toBe(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to re-use the generated bytecode from the python tests e.g. by storying them in a JSON file keyed by HogQL expression.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely agree. I'd like to get to a state where we can confidently say the same code executes the same way on all platforms. Let's leave this for a future refactor. Thanks for the review! 👍

@mariusandra mariusandra merged commit 4b44cba into master Jun 28, 2023
@mariusandra mariusandra deleted the hogvm-2 branch June 28, 2023 15:23
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