Skip to content

Commit

Permalink
hrpc/scan: add support for scan attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Nov 2, 2023
1 parent 75354d5 commit 7def64c
Show file tree
Hide file tree
Showing 2 changed files with 40 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
15 changes: 15 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,9 @@ func (s *Scan) ToProto() proto.Message {
if s.consistency != DefaultConsistency {
scan.Scan.Consistency = s.consistency.toProto()
}
if len(s.attribute) > 0 {
scan.Scan.Attribute = s.attribute
}
scan.Scan.Filter = s.filter
return scan
}
Expand Down Expand Up @@ -344,3 +348,14 @@ func Reversed() func(Call) error {
return nil
}
}

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")
}

Check warning on line 357 in hrpc/scan.go

View check run for this annotation

Codecov / codecov/patch

hrpc/scan.go#L356-L357

Added lines #L356 - L357 were not covered by tests
scan.attribute = append(scan.attribute, &pb.NameBytesPair{Name: &key, Value: val})
return nil
}
}

0 comments on commit 7def64c

Please sign in to comment.