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

Commit

Permalink
Added support for excluding bits and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuce committed Sep 11, 2017
1 parent 3beb914 commit 46226d4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Go client for Pilosa high performance distributed bitmap index.
* Dropped support for Go 1.7
* Added support for creating range encoded frames.
* Added `SetFieldValue`,`Average`, `Sum` and `Xor` calls.
* Added support for excluding bits or attributes from bitmap calls. In order to exclude bits, pass `ExcludeBits: true` in your `QueryOptions`. In order to exclude attributes, pass `ExcludeAttrs: true`.

* **v0.5.0** (2017-08-03):
* Supports imports and exports.
Expand Down
10 changes: 8 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,10 @@ func newHTTPClient(options *ClientOptions) *http.Client {

func makeRequestData(query string, options *QueryOptions) []byte {
request := &internal.QueryRequest{
Query: query,
ColumnAttrs: options.Columns,
Query: query,
ColumnAttrs: options.Columns,
ExcludeAttrs: options.ExcludeAttrs,
ExcludeBits: options.ExcludeBits,
}
r, _ := proto.Marshal(request)
// request.Marshal never returns an error
Expand Down Expand Up @@ -600,6 +602,10 @@ func (options *ClientOptions) withDefaults() (updated *ClientOptions) {
type QueryOptions struct {
// Columns enables returning columns in the query response.
Columns bool
// ExcludeAttrs inhibits returning attributes
ExcludeAttrs bool
// ExcludeBits inhibits returning bits
ExcludeBits bool
}

type returnClientInfo uint
Expand Down
31 changes: 31 additions & 0 deletions client_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,37 @@ func TestRangeFrame(t *testing.T) {
}
}

func TestInhibitAttrsBits(t *testing.T) {
client := getClient()
attrs := map[string]interface{}{
"foo": "bar",
}
_, err := client.Query(index.BatchQuery(
testFrame.SetBit(1, 100),
testFrame.SetRowAttrs(1, attrs),
), nil)
if err != nil {
t.Fatal(err)
}

// test exclude attributes.
resp, err := client.Query(testFrame.Bitmap(1), &QueryOptions{ExcludeAttrs: true})
if len(resp.Result().Bitmap.Bits) != 1 {
t.Fatalf("bits should be included")
}
if len(resp.Result().Bitmap.Attributes) != 0 {
t.Fatalf("attributes should be excluded")
}

resp, err = client.Query(testFrame.Bitmap(1), &QueryOptions{ExcludeBits: true})
if len(resp.Result().Bitmap.Bits) != 0 {
t.Fatalf("bits should be excluded")
}
if len(resp.Result().Bitmap.Attributes) != 1 {
t.Fatalf("attributes should be included")
}
}

func TestImportBitIteratorError(t *testing.T) {
client := getClient()
frame, err := index.Frame("not-important", nil)
Expand Down

0 comments on commit 46226d4

Please sign in to comment.