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.

97 lines
1.9 KiB

2 months ago
package hbaseHandle
import (
"context"
"io"
"github.com/tsuna/gohbase/filter"
"github.com/tsuna/gohbase/hrpc"
)
func (c *HBaseClient) Scan(table string, options ...func(hrpc.Call) error) (map[string]map[string][]byte, error) {
req, err := hrpc.NewScanStr(
context.Background(), table, options...,
)
if err != nil {
return nil, err
}
scanner := c.Client.Scan(req)
packed := make(map[string]map[string][]byte)
for {
res, err := scanner.Next()
if err == io.EOF || res == nil {
break
}
var rowKey string
temp := make(map[string][]byte)
for _, v := range res.Cells {
rowKey = string(v.Row)
temp[string(v.Qualifier)] = v.Value
}
packed[rowKey] = temp
}
return packed, nil
}
func (c *HBaseClient) ScanRange(table string, start string, end string, options ...func(hrpc.Call) error) (map[string]map[string][]byte, error) {
req, err := hrpc.NewScanRangeStr(
context.Background(), table, start, end, options...,
)
if err != nil {
return nil, err
}
scanner := c.Client.Scan(req)
packed := make(map[string]map[string][]byte)
for {
res, err := scanner.Next()
if err == io.EOF || res == nil {
break
}
var rowKey string
temp := make(map[string][]byte)
for _, v := range res.Cells {
rowKey = string(v.Row)
temp[string(v.Qualifier)] = v.Value
}
packed[rowKey] = temp
}
return packed, nil
}
func GetFilterByRowKeyPrefix(prefix string) []func(hrpc.Call) error {
var res []func(hrpc.Call) error
f2 := filter.NewPrefixFilter([]byte(prefix))
res = append(res, hrpc.Filters(f2))
return res
}
func GetFilterByRowKeyRange(num int, start string, end string) []func(hrpc.Call) error {
var res []func(hrpc.Call) error
f1 := filter.NewPageFilter(int64(num))
res = append(res, hrpc.Filters(f1))
f2 := filter.NewRowRange([]byte(start), []byte(end), true, false)
res = append(res, hrpc.Filters(f2))
return res
}