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

Group and sum over partition #30

Closed

Conversation

raffo0707
Copy link

No description provided.

@raffo0707 raffo0707 force-pushed the NI/group-and-sum-over-partition branch from b296bb3 to 7c52c6f Compare April 20, 2016 13:09
@raffo0707 raffo0707 changed the title [RFC][NI] Group and sum over partition Group and sum over partition Apr 20, 2016
@raffo0707
Copy link
Author

group_by: function for grouping over a given field;

  • usage: group_by(array, expression)

sum_by: function for summing grouping values over a field.

  • usage: sum_by(array, expression, expression)
    (the first expression is for grouping, the second one is the field to sum)

@raffo0707 raffo0707 force-pushed the NI/group-and-sum-over-partition branch from 7c52c6f to 89085b3 Compare April 20, 2016 15:34
@raffo0707 raffo0707 force-pushed the NI/group-and-sum-over-partition branch from 89085b3 to 436684d Compare April 20, 2016 15:49
@mtdowling
Copy link
Contributor

These are great function ideas. Before merging these here, I'd like to make sure they are first added as part of the official JMESPath spec. Could you open a PR on jmespath.site to propose these functions with examples? We'll also need compliance tests added to jmespath.test.

One idea I've had for sum_by and related reducing functions is to just add a reduce function to jmespath. We could also add arithmetic operators like "+", "-", etc, or arithmetic functions. Then things like sum_by could become something like:

reduce(foo[*], &carry + item)

We'd need to figure out how to bind carry and item to the reducing function (e.g., do we bind an object with carry and item keys, or a list with [0] and [1], or something else).

@raffo0707 raffo0707 closed this Nov 14, 2017
@raffo0707 raffo0707 deleted the NI/group-and-sum-over-partition branch November 14, 2017 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants