Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigtable): Accept nil RowSet to read all rows #9327

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading