-
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
Enhance the "add" operator so that, when applied to objects, if two f… #1103
base: master
Are you sure you want to change the base?
Conversation
…ields with the same name have a numerical value the corresponding field of the result object is set to the sum of the field values. (The previous behavior was for one of the values to just be discarded.)
The test failure is due to a problem with the continuous integration system itself (as noted in other pull requests), and not to the changes in my pull request. The tests do pass on my machine. |
Note that this doesn't just change the behaviour of This is something that can and should be discussed, but I don't think |
@slapresta My use case is combining objects that represent event counts. I want to derive a single object that contains aggregate counts (which I realize could probably be achieved using currently existing operators, in a way that I think would be more complicated). |
Well, choosing one of the two is what similar operators do: Here's a way to solve your problem without modifying jq's builtins:
Over the input |
Hi, first, I know the appveyor build is broken for reasons having nothing to do with this. I need to find the time to do something about it. (The Oniguruma pacman pkgs for msys broke.) Second, I really appreciate this PR. I'm glad you're doing this. Thanks! However, this change would have backwards-compatibility repercussions that we can't really accept. Perhaps you could add a new jv function to do what you want and then export that function via |
@nicowilliams Thanks for the feedback. (And thanks for |
An
However, the case for including such a filter (however named and with whatever tweaks to handle edge-cases) as a jq builtin seems to me to be quite weak, certainly in comparison with
This of course corresponds with the widely understood and used Σ operation, but if the name "sigma" is deemed inappropriate here, the filter could be called For example, given an array of objects with names, heights, and weights, it is unlikely anyone will want to "add" the names, but using sigma/1, it is trivial to compute the sums of the heights and weights:
|
…ields with the same name have a numerical value the corresponding field of the result object is set to the sum of the field values. (The previous behavior was for one of the values to just be discarded.)
Before:
After:
Perhaps this operator should be given a new name since users might be relying on its current behavior.