You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

  1. package hbase
  2. import (
  3. "github.com/juju/errors"
  4. "github.com/pingcap/go-hbase/proto"
  5. )
  6. func (c *client) Delete(table string, del *Delete) (bool, error) {
  7. response, err := c.do([]byte(table), del.GetRow(), del, true)
  8. if err != nil {
  9. return false, errors.Trace(err)
  10. }
  11. switch r := response.(type) {
  12. case *proto.MutateResponse:
  13. return r.GetProcessed(), nil
  14. }
  15. return false, errors.Errorf("Invalid response seen [response: %#v]", response)
  16. }
  17. func (c *client) Get(table string, get *Get) (*ResultRow, error) {
  18. response, err := c.do([]byte(table), get.GetRow(), get, true)
  19. if err != nil {
  20. return nil, errors.Trace(err)
  21. }
  22. switch r := response.(type) {
  23. case *proto.GetResponse:
  24. res := r.GetResult()
  25. if res == nil {
  26. return nil, errors.Errorf("Empty response: [table=%s] [row=%q]", table, get.GetRow())
  27. }
  28. return NewResultRow(res), nil
  29. case *exception:
  30. return nil, errors.New(r.msg)
  31. }
  32. return nil, errors.Errorf("Invalid response seen [response: %#v]", response)
  33. }
  34. func (c *client) Put(table string, put *Put) (bool, error) {
  35. response, err := c.do([]byte(table), put.GetRow(), put, true)
  36. if err != nil {
  37. return false, errors.Trace(err)
  38. }
  39. switch r := response.(type) {
  40. case *proto.MutateResponse:
  41. return r.GetProcessed(), nil
  42. }
  43. return false, errors.Errorf("Invalid response seen [response: %#v]", response)
  44. }
  45. func (c *client) ServiceCall(table string, call *CoprocessorServiceCall) (*proto.CoprocessorServiceResponse, error) {
  46. response, err := c.do([]byte(table), call.Row, call, true)
  47. if err != nil {
  48. return nil, errors.Trace(err)
  49. }
  50. switch r := response.(type) {
  51. case *proto.CoprocessorServiceResponse:
  52. return r, nil
  53. case *exception:
  54. return nil, errors.New(r.msg)
  55. }
  56. return nil, errors.Errorf("Invalid response seen [response: %#v]", response)
  57. }