diff --git a/builder/bound/radius.go b/builder/bound/radius.go index 32d19c7..cf044a5 100644 --- a/builder/bound/radius.go +++ b/builder/bound/radius.go @@ -3,7 +3,7 @@ package bound type Radius struct { Base Coords []float64 `json:"coords,omitempty"` - Radius float64 `json:"radius,omitempty"` + Radius *float64 `json:"radius,omitempty"` } func NewRadius() *Radius { @@ -18,6 +18,6 @@ func (r *Radius) SetCoords(coords []float64) *Radius { } func (r *Radius) SetRadius(radius float64) *Radius { - r.Radius = radius + r.Radius = &radius return r } diff --git a/builder/extractionfn/bucket.go b/builder/extractionfn/bucket.go index 3fc73cc..c85e5ea 100644 --- a/builder/extractionfn/bucket.go +++ b/builder/extractionfn/bucket.go @@ -2,8 +2,8 @@ package extractionfn type Bucket struct { Base - Size float64 `json:"size,omitempty"` - Offset float64 `json:"offset,omitempty"` + Size *float64 `json:"size,omitempty"` + Offset *float64 `json:"offset,omitempty"` } func NewBucket() *Bucket { @@ -13,11 +13,11 @@ func NewBucket() *Bucket { } func (b *Bucket) SetSize(size float64) *Bucket { - b.Size = size + b.Size = &size return b } func (b *Bucket) SetOffset(offset float64) *Bucket { - b.Offset = offset + b.Offset = &offset return b } diff --git a/builder/havingspec/equal_to.go b/builder/havingspec/equal_to.go index 2634e9b..bd8dfe4 100644 --- a/builder/havingspec/equal_to.go +++ b/builder/havingspec/equal_to.go @@ -2,8 +2,8 @@ package havingspec type EqualTo struct { Base - Aggregation string `json:"aggregation,omitempty"` - Value float64 `json:"value,omitempty"` + Aggregation string `json:"aggregation,omitempty"` + Value *float64 `json:"value,omitempty"` } func NewEqualTo() *EqualTo { @@ -18,6 +18,6 @@ func (e *EqualTo) SetAggregation(aggregation string) *EqualTo { } func (e *EqualTo) SetValue(value float64) *EqualTo { - e.Value = value + e.Value = &value return e } diff --git a/builder/havingspec/greather_than.go b/builder/havingspec/greather_than.go index 67fa5b7..e0ce389 100644 --- a/builder/havingspec/greather_than.go +++ b/builder/havingspec/greather_than.go @@ -2,8 +2,8 @@ package havingspec type GreaterThan struct { Base - Aggregation string `json:"aggregation,omitempty"` - Value float64 `json:"value,omitempty"` + Aggregation string `json:"aggregation,omitempty"` + Value *float64 `json:"value,omitempty"` } func NewGreaterThan() *GreaterThan { @@ -18,6 +18,6 @@ func (g *GreaterThan) SetAggregation(aggregation string) *GreaterThan { } func (g *GreaterThan) SetValue(value float64) *GreaterThan { - g.Value = value + g.Value = &value return g } diff --git a/builder/havingspec/having_spec_test.go b/builder/havingspec/having_spec_test.go index b35715d..954467a 100644 --- a/builder/havingspec/having_spec_test.go +++ b/builder/havingspec/having_spec_test.go @@ -1,6 +1,7 @@ package havingspec import ( + "encoding/json" "testing" "github.com/stretchr/testify/assert" @@ -15,3 +16,42 @@ func TestLoadUnsupportedType(t *testing.T) { assert.NotNil(err, "error should not be nil") assert.Error(err, "unsupported havingspec type") } + +func TestEqualTo(t *testing.T) { + having := NewEqualTo() + having.SetValue(0) + having.SetAggregation("agg") + + got, err := json.Marshal(having) + assert.Nil(t, err) + assert.JSONEq(t, `{"aggregation":"agg", "type":"equalTo", "value":0}`, string(got)) +} + +func TestGreaterThan(t *testing.T) { + having := NewGreaterThan() + having.SetValue(1) + having.SetAggregation("agg") + + got, err := json.Marshal(having) + assert.Nil(t, err) + assert.JSONEq(t, `{"aggregation":"agg", "type":"greaterThan", "value":1}`, string(got)) +} + +func TestLessThan(t *testing.T) { + having := NewLessThan() + having.SetValue(3) + having.SetAggregation("agg") + + got, err := json.Marshal(having) + assert.Nil(t, err) + assert.JSONEq(t, `{"aggregation":"agg", "type":"lessThan", "value":3}`, string(got)) +} + +func TestLessThan_OmitEmpty(t *testing.T) { + having := NewLessThan() + having.SetAggregation("agg") + + got, err := json.Marshal(having) + assert.Nil(t, err) + assert.JSONEq(t, `{"aggregation":"agg", "type":"lessThan"}`, string(got)) +} diff --git a/builder/havingspec/less_than.go b/builder/havingspec/less_than.go index a1c1e3f..6ec9ba4 100644 --- a/builder/havingspec/less_than.go +++ b/builder/havingspec/less_than.go @@ -2,8 +2,8 @@ package havingspec type LessThan struct { Base - Aggregation string `json:"aggregation,omitempty"` - Value float64 `json:"value,omitempty"` + Aggregation string `json:"aggregation,omitempty"` + Value *float64 `json:"value,omitempty"` } func NewLessThan() *LessThan { @@ -18,6 +18,6 @@ func (l *LessThan) SetAggregation(aggregation string) *LessThan { } func (l *LessThan) SetValue(value float64) *LessThan { - l.Value = value + l.Value = &value return l } diff --git a/builder/postaggregation/constant.go b/builder/postaggregation/constant.go index f662f97..afe2f61 100644 --- a/builder/postaggregation/constant.go +++ b/builder/postaggregation/constant.go @@ -2,7 +2,7 @@ package postaggregation type Constant struct { Base - Value float64 `json:"value,omitempty"` + Value *float64 `json:"value,omitempty"` } func NewConstant() *Constant { @@ -17,6 +17,6 @@ func (c *Constant) SetName(name string) *Constant { } func (c *Constant) SetValue(value float64) *Constant { - c.Value = value + c.Value = &value return c } diff --git a/builder/postaggregation/quantile_from_tdigestsketch.go b/builder/postaggregation/quantile_from_tdigestsketch.go index 4f8a412..d4bd671 100644 --- a/builder/postaggregation/quantile_from_tdigestsketch.go +++ b/builder/postaggregation/quantile_from_tdigestsketch.go @@ -5,7 +5,7 @@ package postaggregation // See the "Similar to quantilesFromTDigestSketch except it takes in a single fraction for computing quantile" section type QuantileFromTDigestSketch struct { Base - Fraction float64 `json:"fraction,omitempty"` + Fraction *float64 `json:"fraction,omitempty"` Field *QuantileFromTDigestSketchField `json:"field,omitempty"` } @@ -30,7 +30,7 @@ func (q *QuantileFromTDigestSketch) SetName(name string) *QuantileFromTDigestSke // SetFraction set fraction func (q *QuantileFromTDigestSketch) SetFraction(fraction float64) *QuantileFromTDigestSketch { - q.Fraction = fraction + q.Fraction = &fraction return q } diff --git a/builder/postaggregation/quantiles_doubles_sketch_to_quantile.go b/builder/postaggregation/quantiles_doubles_sketch_to_quantile.go index 679fa1b..330bb5b 100644 --- a/builder/postaggregation/quantiles_doubles_sketch_to_quantile.go +++ b/builder/postaggregation/quantiles_doubles_sketch_to_quantile.go @@ -5,7 +5,7 @@ package postaggregation type QuantilesDoublesSketchToQuantile struct { Base Field *QuantilesDoublesSketchField `json:"field,omitempty"` - Fraction float64 `json:"fraction,omitempty"` + Fraction *float64 `json:"fraction,omitempty"` } // NewQuantilesDoublesSketchToQuantile new instance of QuantilesDoublesSketchToHistogram @@ -23,7 +23,7 @@ func (q *QuantilesDoublesSketchToQuantile) SetName(name string) *QuantilesDouble // SetFraction set fraction func (q *QuantilesDoublesSketchToQuantile) SetFraction(fraction float64) *QuantilesDoublesSketchToQuantile { - q.Fraction = fraction + q.Fraction = &fraction return q }