Skip to content

Commit

Permalink
spanner/spannertest: simplify implementation of rowCmp
Browse files Browse the repository at this point in the history
We can reuse compareVals, which also handles NULLs correctly.

Change-Id: Ia69d840103a508b6c5d9d90da989bc3ba7f7721b
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/44238
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Knut Olav Løite <koloite@gmail.com>
  • Loading branch information
dsymonds committed Aug 21, 2019
1 parent b94aa76 commit 140f0fd
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions spanner/spannertest/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,33 +570,8 @@ func (t *table) rowForPK(pk []interface{}) int {
// a is permitted to be shorter than b.
func rowCmp(a, b []interface{}) int {
for i := 0; i < len(a); i++ {
x, y := a[i], b[i]

// TODO: handle BOOL and TIMESTAMP.
switch x := x.(type) {
default:
panic(fmt.Sprintf("internal error: can't rowCmp %T", x))
case int64:
y := y.(int64)
if x < y {
return -1
} else if x > y {
return 1
}
case float64:
y := y.(float64)
if x < y {
return -1
} else if x > y {
return 1
}
case string:
y := y.(string)
if x < y {
return -1
} else if x > y {
return 1
}
if cmp := compareVals(a[i], b[i]); cmp != 0 {
return cmp
}
}
return 0
Expand Down

0 comments on commit 140f0fd

Please sign in to comment.