googleapis / google-cloud-go

Google Cloud Client Libraries for Go.
https://cloud.google.com/go/docs/reference
Apache License 2.0
3.77k stars 1.29k forks source link

spanner: UNNEST panics on `[][]byte` #2458

Closed gdbelvin closed 4 years ago

gdbelvin commented 4 years ago

Summary

db_eval.go L422 uses == for equality testing, but this panics on []byte types.

                                for _, rhs := range arr {
                    if lhs == rhs {
                        b = true
                    }
                }

Schema

CREATE TABLE LeafData(
  IdentityHash    BYTES(256) NOT NULL,
  Value           BYTES(MAX) NOT NULL,
) PRIMARY KEY(IdentityHash);

Query / Code https://github.com/google/trillian/pull/2137

    idHashes := make([][]byte, 0, len(leaves))
    stmt = spanner.NewStatement(
        `SELECT 
           IdentityHash, 
           Value, 
         FROM 
           LeafData
         WHERE 
           LeafIdentityHash IN UNNEST(@id_hashes)`)
    stmt.Params["id_hashes"] = idHashes
    if err := client.Query(ctx, stmt).Do(...); err != nil {
        return nil, err
    }

Go Environment

$ go version go version go1.14.3 darwin/amd64 $ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gbelvin/Library/Caches/go-build"
GOENV="/Users/gbelvin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/gbelvin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/gbelvin/go/src/github.com/google/trillian/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xq/1dznj60166q1qlzqry5c9c6h006zkw/T/go-build706918679=/tmp/go-build -gno-record-gcc-switches -fno-common"

Expected behavior

Query returns rows that match

Actual behavior

panic: runtime error: comparing uncomparable type []uint8

goroutine 68 [running]:
cloud.google.com/go/spanner/spannertest.evalContext.evalExpr(0xc000502d80, 0x5, 0x8, 0xc00052aa00, 0x5, 0x5, 0x0, 0xc00079e300, 0x196dcc0, 0xc0006d6880, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_eval.go:422 +0x972
cloud.google.com/go/spanner/spannertest.evalContext.evalBoolExpr(0xc000502d80, 0x5, 0x8, 0xc00052aa00, 0x5, 0x5, 0x0, 0xc00079e300, 0x19762c0, 0xc0006d6880, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_eval.go:75 +0x565
cloud.google.com/go/spanner/spannertest.evalContext.evalBoolExpr(0xc000502d80, 0x5, 0x8, 0xc00052aa00, 0x5, 0x5, 0x0, 0xc00079e300, 0x1976340, 0xc00079e2d0, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_eval.go:96 +0x7e0
cloud.google.com/go/spanner/spannertest.whereIter.Next(0x196b600, 0xc00017a530, 0xc000502d80, 0x5, 0x8, 0xc00052aa00, 0x5, 0x5, 0x0, 0xc00079e300, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_query.go:153 +0xe4
cloud.google.com/go/spanner/spannertest.selIter.Next(0x196d980, 0xc000600720, 0xc000502d80, 0x5, 0x8, 0x0, 0x0, 0x0, 0x0, 0xc00079e300, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_query.go:174 +0x49
cloud.google.com/go/spanner/spannertest.toRawIter(0x196d940, 0xc0006f0180, 0xc0004cfca8, 0xc0006f9478, 0xc0006f9200)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_query.go:126 +0xe6
cloud.google.com/go/spanner/spannertest.(*database).evalSelect.func1(0xc0006f9928, 0xc0006f9918)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_query.go:355 +0x50
cloud.google.com/go/spanner/spannertest.(*database).evalSelect(0xc0000c5448, 0x0, 0xc0006f0080, 0x5, 0x8, 0xc00079e2a0, 0x1, 0x1, 0x1976340, 0xc00079e2d0, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_query.go:570 +0x479
cloud.google.com/go/spanner/spannertest.(*database).Query(0xc0000c5448, 0x0, 0xc0006f0080, 0x5, 0x8, 0xc00079e2a0, 0x1, 0x1, 0x1976340, 0xc00079e2d0, ...)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/db_query.go:285 +0x225
cloud.google.com/go/spanner/spannertest.(*server).ExecuteStreamingSql(0xc0000c5440, 0xc0006e8000, 0x1981760, 0xc00017a3d0, 0x0, 0x0)
    /Users/gbelvin/go/pkg/mod/cloud.google.com/go/spanner@v1.6.0/spannertest/inmem.go:523 +0x327
google.golang.org/genproto/googleapis/spanner/v1._Spanner_ExecuteStreamingSql_Handler(0x18520e0, 0xc0000c5440, 0x197f060, 0xc0006e6000, 0x1f126a0, 0xc0006de000)
    /Users/gbelvin/go/pkg/mod/google.golang.org/genproto@v0.0.0-20200528110217-3d3490e7e671/googleapis/spanner/v1/spanner.pb.go:3597 +0x109
google.golang.org/grpc.(*Server).processStreamingRPC(0xc0001fb860, 0x1983920, 0xc0004cf680, 0xc0006de000, 0xc0004b6690, 0x1ed6f60, 0x0, 0x0, 0x0)
    /Users/gbelvin/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1329 +0xcbd
google.golang.org/grpc.(*Server).handleStream(0xc0001fb860, 0x1983920, 0xc0004cf680, 0xc0006de000, 0x0)
    /Users/gbelvin/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1409 +0xc66
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00003c0d0, 0xc0001fb860, 0x1983920, 0xc0004cf680, 0xc0006de000)
    /Users/gbelvin/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746 +0xa1
created by google.golang.org/grpc.(*Server).serveStreams.func1
    /Users/gbelvin/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:744 +0xa1
FAIL    github.com/google/trillian/storage/cloudspanner 1.260s
dsymonds commented 4 years ago

Yeah, that == should probably be using compareVals. Should be easy to fix.