Skip to content

mattevans/distil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

dc0274f Β· Aug 29, 2021

History

19 Commits
Aug 29, 2021
Feb 22, 2019
Dec 19, 2016
Aug 29, 2021
Dec 19, 2016
Nov 14, 2017
Oct 17, 2017
Dec 19, 2016
Dec 19, 2016
Oct 31, 2017
Oct 31, 2017
Dec 19, 2016
Aug 29, 2021
Aug 29, 2021
Dec 19, 2016
Dec 19, 2016
Dec 19, 2016
Dec 19, 2016
Oct 31, 2017
Oct 31, 2017
Dec 19, 2016
Dec 19, 2016
Oct 31, 2017
Oct 31, 2017
Dec 19, 2016
Dec 19, 2016
Dec 19, 2016
Dec 19, 2016
Oct 17, 2017
Dec 19, 2016
Oct 17, 2017
Dec 19, 2016
Oct 31, 2017
Dec 19, 2016
Oct 17, 2017
Dec 19, 2016
Dec 19, 2016
Dec 19, 2016
Dec 19, 2016
Feb 22, 2019
Feb 22, 2019
Feb 22, 2019

Repository files navigation

distil πŸ’§

GoDoc Build Status Go Report Card license

In memory dataset filtering.

Installation

go get -u github.com/mattevans/distil

Example

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.

Thanks & Acknowledgements πŸ‘Œ

The packages's architecture is adapted from aggro, created by Mal Curtis. 🍻

Contributing

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!