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 21
/
Copy pathdelete.go
107 lines (86 loc) · 2.35 KB
/
delete.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package hbase
import (
pb "github.com/golang/protobuf/proto"
"github.com/lazyshot/go-hbase/proto"
"bytes"
"fmt"
"math"
"strings"
)
type Delete struct {
key []byte
families [][]byte
qualifiers [][][]byte
}
func CreateNewDelete(key []byte) *Delete {
return &Delete{
key: key,
families: make([][]byte, 0),
qualifiers: make([][][]byte, 0),
}
}
func (this *Delete) 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 *Delete) AddStringColumn(family, qual string) {
this.AddColumn([]byte(family), []byte(qual))
}
func (this *Delete) AddStringFamily(family string) {
this.AddFamily([]byte(family))
}
func (this *Delete) AddColumn(family, qual []byte) {
this.AddFamily(family)
pos := this.posOfFamily(family)
this.qualifiers[pos] = append(this.qualifiers[pos], qual)
}
func (this *Delete) 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 *Delete) posOfFamily(family []byte) int {
for p, v := range this.families {
if bytes.Equal(family, v) {
return p
}
}
return -1
}
func (this *Delete) toProto() pb.Message {
d := &proto.MutationProto{
Row: this.key,
MutateType: proto.MutationProto_DELETE.Enum(),
}
for i, v := range this.families {
cv := &proto.MutationProto_ColumnValue{
Family: v,
QualifierValue: make([]*proto.MutationProto_ColumnValue_QualifierValue, 0),
}
if len(this.qualifiers[i]) == 0 {
cv.QualifierValue = append(cv.QualifierValue, &proto.MutationProto_ColumnValue_QualifierValue{
Qualifier: nil,
Timestamp: pb.Uint64(uint64(math.MaxInt64)),
DeleteType: proto.MutationProto_DELETE_FAMILY.Enum(),
})
}
for _, v := range this.qualifiers[i] {
cv.QualifierValue = append(cv.QualifierValue, &proto.MutationProto_ColumnValue_QualifierValue{
Qualifier: v,
Timestamp: pb.Uint64(uint64(math.MaxInt64)),
DeleteType: proto.MutationProto_DELETE_MULTIPLE_VERSIONS.Enum(),
})
}
d.ColumnValue = append(d.ColumnValue, cv)
}
return d
}