Skip to content

Commit

Permalink
spanner/spannertest: return error for Read with no keys (#2655)
Browse files Browse the repository at this point in the history
This operation is rejected by the real Cloud Spanner.
  • Loading branch information
dsymonds authored Jul 30, 2020
1 parent c1e8623 commit ac15704
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spanner/spannertest/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ func (d *database) readTable(table string, cols []string, f func(*table, *rawIte
}

func (d *database) Read(tbl string, cols []string, keys []*structpb.ListValue, keyRanges keyRangeList, limit int64) (rowIter, error) {
// The real Cloud Spanner returns an error if the key set is empty by definition.
// That doesn't seem to be well-defined, but it is a common error to attempt a read with no keys,
// so catch that here and return a representative error.
if len(keys) == 0 && len(keyRanges) == 0 {
return nil, status.Error(codes.Unimplemented, "Cloud Spanner does not support reading no keys")
}

return d.readTable(tbl, cols, func(t *table, ri *rawIter, colIndexes []int) error {
// "If the same key is specified multiple times in the set (for
// example if two ranges, two keys, or a key and a range
Expand Down

0 comments on commit ac15704

Please sign in to comment.