mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Merge pull request #954 from niaow/v2.1-fix-nil-grpc
Fix handling of nil in grpc responses
This commit is contained in:
commit
6fa8ead5ff
2 changed files with 23 additions and 0 deletions
|
|
@ -191,6 +191,19 @@ func (r ResultBool) ToRows(callback func(*pb.RowResponse) error) error {
|
|||
}})
|
||||
}
|
||||
|
||||
// EmptyResult produces an empty result.
|
||||
type EmptyResult struct{}
|
||||
|
||||
// ToRows implements the ToRowser interface.
|
||||
func (r EmptyResult) ToRows(callback func(*pb.RowResponse) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToTable implements the ToTabler interface.
|
||||
func (r EmptyResult) ToTable() (*pb.TableResponse, error) {
|
||||
return &pb.TableResponse{}, nil
|
||||
}
|
||||
|
||||
// Normally we wouldn't need this wrapper, but since pilosa returns
|
||||
// some concrete types for which we can't implement the ToTabler
|
||||
// interface, we have to check for those here and then wrap them
|
||||
|
|
@ -199,6 +212,8 @@ func ToTablerWrapper(result interface{}) (pb.ToTabler, error) {
|
|||
toTabler, ok := result.(pb.ToTabler)
|
||||
if !ok {
|
||||
switch v := result.(type) {
|
||||
case nil:
|
||||
toTabler = EmptyResult{}
|
||||
case []pilosa.GroupCount:
|
||||
toTabler = pilosa.GroupCounts(v)
|
||||
case uint64:
|
||||
|
|
@ -220,6 +235,8 @@ func ToRowserWrapper(result interface{}) (pb.ToRowser, error) {
|
|||
toRowser, ok := result.(pb.ToRowser)
|
||||
if !ok {
|
||||
switch v := result.(type) {
|
||||
case nil:
|
||||
toRowser = EmptyResult{}
|
||||
case []pilosa.GroupCount:
|
||||
toRowser = pilosa.GroupCounts(v)
|
||||
case uint64:
|
||||
|
|
|
|||
|
|
@ -272,6 +272,12 @@ func TestGRPC(t *testing.T) {
|
|||
{int64(12)},
|
||||
},
|
||||
},
|
||||
// nil
|
||||
{
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for ti, test := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue