Skip to content

Commit

Permalink
hrpc/scan: add support for scan attribute (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi authored Nov 2, 2023
1 parent 75354d5 commit c4dd77b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hrpc/hrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,31 @@ func TestScanToProto(t *testing.T) {
},
},
},
{ // set scan attribute
s: func() *Scan {
s, _ := NewScanStr(ctx, "",
Attribute("key1", []byte("value1")),
Attribute("key2", []byte("value2")),
)
return s
}(),
expProto: &pb.ScanRequest{
Region: rs,
NumberOfRows: proto.Uint32(DefaultNumberOfRows),
CloseScanner: proto.Bool(false),
ClientHandlesPartials: proto.Bool(true),
ClientHandlesHeartbeats: proto.Bool(true),
Scan: &pb.Scan{
MaxResultSize: proto.Uint64(DefaultMaxResultSize),
Column: []*pb.Column{},
TimeRange: &pb.TimeRange{},
Attribute: []*pb.NameBytesPair{
{Name: proto.String("key1"), Value: []byte("value1")},
{Name: proto.String("key2"), Value: []byte("value2")},
},
},
},
},
{ // scan key range
s: func() *Scan {
s, _ := NewScanRange(ctx, nil, startRow, stopRow)
Expand Down
18 changes: 18 additions & 0 deletions hrpc/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Scan struct {
maxResultSize uint64
numberOfRows uint32
reversed bool
attribute []*pb.NameBytesPair

closeScanner bool
allowPartialResults bool
Expand Down Expand Up @@ -227,6 +228,7 @@ func (s *Scan) ToProto() proto.Message {
if s.consistency != DefaultConsistency {
scan.Scan.Consistency = s.consistency.toProto()
}
scan.Scan.Attribute = s.attribute
scan.Scan.Filter = s.filter
return scan
}
Expand Down Expand Up @@ -344,3 +346,19 @@ func Reversed() func(Call) error {
return nil
}
}

// Attribute is a Scan-only option which set metadata-like attribute on the request. Attribute
// option can be used multiple times and will be appended to a list. Attribute are useful to
// communicate special information about the Scan request to HBase, such as:
// - retrieve MOB metadata
// - change behaviour of coprocessors
func Attribute(key string, val []byte) func(Call) error {
return func(g Call) error {
scan, ok := g.(*Scan)
if !ok {
return errors.New("'Attributes' option can only be used with Scan queries")
}
scan.attribute = append(scan.attribute, &pb.NameBytesPair{Name: &key, Value: val})
return nil
}
}

0 comments on commit c4dd77b

Please sign in to comment.