This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
get.go
91 lines (72 loc) · 1.7 KB
/
get.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package hbase
import (
pb "github.com/golang/protobuf/proto"
"github.com/lazyshot/go-hbase/proto"
"bytes"
"fmt"
"strings"
)
type Get struct {
key []byte
families [][]byte
qualifiers [][][]byte
versions int32
}
func CreateNewGet(key []byte) *Get {
return &Get{
key: key,
families: make([][]byte, 0),
qualifiers: make([][][]byte, 0),
versions: 1,
}
}
func (this *Get) AddString(famqual string) error {
parts := strings.Split(famqual, ":")
if len(parts) > 2 {
return fmt.Errorf("Too many colons were found in the family:qualifier string. '%s'", famqual)
} else if len(parts) == 2 {
this.AddStringColumn(parts[0], parts[1])
} else {
this.AddStringFamily(famqual)
}
return nil
}
func (this *Get) AddStringColumn(family, qual string) {
this.AddColumn([]byte(family), []byte(qual))
}
func (this *Get) AddStringFamily(family string) {
this.AddFamily([]byte(family))
}
func (this *Get) AddColumn(family, qual []byte) {
this.AddFamily(family)
pos := this.posOfFamily(family)
this.qualifiers[pos] = append(this.qualifiers[pos], qual)
}
func (this *Get) AddFamily(family []byte) {
pos := this.posOfFamily(family)
if pos == -1 {
this.families = append(this.families, family)
this.qualifiers = append(this.qualifiers, make([][]byte, 0))
}
}
func (this *Get) posOfFamily(family []byte) int {
for p, v := range this.families {
if bytes.Equal(family, v) {
return p
}
}
return -1
}
func (this *Get) toProto() pb.Message {
g := &proto.Get{
Row: this.key,
}
for i, v := range this.families {
g.Column = append(g.Column, &proto.Column{
Family: v,
Qualifier: this.qualifiers[i],
})
}
g.MaxVersions = pb.Uint32(uint32(this.versions))
return g
}