这是indexloc提供的服务,不要输入任何密码
Skip to content

spanner: possible row mismatch in SelectAll using custom type #11101

@jonasv3

Description

@jonasv3

Client

Spanner

Environment

go version go1.23.2 darwin/arm64

Code and Dependencies

package main

func main() {
	// spannerClient created per best practices
	rowIter := spannerClient.Single().Query(
		context.Background(),
		spanner.Statement{SQL: `
		SELECT
			Id,
			OtherId,
		FROM Items
		ORDER BY OtherId DESC
		`},
	)
	defer rowIter.Stop()

	var dest []struct {
		Id        string
		OtherId Inner[string]
	}

	if err := spanner.SelectAll(rowIter, &dest); err != nil {
		t.Fatal(err)
	}
	for _, d := range dest {
		fmt.Println(d)
	}
}


type Inner[T any] struct {
	val T
}

func (n *Inner[T]) DecodeSpanner(input any) error {
	switch val := input.(type) {
	case T:
		n.val = val
		return nil
	case *T:
		if val == nil {
			return nil
		}
		n.val = *val
		return nil
	}
	panic("n/a")
}
go.mod
module modname

go 1.23

require (
	cloud.google.com/go/spanner v1.70.0
	google.golang.org/api v0.201.0
	google.golang.org/grpc v1.67.1
	…
)

Expected behavior

Given the following data in the table Items:

Id        OtherId
715e8f8d  None
5865d2cd  foobar

with the schema

CREATE TABLE IF NOT EXISTS Items (
    Id STRING(36) DEFAULT (GENERATE_UUID()),
    OtherId STRING(MAX),
) PRIMARY KEY (Id);

and running the above code, I would expect

{5865d2cd {foobar}}
{715e8f8d {}}

Actual behavior

I see a row mismatch, where the row 715e8f8d somehow inherits the value foobar from 5865d2cd.

{5865d2cd {foobar}}
{715e8f8d {foobar}}

(guids truncated for pith)

Additional context

Is not an issue when iterating and decoding using ToStruct().

Metadata

Metadata

Labels

api: spannerIssues related to the Spanner API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions