Skip to content

Commit

Permalink
kvstore: implemented percentile aggregation method
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck committed May 2, 2018
1 parent b5fdc9f commit dc65548
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 0 additions & 1 deletion conformance/tests/ot_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def test_histogram_aggregation(O):

count = 0
for row in O.aggregate(aql.histogram("test-agg", "Person", "age", 5)):
print(row)
count += 1
if len(row["buckets"]) != 6:
errors.append(
Expand Down
4 changes: 2 additions & 2 deletions elastic/es_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (es *Graph) GetVertexPercentileAggregation(ctx context.Context, name string
if err != nil {
return nil, fmt.Errorf("percentile key conversion failed: %s", err)
}
term := protoutil.WrapValue(keyf)
out.Buckets = append(out.Buckets, &aql.AggregationResult{Key: term, Value: float64(val)})
key := protoutil.WrapValue(keyf)
out.Buckets = append(out.Buckets, &aql.AggregationResult{Key: key, Value: float64(val)})
}
}

Expand Down
23 changes: 17 additions & 6 deletions kvgraph/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (

"github.com/bmeg/arachne/aql"
"github.com/bmeg/arachne/protoutil"
"github.com/spenczar/tdigest"
// "github.com/bmizerany/perks/quantile"
// "github.com/dgryski/go-gk"
)

func (kgraph *KVGraph) setupGraphIndex(graph string) error {
Expand Down Expand Up @@ -132,17 +135,25 @@ func (kgdb *KVInterfaceGDB) GetVertexHistogramAggregation(ctx context.Context, n
}
out.Buckets = append(out.Buckets, &aql.AggregationResult{Key: protoutil.WrapValue(bucket), Value: float64(count)})
}

return out, nil
}

//GetVertexPercentileAggregation get percentiles of a term across vertices
func (kgdb *KVInterfaceGDB) GetVertexPercentileAggregation(ctx context.Context, name string, label string, field string, percents []float64) (*aql.NamedAggregationResult, error) {
log.Printf("Running GetVertexPercentileAggregation: { label: %s, field: %s percents: %v }", label, field, percents)
// out := &aql.NamedAggregationResult{
// Name: name,
// Buckets: []*aql.AggregationResult{},
// }
// buckets := []*aql.AggregationResult{}
out := &aql.NamedAggregationResult{
Name: name,
Buckets: []*aql.AggregationResult{},
}

return nil, fmt.Errorf("not implemented")
td := tdigest.New()
for val := range kgdb.kvg.idx.FieldNumbers(fmt.Sprintf("%s.v.%s.%s", kgdb.graph, label, field)) {
td.Add(val, 1)
}
for _, p := range percents {
out.Buckets = append(out.Buckets, &aql.AggregationResult{Key: protoutil.WrapValue(p), Value: td.Quantile(p / 100)})
}

return out, nil
}

0 comments on commit dc65548

Please sign in to comment.