tsuna / gohbase

Pure-Go HBase client
Apache License 2.0
735 stars 213 forks source link

No way to detect if value not found when using Client.Get #64

Open jonbonazza opened 7 years ago

jonbonazza commented 7 years ago

@timoha We have come across a pretty major issue. When using Client.Get, if no result is found in HBase, HBase will return an RPC with no value and no error. The gohbase client will take this rpc response and return an empty *hrpc.Result and no error. A workaround is to check the resulting *hrpc.Result and make sure it's not the zero value, working under the assumption that a zero value hrpc.Result is never valid.

I am fairly certain that the resulting code is here:

// ToLocalResult takes a protobuf Result type and converts it to our own
// Result type in constant time.
func ToLocalResult(pbr *pb.Result) *Result {
        // We should return nil here, not an empty struct.
    if pbr == nil {
        return &Result{}
    }
        // ...
}

I can submit a PR for this if you wish, but I wanted to check in here to ensure that there wasn't some specific reason that an empty struct is returned here.

timoha commented 7 years ago

Well, it depends on how you define an empty case. In our codebase, if we have an empty result (no cells), that means that no values have been found. It kind of makes the code nicer as we don't have to check if res == nil, but instead just check len(res.Cell) == 0.

Maybe it would be nicer to return nil instead of empty hrpc.Result, I don't have strong preference though. If nothing is found, then you'll have nil, nil returned, which is kind of strange also?

jonbonazza commented 6 years ago

@timoha thinking about this more, the standard approach to something like this seems to be to return a specific error (i.e. ErrNoResults) along with a nil Result. What are your thoughts on this approach? For now, we are using len.