😡 In memory dataset bucketing and metrics, inspired by Elasticsearch aggregations
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
aggro_test.go
cell.go
dataset.go
datetime.go
datetime_test.go
field.go
metrics.go
processor.go
query.go
range.go
resultset.go
resultset_test.go
sort.go
table.go

README.md

aggro 😡

GoDoc Go Report Card

In memory dataset bucketing and metrics, inspired by Elasticsearch aggregations

Installation

go get -u github.com/snikch/aggro

Example

Given a dataset...

rows := []map[string]interface{}{
		{"location": "Auckland", "department": "Engineering", "salary": 120000, "start_date": "2016-01-31T22:00:00Z"},
		{"location": "Auckland", "department": "Engineering", "salary": 80000, "start_date": "2016-03-23T22:00:00Z"},
		{"location": "Auckland", "department": "Marketing", "salary": 90000, "start_date": "2016-01-31T22:00:00Z"},
		{"location": "Auckland", "department": "Marketing", "salary": 150000, "start_date": "2016-01-23T22:00:00Z"},
		{"location": "Wellington", "department": "Engineering", "salary": 120000, "start_date": "2016-01-23T22:00:00Z"},
		{"location": "Wellington", "department": "Engineering", "salary": 160000, "start_date": "2016-03-23T22:00:00Z"},
		{"location": "Wellington", "department": "Engineering", "salary": 120000, "start_date": "2016-02-02T22:00:00Z"},
	}

Initialize aggro, build aggregations and run...

// Build a dataset that contains a *Table representing your data.
dataset := &Dataset{
	Table: &Table{
		Fields: []Field{
			{"location", "string"},
			{"department", "string"},
			{"salary", "number"},
			{"start_date", "datetime"},
		},
	},
}

// Add our rows to our dataset.
err := dataset.AddRows(rows...)
if err != nil {
	return err
}

// Build our query specifying preferred metrics and bucket composition.
query := &Query{
    Metrics: []Metric{
        {Type: "max", Field: "salary"},
        {Type: "min", Field: "salary"},
    },
    Bucket: &Bucket{
        Field: &Field{
            Name: "location",
            Type: "string",
        },
        Sort: &SortOptions{
            Type: "alphabetical",
        },
        Bucket: &Bucket{
            Field: &Field{
                Name: "department",
                Type: "string",
            },
            Sort: &SortOptions{
                Type: "alphabetical",
            },
        },
    },
}

// Run it.
results, err := dataset.Run(query)
if err != nil {
	return err
}

Find a list of available measurers here