spanner/spannertest: simplify internal writeValues helper

There's no need to pass pkIndexes through to the closures, since the
passed row is already in table order, so the primary key is the initial
t.pkCols columns of that row.

Change-Id: I52c97ec5a4062a6d9d5878c46e28d65121cc1059
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/44234
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Knut Olav Løite <koloite@gmail.com>
diff --git a/spanner/spannertest/db.go b/spanner/spannertest/db.go
index 677b2e3..daa25a3 100644
--- a/spanner/spannertest/db.go
+++ b/spanner/spannertest/db.go
@@ -200,7 +200,7 @@
 }
 
 // writeValues executes a write option (Insert, Update, etc.).
-func (d *database) writeValues(tbl string, cols []string, values []*structpb.ListValue, f func(t *table, colIndexes, pkIndexes []int, r row) error) error {
+func (d *database) writeValues(tbl string, cols []string, values []*structpb.ListValue, f func(t *table, colIndexes []int, r row) error) error {
 	t, err := d.table(tbl)
 	if err != nil {
 		return err
@@ -218,13 +218,11 @@
 		revIndex[i] = j
 	}
 
-	var pkIndexes []int
 	for pki := 0; pki < t.pkCols; pki++ {
-		i, ok := revIndex[pki]
+		_, ok := revIndex[pki]
 		if !ok {
 			return status.Errorf(codes.InvalidArgument, "primary key column %s not included in write", t.cols[pki].Name)
 		}
-		pkIndexes = append(pkIndexes, i)
 	}
 
 	for _, vs := range values {
@@ -245,7 +243,7 @@
 		}
 		// TODO: enforce NOT NULL?
 
-		if err := f(t, colIndexes, pkIndexes, r); err != nil {
+		if err := f(t, colIndexes, r); err != nil {
 			return err
 		}
 	}
@@ -254,11 +252,8 @@
 }
 
 func (d *database) Insert(tbl string, cols []string, values []*structpb.ListValue) error {
-	return d.writeValues(tbl, cols, values, func(t *table, colIndexes, pkIndexes []int, r row) error {
-		var pk []interface{}
-		for _, i := range pkIndexes {
-			pk = append(pk, r[i])
-		}
+	return d.writeValues(tbl, cols, values, func(t *table, colIndexes []int, r row) error {
+		pk := r[:t.pkCols]
 		if t.rowForPK(pk) >= 0 {
 			// TODO: how do we return `ALREADY_EXISTS`?
 			return status.Errorf(codes.Unknown, "row already in table")
@@ -270,11 +265,8 @@
 }
 
 func (d *database) Update(tbl string, cols []string, values []*structpb.ListValue) error {
-	return d.writeValues(tbl, cols, values, func(t *table, colIndexes, pkIndexes []int, r row) error {
-		var pk []interface{}
-		for _, i := range pkIndexes {
-			pk = append(pk, r[i])
-		}
+	return d.writeValues(tbl, cols, values, func(t *table, colIndexes []int, r row) error {
+		pk := r[:t.pkCols]
 		rowNum := t.rowForPK(pk)
 		if rowNum < 0 {
 			// TODO: is this the right way to return `NOT_FOUND`?
@@ -289,11 +281,8 @@
 }
 
 func (d *database) InsertOrUpdate(tbl string, cols []string, values []*structpb.ListValue) error {
-	return d.writeValues(tbl, cols, values, func(t *table, colIndexes, pkIndexes []int, r row) error {
-		var pk []interface{}
-		for _, i := range pkIndexes {
-			pk = append(pk, r[i])
-		}
+	return d.writeValues(tbl, cols, values, func(t *table, colIndexes []int, r row) error {
+		pk := r[:t.pkCols]
 		rowNum := t.rowForPK(pk)
 		if rowNum < 0 {
 			// New row; do an insert.