Skip to content

Commit

Permalink
Merge pull request #2 from caffinc/development
Browse files Browse the repository at this point in the history
Updating Readme and POM for release
  • Loading branch information
SriramKeerthi authored Nov 27, 2016
2 parents 4ae2682 + 581e465 commit 44e5d91
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
*.iml
target/
dependency-reduced-pom.xml
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,79 @@
# jaggr
Simple JSON Aggregator for Java

## Build Status
![Travis-CI Build Status](https://travis-ci.org/caffinc/jaggr.svg?branch=master)

## Usage
jaggr is on Bintray and Maven Central (Soon):

<dependency>
<groupId>com.caffinc</groupId>
<artifactId>jaggr</artifactId>
<version>0.1</version>
</dependency>

Assume the following JSON documents are stored in a file called `raw.json`:

{"_id": 1, "f": "a", "test": {"f": 3}}
{"_id": 2, "f": "a", "test": {"f": 2}}
{"_id": 3, "f": "a", "test": {"f": 1}}
{"_id": 4, "f": "a", "test": {"f": 5}}
{"_id": 5, "f": "a", "test": {"f": -1}}
{"_id": 6, "f": "b", "test": {"f": 1}}
{"_id": 7, "f": "b", "test": {"f": 1}}
{"_id": 8, "f": "b", "test": {"f": 1}}
{"_id": 9, "f": "b", "test": {"f": 1}}
{"_id": 10, "f": "b", "test": {"f": 1}}

Read it in using the built in JsonFileReader using:

List<Map<String, Object>> jsonList = JsonFileReader.readJsonFromFile("raw.json");

Now various aggregations can be defined using the `AggregationBuilder`:

Aggregation aggregation = new AggregationBuilder()
.setGroupBy(field)
.addOperation("avg", new AverageOperation(avgField))
.addOperation("sum", new SumOperation(sumField))
.addOperation("min", new MinOperation(minField))
.addOperation("max", new MaxOperation(maxField))
.addOperation("count", new CountOperation())
.getAggregation();

Aggregation can now be performed using the `aggregate()` method:

List<Map<String, Object>> result = aggregation.aggregate(jsonList);

The result of the above aggregation would look as follows:

{"_id": "a", "avg": 2.0, "sum": 10, "min": -1, "max": 5, "count": 5}
{"_id": "b", "avg": 1.0, "sum": 5, "min": 1, "max": 1, "count": 5}

## Tests

There are extensive tests for each of the aggregations which can be checked out in the [https://github.com/caffinc/jaggr/blob/master/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java](https://github.com/caffinc/jaggr/blob/master/jaggr/src/test/java/com/caffinc/jaggr/core/AggregationBuilderTest.java "AggregationBuilderTest") file.

## Dependencies

These are not absolute, but are current (probably) as of 26th November, 2016. It should be trivial to upgrade or downgrade versions as required.

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

## Help

If you face any issues trying to get this to work for you, shoot me an email: [email protected].

Good luck!
62 changes: 57 additions & 5 deletions jaggr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@

<groupId>com.caffinc</groupId>
<artifactId>jaggr</artifactId>
<version>1.0-SNAPSHOT</version>
<name>jaggr - JSON Aggregator</name>
<version>0.1</version>
<name>jaggr</name>
<description>Simple JSON Aggregator for Java</description>
<url>https://github.com/caffinc/jaggr</url>

<developers>
<developer>
<name>Caffinc</name>
<email>[email protected]</email>
<organization>Caffinc</organization>
<organizationUrl>http://www.caffinc.com</organizationUrl>
</developer>
</developers>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/caffinc/jaggr</url>
</scm>


<build>
<plugins>
Expand All @@ -20,20 +44,48 @@
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<properties>
<junit-version>4.12</junit-version>
<gson-version>2.6.2</gson-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
<version>${gson-version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit 44e5d91

Please sign in to comment.