This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
forked from c4pt0r/go-hbase
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathclient_ops.go
67 lines (57 loc) · 1.76 KB
/
client_ops.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package hbase
import (
"github.com/juju/errors"
"github.com/pingcap/go-hbase/proto"
)
func (c *client) Delete(table string, del *Delete) (bool, error) {
response, err := c.do([]byte(table), del.GetRow(), del, true)
if err != nil {
return false, errors.Trace(err)
}
switch r := response.(type) {
case *proto.MutateResponse:
return r.GetProcessed(), nil
}
return false, errors.Errorf("Invalid response seen [response: %#v]", response)
}
func (c *client) Get(table string, get *Get) (*ResultRow, error) {
response, err := c.do([]byte(table), get.GetRow(), get, true)
if err != nil {
return nil, errors.Trace(err)
}
switch r := response.(type) {
case *proto.GetResponse:
res := r.GetResult()
if res == nil {
return nil, errors.Errorf("Empty response: [table=%s] [row=%q]", table, get.GetRow())
}
return NewResultRow(res), nil
case *exception:
return nil, errors.New(r.msg)
}
return nil, errors.Errorf("Invalid response seen [response: %#v]", response)
}
func (c *client) Put(table string, put *Put) (bool, error) {
response, err := c.do([]byte(table), put.GetRow(), put, true)
if err != nil {
return false, errors.Trace(err)
}
switch r := response.(type) {
case *proto.MutateResponse:
return r.GetProcessed(), nil
}
return false, errors.Errorf("Invalid response seen [response: %#v]", response)
}
func (c *client) ServiceCall(table string, call *CoprocessorServiceCall) (*proto.CoprocessorServiceResponse, error) {
response, err := c.do([]byte(table), call.Row, call, true)
if err != nil {
return nil, errors.Trace(err)
}
switch r := response.(type) {
case *proto.CoprocessorServiceResponse:
return r, nil
case *exception:
return nil, errors.New(r.msg)
}
return nil, errors.Errorf("Invalid response seen [response: %#v]", response)
}