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

Commit

Permalink
Merge pull request #45 from theatlantic/fix-topn-attrs
Browse files Browse the repository at this point in the history
fixed issue with requiring an (optional) bitmap for TopN call
  • Loading branch information
codysoyland authored Aug 7, 2017
2 parents 21aefaa + 4c891cb commit 38863bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,11 @@ func (f *Frame) filterFieldTopN(n uint64, bitmap *PQLBitmapQuery, inverse bool,
if !inverse {
inverseStr = "false"
}
return NewPQLBitmapQuery(fmt.Sprintf("TopN(%s, frame='%s', n=%d, inverse=%s, field='%s', %s)",
if bitmap == nil {
return NewPQLBitmapQuery(fmt.Sprintf("TopN(frame='%s', n=%d, inverse=%s, field='%s', filters=%s)",
f.name, n, inverseStr, field, string(b)), f.index, nil)
}
return NewPQLBitmapQuery(fmt.Sprintf("TopN(%s, frame='%s', n=%d, inverse=%s, field='%s', filters=%s)",
bitmap.serialize(), f.name, n, inverseStr, field, string(b)), f.index, nil)
}

Expand Down
7 changes: 5 additions & 2 deletions orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,14 @@ func TestTopN(t *testing.T) {
"TopN(Bitmap(project=3, frame='collaboration'), frame='sample-frame', n=10, inverse=true)",
sampleFrame.InverseBitmapTopN(10, collabFrame.Bitmap(3)))
comparePQL(t,
"TopN(Bitmap(project=7, frame='collaboration'), frame='sample-frame', n=12, inverse=false, field='category', [80,81])",
"TopN(Bitmap(project=7, frame='collaboration'), frame='sample-frame', n=12, inverse=false, field='category', filters=[80,81])",
sampleFrame.FilterFieldTopN(12, collabFrame.Bitmap(7), "category", 80, 81))
comparePQL(t,
"TopN(Bitmap(project=7, frame='collaboration'), frame='sample-frame', n=12, inverse=true, field='category', [80,81])",
"TopN(Bitmap(project=7, frame='collaboration'), frame='sample-frame', n=12, inverse=true, field='category', filters=[80,81])",
sampleFrame.InverseFilterFieldTopN(12, collabFrame.Bitmap(7), "category", 80, 81))
comparePQL(t,
"TopN(frame='sample-frame', n=12, inverse=true, field='category', filters=[80,81])",
sampleFrame.InverseFilterFieldTopN(12, nil, "category", 80, 81))
}

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

0 comments on commit 38863bd

Please sign in to comment.