This repository was 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 pathresult.go
76 lines (65 loc) · 1.37 KB
/
result.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
package hbase
import (
"fmt"
"github.com/pingcap/go-hbase/proto"
)
type Kv struct {
Row []byte
Ts uint64
Value []byte
// history results
Values map[uint64][]byte
Column
}
func (kv *Kv) String() string {
if kv == nil {
return "<nil>"
}
return fmt.Sprintf("Kv(%+v)", *kv)
}
type ResultRow struct {
Row []byte
Columns map[string]*Kv
SortedColumns []*Kv
}
func (r *ResultRow) String() string {
if r == nil {
return "<nil>"
}
return fmt.Sprintf("ResultRow(%+v)", *r)
}
func NewResultRow(result *proto.Result) *ResultRow {
// empty response
if len(result.GetCell()) == 0 {
return nil
}
res := &ResultRow{}
res.Columns = make(map[string]*Kv)
res.SortedColumns = make([]*Kv, 0)
for _, cell := range result.GetCell() {
res.Row = cell.GetRow()
col := &Kv{
Row: res.Row,
Column: Column{
Family: cell.GetFamily(),
Qual: cell.GetQualifier(),
},
Value: cell.GetValue(),
Ts: cell.GetTimestamp(),
}
colName := string(col.Column.Family) + ":" + string(col.Column.Qual)
if v, exists := res.Columns[colName]; exists {
// renew the same cf result
if col.Ts > v.Ts {
v.Value = col.Value
v.Ts = col.Ts
}
v.Values[col.Ts] = col.Value
} else {
col.Values = map[uint64][]byte{col.Ts: col.Value}
res.Columns[colName] = col
res.SortedColumns = append(res.SortedColumns, col)
}
}
return res
}