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 pathresult.go
69 lines (50 loc) · 1.36 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
package hbase
import (
"bytes"
"github.com/lazyshot/go-hbase/proto"
"time"
)
type ResultRow struct {
Row EncodedValue
Columns map[string]*ResultRowColumn
SortedColumns []*ResultRowColumn
}
type ResultRowColumn struct {
ColumnName string
Family EncodedValue
Qualifier EncodedValue
Timestamp time.Time
Value EncodedValue
Values map[time.Time]EncodedValue
}
func newResultRow(result *proto.Result) *ResultRow {
res := &ResultRow{}
res.Columns = make(map[string]*ResultRowColumn)
res.SortedColumns = make([]*ResultRowColumn, 0)
for _, cell := range result.GetCell() {
res.Row = cell.GetRow()
col := ResultRowColumn{
Family: cell.GetFamily(),
Qualifier: cell.GetQualifier(),
Value: cell.GetValue(),
Timestamp: time.Unix(int64(cell.GetTimestamp()), 0),
}
col.ColumnName = col.Family.String() + ":" + col.Qualifier.String()
if v, exists := res.Columns[col.ColumnName]; exists {
if col.Timestamp.After(v.Timestamp) {
v.Value = col.Value
v.Timestamp = col.Timestamp
}
v.Values[col.Timestamp] = col.Value
} else {
col.Values = map[time.Time]EncodedValue{col.Timestamp: col.Value}
res.Columns[col.ColumnName] = &col
res.SortedColumns = append(res.SortedColumns, &col)
}
}
return res
}
type EncodedValue []byte
func (e EncodedValue) String() string {
return bytes.NewBuffer(e).String()
}