Skip to content

Commit eed796c

Browse files
authored
feat: Support UUID type (#220)
1 parent 0d0904f commit eed796c

File tree

4 files changed

+97
-39
lines changed

4 files changed

+97
-39
lines changed

decoder.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
175175
for _, v := range vs {
176176
decoded = append(decoded, nullJSONToString(v))
177177
}
178+
case sppb.TypeCode_UUID:
179+
var vs []spanner.NullUUID
180+
if err := column.Decode(&vs); err != nil {
181+
return "", err
182+
}
183+
if vs == nil {
184+
return "NULL", nil
185+
}
186+
for _, v := range vs {
187+
decoded = append(decoded, nullUUIDToString(v))
188+
}
178189
}
179190
return fmt.Sprintf("[%s]", strings.Join(decoded, ", ")), nil
180191
case sppb.TypeCode_BOOL:
@@ -237,6 +248,12 @@ func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
237248
return "", err
238249
}
239250
return nullJSONToString(v), nil
251+
case sppb.TypeCode_UUID:
252+
var v spanner.NullUUID
253+
if err := column.Decode(&v); err != nil {
254+
return "", err
255+
}
256+
return nullUUIDToString(v), nil
240257
default:
241258
return fmt.Sprintf("%s", column.Value), nil
242259
}
@@ -324,6 +341,14 @@ func nullJSONToString(v spanner.NullJSON) string {
324341
}
325342
}
326343

344+
func nullUUIDToString(v spanner.NullUUID) string {
345+
if v.Valid {
346+
return v.String()
347+
} else {
348+
return "NULL"
349+
}
350+
}
351+
327352
func formatTypeSimple(typ *sppb.Type) string {
328353
switch code := typ.GetCode(); code {
329354
case sppb.TypeCode_ARRAY:

decoder_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
sppb "cloud.google.com/go/spanner/apiv1/spannerpb"
25+
"github.com/google/uuid"
2526
"google.golang.org/protobuf/types/known/structpb"
2627
"google.golang.org/protobuf/types/known/typepb"
2728

@@ -138,6 +139,11 @@ func TestDecodeColumn(t *testing.T) {
138139
value: spanner.NullJSON{Value: nil, Valid: true},
139140
want: `null`,
140141
},
142+
{
143+
desc: "uuid",
144+
value: spanner.NullUUID{UUID: uuid.MustParse("1778a92d-dcdb-4e7c-a515-b6f953b59e54"), Valid: true},
145+
want: `1778a92d-dcdb-4e7c-a515-b6f953b59e54`,
146+
},
141147

142148
// nullable
143149
{
@@ -190,6 +196,11 @@ func TestDecodeColumn(t *testing.T) {
190196
value: spanner.NullJSON{Value: nil, Valid: false},
191197
want: "NULL",
192198
},
199+
{
200+
desc: "null uuid",
201+
value: spanner.NullUUID{UUID: uuid.UUID{}, Valid: false},
202+
want: "NULL",
203+
},
193204

194205
// array non-nullable
195206
{
@@ -267,6 +278,14 @@ func TestDecodeColumn(t *testing.T) {
267278
},
268279
want: `[{"msg":"foo"}, {"msg":"bar"}]`,
269280
},
281+
{
282+
desc: "array uuid",
283+
value: []spanner.NullUUID{
284+
{UUID: uuid.MustParse("1778a92d-dcdb-4e7c-a515-b6f953b59e54"), Valid: true},
285+
{UUID: uuid.MustParse("7cdd7424-867d-4293-8597-dc07f14ac733"), Valid: true},
286+
},
287+
want: `[1778a92d-dcdb-4e7c-a515-b6f953b59e54, 7cdd7424-867d-4293-8597-dc07f14ac733]`,
288+
},
270289

271290
// array nullable
272291
{
@@ -319,6 +338,11 @@ func TestDecodeColumn(t *testing.T) {
319338
value: []spanner.NullJSON(nil),
320339
want: "NULL",
321340
},
341+
{
342+
desc: "null array uuid",
343+
value: []spanner.NullUUID(nil),
344+
want: "NULL",
345+
},
322346

323347
// PROTO
324348
// This table tests uses spanner.GenericColumnValue because of non-stability

go.mod

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@ module github.com/cloudspannerecosystem/spanner-cli
33
go 1.24
44

55
require (
6-
cloud.google.com/go v0.120.1
7-
cloud.google.com/go/spanner v1.79.0
6+
cloud.google.com/go v0.121.0
7+
cloud.google.com/go/spanner v1.81.1
88
github.com/apstndb/gsqlsep v0.0.0-20240823174243-432be37d515a
99
github.com/chzyer/readline v1.5.1
1010
github.com/google/go-cmp v0.7.0
1111
github.com/jessevdk/go-flags v1.6.1
1212
github.com/olekukonko/tablewriter v0.0.5
1313
github.com/xlab/treeprint v1.2.0
14-
google.golang.org/api v0.229.0
14+
google.golang.org/api v0.232.0
1515
google.golang.org/genproto v0.0.0-20250414145226-207652e42e2e
16-
google.golang.org/grpc v1.71.1
16+
google.golang.org/grpc v1.72.0
1717
google.golang.org/protobuf v1.36.6
1818
)
1919

2020
require (
21-
cel.dev/expr v0.19.2 // indirect
22-
cloud.google.com/go/auth v0.16.0 // indirect
21+
cel.dev/expr v0.20.0 // indirect
22+
cloud.google.com/go/auth v0.16.1 // indirect
2323
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
2424
cloud.google.com/go/compute/metadata v0.6.0 // indirect
25-
cloud.google.com/go/iam v1.5.0 // indirect
26-
cloud.google.com/go/longrunning v0.6.6 // indirect
27-
cloud.google.com/go/monitoring v1.24.1 // indirect
25+
cloud.google.com/go/iam v1.5.2 // indirect
26+
cloud.google.com/go/longrunning v0.6.7 // indirect
27+
cloud.google.com/go/monitoring v1.24.2 // indirect
2828
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
2929
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
3030
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3131
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
3232
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
3333
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
3434
github.com/felixge/httpsnoop v1.0.4 // indirect
35+
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
3536
github.com/go-logr/logr v1.4.2 // indirect
3637
github.com/go-logr/stdr v1.2.2 // indirect
3738
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
@@ -41,6 +42,8 @@ require (
4142
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
4243
github.com/mattn/go-runewidth v0.0.9 // indirect
4344
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
45+
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
46+
github.com/zeebo/errs v1.4.0 // indirect
4447
go.opencensus.io v0.24.0 // indirect
4548
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
4649
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
@@ -54,11 +57,11 @@ require (
5457
golang.org/x/crypto v0.37.0 // indirect
5558
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 // indirect
5659
golang.org/x/net v0.39.0 // indirect
57-
golang.org/x/oauth2 v0.29.0 // indirect
58-
golang.org/x/sync v0.13.0 // indirect
60+
golang.org/x/oauth2 v0.30.0 // indirect
61+
golang.org/x/sync v0.14.0 // indirect
5962
golang.org/x/sys v0.32.0 // indirect
6063
golang.org/x/text v0.24.0 // indirect
6164
golang.org/x/time v0.11.0 // indirect
62-
google.golang.org/genproto/googleapis/api v0.0.0-20250414145226-207652e42e2e // indirect
63-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250414145226-207652e42e2e // indirect
65+
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
66+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2 // indirect
6467
)

0 commit comments

Comments
 (0)