You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the ireduce is preceded by an expression, it no longer works the same way and instead of merging it will output duplicate keys (.data). This is similar to what happens when using eval instead of eval-all. (Maybe it's no longer evaluated as multifile internally or something.)
Another manifestation may be a document duplication with a similar command, or maybe I misunderstand how it should work there.
$ yq eval-all -e '. as $all | . as $item ireduce({}; . * $item)'<<(echo"${input_data}")
I tried to simplify the command for a reproducer but for a context I was after something like yq eval-all -e '. as $all | select(fi==0) | .data = null | $all as $item ireduce({}; . * $item)' < <( echo "${input_data}" )
that would merge keys on .data from all files except the first one which should be discarded.
The text was updated successfully, but these errors were encountered:
This is actually intentional when using variables - despite how odd it looks.
The expression ". as $all | ..." is actually like a for loop (this is how jq does it) - where each "." (in this case a document) is set to "$all" then the "..." expression is evaluated with that value. That's why you're seeing two outputs, it went through the loop twice, once with the first doc, then the next.
You can 'trick' by doing wrapping the '.' in an array:
yq ea '[.] as $all | ($all | .[]) as $item ireduce({}; . * $item)' file.yaml
This will now work because its wrapping both documents into an array, setting that as "$all" and then in the loop, it splats it out again.
Describe the bug
. as $item ireduce({}; . * $item)
can't merge multiple documents when preceded by other commands.Version of yq: v4.34.1
Operating system: linux
Installed via: go install
Input Yaml
$ input_data=$( echo -e 'unique: value\ndata:\n foo:\n alpha\n---\ndata:\n bar:\n beta' )
Command
$ yq eval-all -e '. as $all | $all as $item ireduce({}; . * $item)' < <( echo "${input_data}" )
Actual behavior
Expected behavior
Additional context
Based on https://mikefarah.gitbook.io/yq/operators/reduce#merge-all-yaml-files-together
When
. as $item ireduce
is the first command it all works as expected.$ yq eval-all -e '. as $item ireduce({}; . * $item)' < <( echo "${input_data}" )
When the
ireduce
is preceded by an expression, it no longer works the same way and instead of merging it will output duplicate keys (.data
). This is similar to what happens when usingeval
instead ofeval-all
. (Maybe it's no longer evaluated as multifile internally or something.)Another manifestation may be a document duplication with a similar command, or maybe I misunderstand how it should work there.
$ yq eval-all -e '. as $all | . as $item ireduce({}; . * $item)' < <( echo "${input_data}" )
I tried to simplify the command for a reproducer but for a context I was after something like
yq eval-all -e '. as $all | select(fi==0) | .data = null | $all as $item ireduce({}; . * $item)' < <( echo "${input_data}" )
that would merge keys on
.data
from all files except the first one which should be discarded.The text was updated successfully, but these errors were encountered: