Skip to content

Support aggregates and folds over arrays #38

Description

@Mearman

Sums, counts and similar folds lose the elements they combine, so they have no inverse and can only be one-way rules. Nothing in the rule set read more than one element into one value.

Decision: implement a one-way aggregate rule with a named direction: { op: "aggregate", fn: "sum", from: "orders[].lines[].qty", to: "sales[].units", direction: "encode" }, with fn one of count, sum, min and max. It reads the input document of the run, after the two-way rules have written. to has fewer wildcards than from, and the elements are grouped by their indexes at the wildcards to keeps, so the example writes one total per order; the groups are enumerated from the arrays themselves, so an order with no lines gets 0. count counts any value; the others take finite numbers, a sum that overflows throws, and min or max of an empty group throws because it has no answer. validateCrosswalk checks the wildcard counts and that the arrays to keeps are the counterparts of the arrays from groups by. assertRoundTrip leaves out a decode-direction aggregate's to, as it does a decode-direction default.

Implemented in #55.

Activity

  1. added
    enhancementNew feature or request
    deferredDeliberately not built yet, with a trigger for revisiting
    on Oct 20, 2026
  2. added theissue type on Oct 20, 2026
  3. github-actions commented on Oct 21, 2026

    @github-actions

    🎉 This issue has been resolved in version 0.7.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    deferredDeliberately not built yet, with a trigger for revisitingenhancementNew feature or requestreleased

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions