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

Rework user ops #4663

Merged
merged 3 commits into from Jun 22, 2023
Merged

Rework user ops #4663

merged 3 commits into from Jun 22, 2023

Conversation

mattnibs
Copy link
Collaborator

@mattnibs mattnibs commented Jun 21, 2023

Rework user ops in the following ways:

  • User ops take either a const or path as an argument.
  • The this value of the parent is carried through when a user op is invoked.

Fixes #4650
Fixes #4658
Fixes #4653

@philrz
Copy link
Contributor

philrz commented Jun 21, 2023

FWIW, I tested out this branch at commit 6fb851c and confirmed it seems to address what's described in #4650. That is, since we're no longer using spread to pass this into the user op, now primitive values make it through ok.

$ zq -version
Version: v1.8.1-32-g6fb851c9

$ cat kind-in-op-4663.zed
op CallMe(): (
  yield {kind: kind(this),ThisWas: this}
)
CallMe()

$ echo '{foo: "bar"} "hello"' | zq -z -I kind-in-op-4663.zed -
{kind:"record",ThisWas:{foo:"bar"}}
{kind:"primitive",ThisWas:"hello"}

@philrz
Copy link
Contributor

philrz commented Jun 21, 2023

It looks like #4658 is addressed as well. I can now pass in a dotted reference to a nested field or use field referencing with indexing and then reference the field ok from inside the user op.

$ zq -version
Version: v1.8.1-32-g6fb851c9

$ cat yield-in-op-4663.zed
op CallMe(f): (
  yield f
)

$ echo '{foo: {bar: "baz"}}' | zq -Z -I yield-in-op-4663.zed 'CallMe(foo.bar)' -
"baz"

$ echo '{foo: {bar: "baz"}}' | zq -Z -I yield-in-op-4663.zed 'CallMe(this["foo"]["bar"])' -
"baz"

@mattnibs mattnibs force-pushed the user-ops-take-5 branch 4 times, most recently from 124fe79 to a7e7693 Compare June 21, 2023 22:09
Rework user ops in the following ways:
- User ops take either a const or path as an argument.
- The this value of the parent is carried through when a user op is
  invoked.
@mattnibs mattnibs changed the title User Ops Round III Rework user ops Jun 21, 2023
@mattnibs mattnibs marked this pull request as ready for review June 21, 2023 22:11
@mattnibs mattnibs requested a review from a team June 21, 2023 22:11
Copy link
Member

@nwt nwt left a comment

Choose a reason for hiding this comment

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

The stuff in runtime/op/scope.go is now unused, so you can remove that.

compiler/semantic/analyzer.go Outdated Show resolved Hide resolved
compiler/semantic/op.go Outdated Show resolved Hide resolved
compiler/semantic/op.go Outdated Show resolved Hide resolved
runtime/op/ztests/user-no-params.yaml Outdated Show resolved Hide resolved
docs/language/statements.md Outdated Show resolved Hide resolved
docs/language/statements.md Outdated Show resolved Hide resolved
docs/language/statements.md Outdated Show resolved Hide resolved
Co-authored-by: Noah Treuhaft <noah.treuhaft@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants