-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding missing post aggregate for Quantiles double sketch. (#76)
- Loading branch information
1 parent
c9db3cc
commit b2d2228
Showing
8 changed files
with
249 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
builder/postaggregation/quantiles_doubles_sketch_to_cdf.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package postaggregation | ||
|
||
// QuantilesDoublesSketchToCDF struct based on | ||
// PostAggregator section in https://druid.apache.org/docs/latest/development/extensions-core/datasketches-quantiles.html#cdf | ||
type QuantilesDoublesSketchToCDF struct { | ||
Base | ||
Field *QuantilesDoublesSketchField `json:"field,omitempty"` | ||
SplitPoints []float64 `json:"splitPoints,omitempty"` | ||
} | ||
|
||
// NewQuantilesDoublesSketchToCDF new instance of QuantilesDoublesSketchToCDF | ||
func NewQuantilesDoublesSketchToCDF() *QuantilesDoublesSketchToCDF { | ||
q := &QuantilesDoublesSketchToCDF{} | ||
q.SetType("quantilesDoublesSketchToCDF") | ||
return q | ||
} | ||
|
||
// SetName set name | ||
func (q *QuantilesDoublesSketchToCDF) SetName(name string) *QuantilesDoublesSketchToCDF { | ||
q.Base.SetName(name) | ||
return q | ||
} | ||
|
||
// SetSplitPoints set splitPoints | ||
func (q *QuantilesDoublesSketchToCDF) SetSplitPoints(splitPoints []float64) *QuantilesDoublesSketchToCDF { | ||
q.SplitPoints = splitPoints | ||
return q | ||
} | ||
|
||
// SetField set QuantilesDoublesSketchField | ||
func (q *QuantilesDoublesSketchToCDF) SetField(field *QuantilesDoublesSketchField) *QuantilesDoublesSketchToCDF { | ||
q.Field = field | ||
return q | ||
} |
49 changes: 49 additions & 0 deletions
49
builder/postaggregation/quantiles_doubles_sketch_to_cdf_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package postaggregation | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestQuantilesDoublesSketchToCDF(t *testing.T) { | ||
qf := NewQuantilesDoublesSketchField() | ||
qf.SetType("fieldAccess").SetName("tp75tp90").SetFieldName("a1:agg") | ||
quantilesDoublesSketchToCDF := NewQuantilesDoublesSketchToCDF() | ||
quantilesDoublesSketchToCDF.SetName("tp75tp90").SetField(qf).SetSplitPoints([]float64{0.75, 0.90}) | ||
|
||
// "omitempty" will ignore boolean=false | ||
quantilesDoublesSketchToCDFJSON := ` | ||
{ | ||
"type": "quantilesDoublesSketchToCDF", | ||
"name": "tp75tp90", | ||
"field": { | ||
"type": "fieldAccess", | ||
"name": "tp75tp90", | ||
"fieldName": "a1:agg" | ||
}, | ||
"splitPoints": [0.75, 0.9] | ||
} | ||
` | ||
|
||
t.Run("build quantilesDoublesSketchToQuantiles", | ||
func(t *testing.T) { | ||
postAggJSON, err := json.Marshal(quantilesDoublesSketchToCDF) | ||
assert.Nil(t, | ||
err) | ||
assert.JSONEq(t, | ||
string(postAggJSON), | ||
quantilesDoublesSketchToCDFJSON) | ||
}) | ||
|
||
t.Run("load quantilesDoublesSketchToQuantiles", | ||
func(t *testing.T) { | ||
postAgg, err := Load([]byte(quantilesDoublesSketchToCDFJSON)) | ||
assert.Nil(t, | ||
err) | ||
assert.Equal(t, | ||
quantilesDoublesSketchToCDF, | ||
postAgg) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
builder/postaggregation/quantiles_doubles_sketch_to_rank.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package postaggregation | ||
|
||
// QuantilesDoublesSketchToRank struct based on | ||
// PostAggregator section in https://druid.apache.org/docs/latest/development/extensions-core/datasketches-quantiles.html#rank | ||
type QuantilesDoublesSketchToRank struct { | ||
Base | ||
Field *QuantilesDoublesSketchField `json:"field,omitempty"` | ||
Value *float64 `json:"value,omitempty"` | ||
} | ||
|
||
// NewQuantilesDoublesSketchToRank new instance of NewQuantilesDoublesSketchToRank | ||
func NewQuantilesDoublesSketchToRank() *QuantilesDoublesSketchToRank { | ||
q := &QuantilesDoublesSketchToRank{} | ||
q.SetType("quantilesDoublesSketchToRank") | ||
return q | ||
} | ||
|
||
// SetName set name | ||
func (q *QuantilesDoublesSketchToRank) SetName(name string) *QuantilesDoublesSketchToRank { | ||
q.Base.SetName(name) | ||
return q | ||
} | ||
|
||
// SetValue set value | ||
func (q *QuantilesDoublesSketchToRank) SetValue(value float64) *QuantilesDoublesSketchToRank { | ||
q.Value = &value | ||
return q | ||
} | ||
|
||
// SetField set QuantilesDoublesSketchField | ||
func (q *QuantilesDoublesSketchToRank) SetField(field *QuantilesDoublesSketchField) *QuantilesDoublesSketchToRank { | ||
q.Field = field | ||
return q | ||
} |
50 changes: 50 additions & 0 deletions
50
builder/postaggregation/quantiles_doubles_sketch_to_rank_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package postaggregation | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestQuantilesDoublesSketchToRank(t *testing.T) { | ||
qf := NewQuantilesDoublesSketchField() | ||
qf.SetType("fieldAccess").SetName("tp90").SetFieldName("a1:agg") | ||
quantilesDoublesSketchToRank := NewQuantilesDoublesSketchToRank() | ||
quantilesDoublesSketchToRank.SetName("tp90").SetField(qf).SetValue(0.90) | ||
|
||
// "omitempty" will ignore boolean=false | ||
quantilesDoublesSketchToRankJSON := ` | ||
{ | ||
"type": "quantilesDoublesSketchToRank", | ||
"name": "tp90", | ||
"field": { | ||
"type": "fieldAccess", | ||
"name": "tp90", | ||
"fieldName": "a1:agg" | ||
}, | ||
"value": 0.9 | ||
} | ||
` | ||
|
||
t.Run("build quantilesDoublesSketchToRank", | ||
func(t *testing.T) { | ||
postAggJSON, err := json.Marshal(quantilesDoublesSketchToRank) | ||
assert.Nil(t, | ||
err) | ||
assert.JSONEq(t, | ||
string(postAggJSON), | ||
quantilesDoublesSketchToRankJSON) | ||
}) | ||
|
||
t.Run("load quantilesDoublesSketchToRank", | ||
func(t *testing.T) { | ||
postAgg, err := Load([]byte(quantilesDoublesSketchToRankJSON)) | ||
assert.Nil(t, | ||
err) | ||
assert.Equal(t, | ||
quantilesDoublesSketchToRank, | ||
postAgg) | ||
}) | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
builder/postaggregation/quantiles_doubles_sketch_to_string.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package postaggregation | ||
|
||
// QuantilesDoublesSketchToString struct based on | ||
// PostAggregator section in https://druid.apache.org/docs/latest/development/extensions-core/datasketches-quantiles.html#sketch-summary | ||
type QuantilesDoublesSketchToString struct { | ||
Base | ||
Field *QuantilesDoublesSketchField `json:"field,omitempty"` | ||
} | ||
|
||
// NewQuantilesDoublesSketchToString new instance of QuantilesDoublesSketchToString | ||
func NewQuantilesDoublesSketchToString() *QuantilesDoublesSketchToString { | ||
q := &QuantilesDoublesSketchToString{} | ||
q.SetType("quantilesDoublesSketchToString") | ||
return q | ||
} | ||
|
||
// SetName set name | ||
func (q *QuantilesDoublesSketchToString) SetName(name string) *QuantilesDoublesSketchToString { | ||
q.Base.SetName(name) | ||
return q | ||
} | ||
|
||
// SetField set QuantilesDoublesSketchField | ||
func (q *QuantilesDoublesSketchToString) SetField(field *QuantilesDoublesSketchField) *QuantilesDoublesSketchToString { | ||
q.Field = field | ||
return q | ||
} |
48 changes: 48 additions & 0 deletions
48
builder/postaggregation/quantiles_doubles_sketch_to_string_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package postaggregation | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestQuantilesDoublesSketchToString(t *testing.T) { | ||
qf := NewQuantilesDoublesSketchField() | ||
qf.SetType("fieldAccess").SetName("tp75tp90").SetFieldName("a1:agg") | ||
quantilesDoublesSketchToString := NewQuantilesDoublesSketchToString() | ||
quantilesDoublesSketchToString.SetName("tp75tp90").SetField(qf) | ||
|
||
// "omitempty" will ignore boolean=false | ||
quantilesDoublesSketchToStringJSON := ` | ||
{ | ||
"type": "quantilesDoublesSketchToString", | ||
"name": "tp75tp90", | ||
"field": { | ||
"type": "fieldAccess", | ||
"name": "tp75tp90", | ||
"fieldName": "a1:agg" | ||
} | ||
} | ||
` | ||
|
||
t.Run("build quantilesDoublesSketchToString", | ||
func(t *testing.T) { | ||
postAggJSON, err := json.Marshal(quantilesDoublesSketchToString) | ||
assert.Nil(t, | ||
err) | ||
assert.JSONEq(t, | ||
string(postAggJSON), | ||
quantilesDoublesSketchToStringJSON) | ||
}) | ||
|
||
t.Run("load quantilesDoublesSketchToString", | ||
func(t *testing.T) { | ||
postAgg, err := Load([]byte(quantilesDoublesSketchToStringJSON)) | ||
assert.Nil(t, | ||
err) | ||
assert.Equal(t, | ||
quantilesDoublesSketchToString, | ||
postAgg) | ||
}) | ||
} |