Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add thetaSketch aggregator #41

Merged
merged 4 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions builder/aggregation/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func Load(data []byte) (builder.Aggregator, error) {
a = NewStringLast()
case "tDigestSketch":
a = NewTDigestSketch()
case "thetaSketch":
a = NewThetaSketch()
default:
return nil, errors.New("unsupported aggregation type")
}
Expand Down
41 changes: 41 additions & 0 deletions builder/aggregation/thetasketch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package aggregation

// ThetaSketch holds the theta sketch struct based on
// Aggregator section in http://druid.apache.org/docs/latest/development/extensions-core/datasketches-theta.html
type ThetaSketch struct {
Base
FieldName string `json:"fieldName,omitempty"`
IsInputThetaSketch bool `json:"isInputThetaSketch,omitempty"`
Size int64 `json:"size, omitempty"`
}

// NewThetaSketch create a new instance of ThetaSketch
func NewThetaSketch() *ThetaSketch {
t := &ThetaSketch{}
t.Base.SetType("thetaSketch")
return t
}

// SetName set name
func (t *ThetaSketch) SetName(name string) *ThetaSketch {
t.Base.SetName(name)
return t
}

// SetFieldName set fieldName
func (t *ThetaSketch) SetFieldName(fieldName string) *ThetaSketch {
t.FieldName = fieldName
return t
}

// SetIsInputThetaSketch set theta isInputThetaSketch
func (t *ThetaSketch) SetIsInputThetaSketch(isInputThetaSketch bool) *ThetaSketch {
t.IsInputThetaSketch = isInputThetaSketch
return t
}

// SetSize set theta size
func (t *ThetaSketch) SetSize(size int64) *ThetaSketch {
t.Size = size
return t
}
19 changes: 19 additions & 0 deletions builder/aggregation/thetasketch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package aggregation

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)

func TestThetaSketch(t *testing.T) {
thetaSketch := NewThetaSketch()
thetaSketch.SetName("output_name").SetFieldName("metric_name").SetIsInputThetaSketch(false).SetSize(16384)

// "omitempty" will ignore boolean=false
expected := `{"type":"thetaSketch", "name":"output_name", "fieldName":"metric_name", "size":16384}`

thetaSketchJson, err := json.Marshal(thetaSketch)
assert.Nil(t, err)
assert.JSONEq(t, expected, string(thetaSketchJson))
}