Skip to content

Add map/reduce property aggregation (Supercluster parity) #1

Description

@StoneTapeStudios

Supercluster supports map and reduce options that let users aggregate custom properties per cluster. For example, summing a numeric property across all points in a cluster:

const index = new Supercluster({
  map: (props) => ({ sum: props.myValue }),
  reduce: (accumulated, props) => {
    accumulated.sum += props.sum;
  },
});

This is one of Supercluster's most-used features. arrow-supercluster doesn't support it yet.

What needs to happen

  • Add optional map and reduce fields to ArrowClusterEngineOptions in packages/arrow-supercluster/src/types.ts
  • During clustering in _cluster() (packages/arrow-supercluster/src/arrow-cluster-engine.ts), call map for leaf points and reduce when merging points into clusters
  • Store the aggregated properties and expose them in ClusterOutput (likely a new properties array or similar)
  • The tricky part: ClusterOutput currently uses only typed arrays. Aggregated properties are user-defined objects, so this needs a design decision on how to expose them without breaking the typed-array-only contract
  • Add tests in packages/arrow-supercluster/tests/

References

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions