Skip to content

Commit

Permalink
update float to be ptr (#67)
Browse files Browse the repository at this point in the history
* update float to be ptr

* add one test

* add tests

Co-authored-by: jyu6 <[email protected]>
  • Loading branch information
jy4096 and jyu6 authored May 25, 2022
1 parent 87f5cd8 commit e4912c6
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 21 deletions.
4 changes: 2 additions & 2 deletions builder/bound/radius.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions builder/extractionfn/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions builder/havingspec/equal_to.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions builder/havingspec/greather_than.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
40 changes: 40 additions & 0 deletions builder/havingspec/having_spec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package havingspec

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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))
}
6 changes: 3 additions & 3 deletions builder/havingspec/less_than.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions builder/postaggregation/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package postaggregation

type Constant struct {
Base
Value float64 `json:"value,omitempty"`
Value *float64 `json:"value,omitempty"`
}

func NewConstant() *Constant {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions builder/postaggregation/quantile_from_tdigestsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit e4912c6

Please sign in to comment.