Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Replaced Sum call with SumReduce call; removed Average call
Browse files Browse the repository at this point in the history
  • Loading branch information
yuce committed Sep 11, 2017
1 parent 57aca6e commit 3beb914
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
9 changes: 6 additions & 3 deletions client_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,11 @@ func TestRangeFrame(t *testing.T) {
options := &FrameOptions{}
options.AddIntField("foo", 10, 20)
frame, _ := index.Frame("rangeframe", options)
client.EnsureFrame(frame)
_, err := client.Query(index.BatchQuery(
err := client.EnsureFrame(frame)
if err != nil {
t.Fatal(err)
}
_, err = client.Query(index.BatchQuery(
frame.SetBit(1, 10),
frame.SetBit(1, 100),
frame.SetIntFieldValue(10, "foo", 11),
Expand All @@ -811,7 +814,7 @@ func TestRangeFrame(t *testing.T) {
if err != nil {
t.Fatal(err)
}
resp, err := client.Query(frame.Sum(frame.Bitmap(1), "foo"), nil)
resp, err := client.Query(frame.SumReduce(frame.Bitmap(1), "foo"), nil)
if err != nil {
t.Fatal(err)
}
Expand Down
13 changes: 3 additions & 10 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,10 @@ func (f *Frame) SetRowAttrs(rowID uint64, attrs map[string]interface{}) *PQLBase
f.options.RowLabel, rowID, f.name, attrsString), f.index, nil)
}

// Average creates an Average query.
// SumReduce creates a SumReduce query.
// The corresponding frame should include the field in its options.
func (f *Frame) Average(bitmap *PQLBitmapQuery, field string) *PQLBaseQuery {
return f.rangeQuery("Average", bitmap, field)
}

// Sum creates a Sum query.
// The corresponding frame should include the field in its options.
func (f *Frame) Sum(bitmap *PQLBitmapQuery, field string) *PQLBaseQuery {
return f.rangeQuery("Sum", bitmap, field)
func (f *Frame) SumReduce(bitmap *PQLBitmapQuery, field string) *PQLBaseQuery {
return f.rangeQuery("SumReduce", bitmap, field)
}

// SetIntFieldValue creates a SetFieldValue query.
Expand All @@ -638,7 +632,6 @@ func (f *Frame) SetIntFieldValue(columnID uint64, field string, value int) *PQLB

func (f *Frame) rangeQuery(call string, bitmap *PQLBitmapQuery, field string) *PQLBaseQuery {
qry := fmt.Sprintf("%s(%s, frame='%s', field='%s')", call, bitmap.serialize(), f.name, field)
fmt.Println("QRY", qry)
return NewPQLBaseQuery(qry, f.index, nil)
}

Expand Down
13 changes: 3 additions & 10 deletions orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,11 @@ func TestSetRowAttrsInvalidAttr(t *testing.T) {
}
}

func TestAverage(t *testing.T) {
func TestSumReduce(t *testing.T) {
b := collabFrame.Bitmap(42)
comparePQL(t,
"Average(frame='sample-frame', Bitmap(project=42, frame='collaboration'), field='foo')",
sampleFrame.Average(b, "foo"))
}

func TestSum(t *testing.T) {
b := collabFrame.Bitmap(42)
comparePQL(t,
"Sum(frame='sample-frame', Bitmap(project=42, frame='collaboration'), field='foo')",
sampleFrame.Sum(b, "foo"))
"SumReduce(Bitmap(project=42, frame='collaboration'), frame='sample-frame', field='foo')",
sampleFrame.SumReduce(b, "foo"))
}

func TestBatchQuery(t *testing.T) {
Expand Down

0 comments on commit 3beb914

Please sign in to comment.