-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
|= empty
does not work as expected in v1.6
#2051
Comments
|= empty
do not work as expected in v1.6|= empty
does not work as expected in v1.6
Wow, yeah, this is surprising. I'm not sure that there's any way to fix this. |
I have no idea of the code, but yes deleting elements from array inside a loop should always be done backwards ! There is another possibility : attribute the special value |
Ah, so here's the notional fix: when in the context of |
fixes it:
ah, but it's not right:
The problem is that |
In case a path gets deleted, we should iterate arrays backwards in path/1 context.
This reverts commit 9c9013b.
How about delaying def _modify(ps; f):
reduce path(ps) as $p
([., []]; label $out | (setpath([0] + $p; getpath([0] + $p) | f) | ., break $out), .[1] += [$p])
| . as $x | $x[0] | delpaths($x[1]); |
I have some unexpected behaviour on using Input: but If I change the select to the following: (https://jqplay.org/s/_6xd9PGoXN) Input: Is this an instance of the same issue or something different? |
@amagee That's surely an instance of the same issue. |
Additionally,
So it does not resize the array and it shifts the elements by one after emptying an element resulting in the element after an emptied element being skipped.
|
Just to mention that gojq do not have this issue.
|
Describe the bug
Following the documentation
|= empty
is supposed to delete the element.But when multiple elements are set to empty it does not work properly.
To Reproduce
query:
(.[] | select(. >= 2)) |= empty
input:
[1,5,3,0,7]
output:
[1,3,7]
Expected behavior
output:
[1,0]
Environment:
jqplay
Note
>=2
with>=7
then7
is deleted.>=2
with>=5
then only5
is deleted.The text was updated successfully, but these errors were encountered: