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

Multiply (merge) support appending arrays without creating duplicates #1702

Open
mikkel3000 opened this issue Jun 19, 2023 · 2 comments
Open

Comments

@mikkel3000
Copy link

Request
When merging yaml files containing arrays using the "+" flag, it will create duplicates if some of the arrays are equal in the two documents. I would like an additional flag("a" in the example) which appends lists without creating duplicates.

Example
If we have data1.yml like:

equalList:
  - a
  - b
changedList:
  - a
  - b

And data2.yml like:

equalList:
  - a
  - b
changedList:
  - c

And we run a command:

yq eval-all '. as $item ireduce ({}; . *+ $item)' data1.yml data2.yml

the current output is:

equalList:
  - a
  - b
  - a
  - b
changedList:
  - a
  - b
  - c

With a new flag ("a" in this example) the output should be:

yq eval-all '. as $item ireduce ({}; . *a $item)' data1.yml data2.yml
equalList:
  - a
  - b
changedList:
  - a
  - b
  - c
@scrungus
Copy link

@mikkel3000
Copy link
Author

After release v4.44.2 unique works on arrays of objects, which provides a workaround for my underlying issue.

Running the following on the resulting yaml will remove duplicates from any arrays:
yq eval '(.. | select(type == "!!seq")) |= unique' result.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants