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

Bloblang with method is not properly filtering arrays #2697

Open
joreetz-otto opened this issue Jul 12, 2024 · 3 comments
Open

Bloblang with method is not properly filtering arrays #2697

joreetz-otto opened this issue Jul 12, 2024 · 3 comments
Labels
bloblang Bloblang features needs investigation It looks as though have all the information needed but investigation is required

Comments

@joreetz-otto
Copy link

The with method in bloblang is not working as expected (at least for me after reading the doc on field paths) on objects in arrays.

rpk version v24.1.9 (rev 871368edb0)

Example:

root = {"a": [{"b": 1, "c": 2}, {"b": 3, "c": 4}]}
root = root.with("a.*.b")

Expected result:

{"a":[{"b":1},{"b":3}]}

Result

{"a":[{"b":1,"c":2},{"b":3,"c":4}]}

Even these give the same result

root = {"a": [{"b": 1, "c": 2}, {"b": 3, "c": 4}]}
root = root.with("a.1.b")
root = {"a": [{"b": 1, "c": 2}, {"b": 3, "c": 4}]}
root = root.with("a.*.IDONOTEXIST")
@joreetz-otto joreetz-otto changed the title Bloblang with method is not properly filtering arrays Bloblang with method is not properly filtering arrays Jul 12, 2024
@mihaitodor
Copy link
Collaborator

mihaitodor commented Jul 12, 2024

Hey @joreetz-otto 👋 Nice catch, I can reproduce that, but not sure if there's an easy way to get it to work with arrays...

As a workaround, you can do this:

root = this
root.a = this.a.map_each(o -> o.with("b"))

Also, if you have multiple levels of nested arrays, it should be possible to use a recursive mapping to apply this workaround.

@mihaitodor mihaitodor added needs investigation It looks as though have all the information needed but investigation is required bloblang Bloblang features labels Jul 12, 2024
@joreetz-otto
Copy link
Author

Hey @mihaitodor thanks for confirming this so fast.
I will try your workaround.
Can you tell me where the method is implemented? I couldn't find it. I will see if I can manage to fix this.

@mihaitodor
Copy link
Collaborator

You'll probably have to dig into gabs: https://github.com/Jeffail/gabs. The method is implemented here. There's also without() here. They're not implemented in the same place since there's some leftover internal cleanup which should get done eventually...

PS: I just looked at the get() method and that handles arrays just fine. I think it's a bit more tricky in the case of with() / without() because * creates a "view" of the object, so I'm not sure what may need to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bloblang Bloblang features needs investigation It looks as though have all the information needed but investigation is required
Projects
None yet
Development

No branches or pull requests

2 participants