From 140f0fd3f08a201195d506fc6a0bd4c248590fb5 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Wed, 21 Aug 2019 13:56:03 +1000 Subject: [PATCH] spanner/spannertest: simplify implementation of rowCmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Knut Olav Løite --- spanner/spannertest/db.go | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/spanner/spannertest/db.go b/spanner/spannertest/db.go index bcce1a7ddf98..a055c76a810d 100644 --- a/spanner/spannertest/db.go +++ b/spanner/spannertest/db.go @@ -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