Skip to content

Commit

Permalink
fix(bigtable): Accept nil RowSet to read all rows (#9327)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhshkh committed Mar 13, 2024
1 parent 5109154 commit cd36506
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
21 changes: 14 additions & 7 deletions bigtable/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,19 @@ func (t *Table) ReadRows(ctx context.Context, arg RowSet, f func(Row) bool, opts
var prevRowKey string
attrMap := make(map[string]interface{})
err = gax.Invoke(ctx, func(ctx context.Context, _ gax.CallSettings) error {
if !arg.valid() {
// Empty row set, no need to make an API call.
// NOTE: we must return early if arg == RowList{} because reading
// an empty RowList from bigtable returns all rows from that table.
return nil
}
req := &btpb.ReadRowsRequest{
TableName: t.c.fullTableName(t.table),
AppProfileId: t.c.appProfile,
Rows: arg.proto(),
}

if arg != nil {
if !arg.valid() {
// Empty row set, no need to make an API call.
// NOTE: we must return early if arg == RowList{} because reading
// an empty RowList from bigtable returns all rows from that table.
return nil
}
req.Rows = arg.proto()
}
settings := makeReadSettings(req)
for _, opt := range opts {
Expand Down Expand Up @@ -222,6 +225,10 @@ func (t *Table) ReadRows(ctx context.Context, arg RowSet, f func(Row) bool, opts
}
if err != nil {
// Reset arg for next Invoke call.
if arg == nil {
// Should be lowest possible key value, an empty byte array
arg = InfiniteRange("")
}
if req.Reversed {
arg = arg.retainRowsBefore(prevRowKey)
} else {
Expand Down
7 changes: 0 additions & 7 deletions bigtable/internal/testproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,6 @@ func (s *goTestProxyServer) ReadRows(ctx context.Context, req *pb.ReadRowsReques
rowPbs := rrq.Rows
rs := rowSetFromProto(rowPbs)

// Bigtable client doesn't have a Table.GetAll() function--RowSet must be
// provided for ReadRows. Use InfiniteRange() to get the full table.
if rs == nil {
// Should be lowest possible key value, an empty byte array
rs = bigtable.InfiniteRange("")
}

ctx, cancel := btc.timeout(ctx)
defer cancel()

Expand Down

0 comments on commit cd36506

Please sign in to comment.