https://github.com/akaliutau/map-redux
MapRedux is a lightweight library to aggregate data from Map-like data structures.
https://github.com/akaliutau/map-redux
data-aggregation json
Last synced: 11 days ago
JSON representation
MapRedux is a lightweight library to aggregate data from Map-like data structures.
- Host: GitHub
- URL: https://github.com/akaliutau/map-redux
- Owner: akaliutau
- License: mit
- Created: 2023-09-10T16:50:02.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-10T19:46:38.000Z (over 2 years ago)
- Last Synced: 2025-01-11T00:13:28.250Z (over 1 year ago)
- Topics: data-aggregation, json
- Language: Java
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
About
======
MapRedux is a lightweight library to aggregate data from Map-like data structures.
Motivation
===========
The library is to merge data from Map-like structures into [aggregated] Map structures.
The most useful features:
* Support of custom Reducers
* Support of sorting by multiple columns
How to use
============
Add dependency:
```
io.github.akaliutau
mapredux
0.0.5
```
Consider the following input:
```json lines
{"country": "Netherlands", "age": 25, "hobbies": "swimming", "region": "Europe", "name": "Alice"}
{"country": "US", "age": 23, "hobbies": "reading", "region": "North America", "name": "Bob"}
{"country": "US", "age": 29, "hobbies": "spying", "region": "North America", "name": "Eve"}
{"country": "South Korea", "age": 31, "hobbies": "walking", ",region": "Asia", "name": "Yuni"}
{"age": 18, "region": "North America", "name": "X"}
```
```
MapRedux mr = new MapRedux.Builder()
.select(
column("name", "count", "count"),
column("age", "avg_age", "avg"),
column("region"),
column("country"),
column("hobbies", "set")
)
.where(m -> (int) m.get("age") > 18)
.groupBy("region", "country")
.orderBy(new StringColumnComparator("region"))
.build();
List> result = mr.reduce(records);
```
Aggregated results will look like this:
```json lines
{"country": "South Korea", "avg_age": 31.0, "hobbies": ["walking"], "count": 1, "region": "Asia"}
{"country": "Netherlands", "avg_age": 25.0, "hobbies": ["swimming"], "count": 1, "region": "Europe"}
{"country": "US", "avg_age": 26.0, "hobbies": ["spying", "reading"], "count": 2, "region": "North America"}
```
Further work
============
The current version is effectively a pre-release; full release will include more features and improvements in terms of
stability and performance