项目作者: snikch

项目描述 :
😡 In memory dataset bucketing and metrics, inspired by Elasticsearch aggregations
高级语言: Go
项目地址: git://github.com/snikch/aggro.git
创建时间: 2016-11-15T12:14:01Z
项目社区:https://github.com/snikch/aggro

开源协议:MIT License

下载


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…

  1. rows := []map[string]interface{}{
  2. {"location": "Auckland", "department": "Engineering", "salary": 120000, "start_date": "2016-01-31T22:00:00Z"},
  3. {"location": "Auckland", "department": "Engineering", "salary": 80000, "start_date": "2016-03-23T22:00:00Z"},
  4. {"location": "Auckland", "department": "Marketing", "salary": 90000, "start_date": "2016-01-31T22:00:00Z"},
  5. {"location": "Auckland", "department": "Marketing", "salary": 150000, "start_date": "2016-01-23T22:00:00Z"},
  6. {"location": "Wellington", "department": "Engineering", "salary": 120000, "start_date": "2016-01-23T22:00:00Z"},
  7. {"location": "Wellington", "department": "Engineering", "salary": 160000, "start_date": "2016-03-23T22:00:00Z"},
  8. {"location": "Wellington", "department": "Engineering", "salary": 120000, "start_date": "2016-02-02T22:00:00Z"},
  9. }

Initialize aggro, build aggregations and run…

  1. // Build a dataset that contains a *Table representing your data.
  2. dataset := &Dataset{
  3. Table: &Table{
  4. Fields: []Field{
  5. {"location", "string"},
  6. {"department", "string"},
  7. {"salary", "number"},
  8. {"start_date", "datetime"},
  9. },
  10. },
  11. }
  12. // Add our rows to our dataset.
  13. err := dataset.AddRows(rows...)
  14. if err != nil {
  15. return err
  16. }
  17. // Build our query specifying preferred metrics and bucket composition.
  18. query := &Query{
  19. Metrics: []Metric{
  20. {Type: "max", Field: "salary"},
  21. {Type: "min", Field: "salary"},
  22. },
  23. Bucket: &Bucket{
  24. Field: &Field{
  25. Name: "location",
  26. Type: "string",
  27. },
  28. Sort: &SortOptions{
  29. Type: "alphabetical",
  30. },
  31. Bucket: &Bucket{
  32. Field: &Field{
  33. Name: "department",
  34. Type: "string",
  35. },
  36. Sort: &SortOptions{
  37. Type: "alphabetical",
  38. },
  39. },
  40. },
  41. }
  42. // Run it.
  43. results, err := dataset.Run(query)
  44. if err != nil {
  45. return err
  46. }

Find a list of available measurers here