In memory dataset filtering.
go get -u github.com/mattevans/distil
Given a dataset...
data := []map[string]interface{}{
{"location": "New York", "department": "Engineering", "salary": 120000, "start_date": "2016-01-23T12:00:00Z"},
{"location": "New York", "department": "Engineering", "salary": 80000, "start_date": "2016-03-23T12:00:00Z"},
{"location": "New York", "department": "Marketing", "salary": 90000, "start_date": "2016-01-23T12:00:00Z"},
{"location": "New York", "department": "Marketing", "salary": 150000, "start_date": "2016-01-23T12:00:00Z"},
{"location": "Chicago", "department": "Engineering", "salary": 120000, "start_date": "2016-01-23T12:00:00Z"},
{"location": "Chicago", "department": "Engineering", "salary": 160000, "start_date": "2016-03-23T12:00:00Z"},
}
Initialize distil, build filters and run...
// Init distil dataset.
dataset := NewDataset(data...)
// Build a distil query and apply filters.
query := &Query{}
query.Filters = append(query.Filters, Filter{
Field: "location",
Value: "Chicago",
Operator: Operator{
Code: "eq",
Type: "string",
},
})
// Run it.
results, err := dataset.Run(query)
if err != nil {
errors.New("Unexpected error running query: %s", err.Error())
}
Returns...
[]map[string]interface{}{
{"location": "Chicago", "department": "Engineering", "salary": 120000, "start_date": "2016-01-23T12:00:00Z"},
{"location": "Chicago", "department": "Engineering", "salary": 160000, "start_date": "2016-03-23T12:00:00Z"},
}
Find a list of available operators here.
The packages's architecture is adapted from aggro, created by Mal Curtis. 🍻
If you've found a bug or would like to contribute, please create an issue here on GitHub, or better yet fork the project and submit a pull request!