Skip to content

Commit

Permalink
Fix agg post agg (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-chichu authored and dhia-gharsallaoui committed Sep 22, 2022
1 parent a8df7d0 commit d286e7b
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 40 deletions.
25 changes: 20 additions & 5 deletions builder/aggregation/quantiles_doubles_sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ import (
func TestQuantilesDoublesSketch(t *testing.T) {
quantilesDoublesSketch := NewQuantilesDoublesSketch()
quantilesDoublesSketch.SetName("output_name").SetFieldName("metric_name").SetK(100)

// "omitempty" will ignore boolean=false
expected := `{"type":"quantilesDoublesSketch", "name":"output_name", "fieldName": "metric_name", "k":100}`
quantilesDoublesSketchJSON := `{"type":"quantilesDoublesSketch", "name":"output_name", "fieldName": "metric_name", "k":100}`

t.Run("build quantilesDoublesSketch",
func(t *testing.T) {
aggJSON, err := json.Marshal(quantilesDoublesSketch)
assert.Nil(t,
err)
assert.JSONEq(t,
quantilesDoublesSketchJSON,
string(aggJSON))
})

quantilesDoublesSketchJSON, err := json.Marshal(quantilesDoublesSketch)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantilesDoublesSketchJSON))
t.Run("load quantilesDoublesSketch",
func(t *testing.T) {
agg, err := Load([]byte(quantilesDoublesSketchJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesDoublesSketch,
agg)
})
}
6 changes: 6 additions & 0 deletions builder/postaggregation/post_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ func Load(data []byte) (builder.PostAggregator, error) {
p = NewLongGreatest()
case "longLeast":
p = NewLongLeast()
case "quantileFromTDigestSketch":
p = NewQuantileFromTDigestSketch()
case "quantilesFromTDigestSketch":
p = NewQuantilesFromTDigestSketch()
case "quantilesDoublesSketchToQuantile":
p = NewQuantilesDoublesSketchToQuantile()
case "quantilesDoublesSketchToQuantiles":
p = NewQuantilesDoublesSketchToQuantiles()
case "quantilesDoublesSketchToHistogram":
p = NewQuantilesDoublesSketchToHistogram()
default:
return nil, errors.New("unsupported postaggregation type")
}
Expand Down
24 changes: 20 additions & 4 deletions builder/postaggregation/quantile_from_tdigestsketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
)

func TestQuantileFromTDigestSketch(t *testing.T) {

qf := NewQuantileFromTDigestSketchField()
qf.SetType("fieldAccess").SetFieldName("merged_sketch")
quantilesFromTDigestSketch := NewQuantileFromTDigestSketch()
quantilesFromTDigestSketch.SetName("tp90").SetField(qf).SetFraction(0.90)

// "omitempty" will ignore boolean=false
expected := `
quantileFromTDigestSketchJSON := `
{
"type": "quantileFromTDigestSketch",
"name": "tp90",
Expand All @@ -24,8 +25,23 @@ func TestQuantileFromTDigestSketch(t *testing.T) {
"fraction": 0.9
}
`
t.Run("build quantileFromTDigestSketch",
func(t *testing.T) {
postAggJSON, err := json.Marshal(quantilesFromTDigestSketch)
assert.Nil(t,
err)
assert.JSONEq(t,
quantileFromTDigestSketchJSON,
string(postAggJSON))
})

quantileFromTDigestSketchJSON, err := json.Marshal(quantilesFromTDigestSketch)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantileFromTDigestSketchJSON))
t.Run("load quantileFromTDigestSketch",
func(t *testing.T) {
postAgg, err := Load([]byte(quantileFromTDigestSketchJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesFromTDigestSketch,
postAgg)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestQuantilesDoublesSketchToHistogram_SetNumBins(t *testing.T) {
quantilesDoublesSketchToHistogram.SetName("h").SetField(qf).SetNumBins(2)

// "omitempty" will ignore boolean=false
expected := `
quantilesDoublesSketchToHistogramJSON := `
{
"type": "quantilesDoublesSketchToHistogram",
"name": "h",
Expand All @@ -26,9 +26,25 @@ func TestQuantilesDoublesSketchToHistogram_SetNumBins(t *testing.T) {
}
`

quantilesDoublesSketchToHistogramJSON, err := json.Marshal(quantilesDoublesSketchToHistogram)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantilesDoublesSketchToHistogramJSON))
t.Run("build quantilesDoublesSketchToHistogram",
func(t *testing.T) {
postAggJSON, err := json.Marshal(quantilesDoublesSketchToHistogram)
assert.Nil(t,
err)
assert.JSONEq(t,
string(postAggJSON),
quantilesDoublesSketchToHistogramJSON)
})

t.Run("load quantilesDoublesSketchToHistogram",
func(t *testing.T) {
postAgg, err := Load([]byte(quantilesDoublesSketchToHistogramJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesDoublesSketchToHistogram,
postAgg)
})
}

func TestQuantilesDoublesSketchToHistogram_SetSplitPoints(t *testing.T) {
Expand All @@ -38,7 +54,7 @@ func TestQuantilesDoublesSketchToHistogram_SetSplitPoints(t *testing.T) {
quantilesDoublesSketchToHistogram.SetName("h").SetField(qf).SetSplitPoints([]float64{0.5, 1.5, 2.0})

// "omitempty" will ignore boolean=false
expected := `
quantilesDoublesSketchToHistogramJSON := `
{
"type": "quantilesDoublesSketchToHistogram",
"name": "h",
Expand All @@ -51,7 +67,23 @@ func TestQuantilesDoublesSketchToHistogram_SetSplitPoints(t *testing.T) {
}
`

quantilesDoublesSketchToHistogramJSON, err := json.Marshal(quantilesDoublesSketchToHistogram)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantilesDoublesSketchToHistogramJSON))
t.Run("build quantilesDoublesSketchToHistogram",
func(t *testing.T) {
postAggJSON, err := json.Marshal(quantilesDoublesSketchToHistogram)
assert.Nil(t,
err)
assert.JSONEq(t,
string(postAggJSON),
quantilesDoublesSketchToHistogramJSON)
})

t.Run("load quantilesDoublesSketchToHistogram",
func(t *testing.T) {
postAgg, err := Load([]byte(quantilesDoublesSketchToHistogramJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesDoublesSketchToHistogram,
postAgg)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestQuantilesDoublesSketchToQuantile(t *testing.T) {
quantilesDoublesSketchToQuantile.SetName("tp90").SetField(qf).SetFraction(0.90)

// "omitempty" will ignore boolean=false
expected := `
quantilesDoublesSketchToQuantileJSON := `
{
"type": "quantilesDoublesSketchToQuantile",
"name": "tp90",
Expand All @@ -26,7 +26,23 @@ func TestQuantilesDoublesSketchToQuantile(t *testing.T) {
}
`

quantilesDoublesSketchToQuantileJSON, err := json.Marshal(quantilesDoublesSketchToQuantile)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantilesDoublesSketchToQuantileJSON))
t.Run("build quantilesDoublesSketchToQuantile",
func(t *testing.T) {
postAggJSON, err := json.Marshal(quantilesDoublesSketchToQuantile)
assert.Nil(t,
err)
assert.JSONEq(t,
string(postAggJSON),
quantilesDoublesSketchToQuantileJSON)
})

t.Run("load quantilesDoublesSketchToQuantile",
func(t *testing.T) {
postAgg, err := Load([]byte(quantilesDoublesSketchToQuantileJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesDoublesSketchToQuantile,
postAgg)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@ func TestQuantilesDoublesSketchToQuantiles(t *testing.T) {
quantilesDoublesSketchToQuantiles.SetName("tp75tp90").SetField(qf).SetFractions([]float64{0.75, 0.90})

// "omitempty" will ignore boolean=false
expected := `
{
"type": "quantilesDoublesSketchToQuantiles",
"name": "tp75tp90",
"field": {
"type": "fieldAccess",
"name": "tp75tp90",
"fieldName": "a1:agg"
},
"fractions": [0.75, 0.9]
}
`
quantilesDoublesSketchToQuantilesJSON := `
{
"type": "quantilesDoublesSketchToQuantiles",
"name": "tp75tp90",
"field": {
"type": "fieldAccess",
"name": "tp75tp90",
"fieldName": "a1:agg"
},
"fractions": [0.75, 0.9]
}
`

t.Run("build quantilesDoublesSketchToQuantiles",
func(t *testing.T) {
postAggJSON, err := json.Marshal(quantilesDoublesSketchToQuantiles)
assert.Nil(t,
err)
assert.JSONEq(t,
string(postAggJSON),
quantilesDoublesSketchToQuantilesJSON)
})

quantilesDoublesSketchToQuantilesJSON, err := json.Marshal(quantilesDoublesSketchToQuantiles)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantilesDoublesSketchToQuantilesJSON))
t.Run("load quantilesDoublesSketchToQuantiles",
func(t *testing.T) {
postAgg, err := Load([]byte(quantilesDoublesSketchToQuantilesJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesDoublesSketchToQuantiles,
postAgg)
})
}
24 changes: 20 additions & 4 deletions builder/postaggregation/quantiles_from_tdigestsketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestQuantilesFromTDigestSketch(t *testing.T) {
quantilesFromTDigestSketch.SetName("tp75tp90").SetField(qf).SetFractions([]float64{0.75, 0.90})

// "omitempty" will ignore boolean=false
expected := `
quantilesFromTDigestSketchJSON := `
{
"type": "quantilesFromTDigestSketch",
"name": "tp75tp90",
Expand All @@ -25,7 +25,23 @@ func TestQuantilesFromTDigestSketch(t *testing.T) {
}
`

quantilesFromTDigestSketchJSON, err := json.Marshal(quantilesFromTDigestSketch)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(quantilesFromTDigestSketchJSON))
t.Run("build quantilesFromTDigestSketch",
func(t *testing.T) {
postAggJSON, err := json.Marshal(quantilesFromTDigestSketch)
assert.Nil(t,
err)
assert.JSONEq(t,
string(postAggJSON),
quantilesFromTDigestSketchJSON)
})

t.Run("load quantilesFromTDigestSketch",
func(t *testing.T) {
postAgg, err := Load([]byte(quantilesFromTDigestSketchJSON))
assert.Nil(t,
err)
assert.Equal(t,
quantilesFromTDigestSketch,
postAgg)
})
}

0 comments on commit d286e7b

Please sign in to comment.