Skip to content

Commit f1ab4c9

Browse files
authored
Support FLOAT32 type (#176)
* Support FLOAT32 type * Revert go directive * Use minimum version of dependencies
1 parent e1ee214 commit f1ab4c9

4 files changed

Lines changed: 1574 additions & 99 deletions

File tree

decoder.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
7070
for _, v := range vs {
7171
decoded = append(decoded, nullBytesToString(v))
7272
}
73+
case sppb.TypeCode_FLOAT32:
74+
var vs []spanner.NullFloat32
75+
if err := column.Decode(&vs); err != nil {
76+
return "", err
77+
}
78+
if vs == nil {
79+
return "NULL", nil
80+
}
81+
for _, v := range vs {
82+
decoded = append(decoded, nullFloat32ToString(v))
83+
}
7384
case sppb.TypeCode_FLOAT64:
7485
var vs []spanner.NullFloat64
7586
if err := column.Decode(&vs); err != nil {
@@ -178,6 +189,12 @@ func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
178189
return "", err
179190
}
180191
return nullBytesToString(v), nil
192+
case sppb.TypeCode_FLOAT32:
193+
var v spanner.NullFloat32
194+
if err := column.Decode(&v); err != nil {
195+
return "", err
196+
}
197+
return nullFloat32ToString(v), nil
181198
case sppb.TypeCode_FLOAT64:
182199
var v spanner.NullFloat64
183200
if err := column.Decode(&v); err != nil {
@@ -241,6 +258,14 @@ func nullBytesToString(v []byte) string {
241258
}
242259
}
243260

261+
func nullFloat32ToString(v spanner.NullFloat32) string {
262+
if v.Valid {
263+
return fmt.Sprintf("%f", v.Float32)
264+
} else {
265+
return "NULL"
266+
}
267+
}
268+
244269
func nullFloat64ToString(v spanner.NullFloat64) string {
245270
if v.Valid {
246271
return fmt.Sprintf("%f", v.Float64)

decoder_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func TestDecodeColumn(t *testing.T) {
8989
value: []byte{'a', 'b', 'c', 'd'},
9090
want: "YWJjZA==", // base64 encoded 'abc'
9191
},
92+
{
93+
desc: "float32",
94+
value: float32(1.23),
95+
want: "1.230000",
96+
},
9297
{
9398
desc: "float64",
9499
value: 1.23,
@@ -141,6 +146,11 @@ func TestDecodeColumn(t *testing.T) {
141146
value: []byte(nil),
142147
want: "NULL",
143148
},
149+
{
150+
desc: "null float32",
151+
value: spanner.NullFloat32{Float32: 0, Valid: false},
152+
want: "NULL",
153+
},
144154
{
145155
desc: "null float64",
146156
value: spanner.NullFloat64{Float64: 0, Valid: false},
@@ -193,6 +203,11 @@ func TestDecodeColumn(t *testing.T) {
193203
value: [][]byte{{'a', 'b', 'c', 'd'}, {'e', 'f', 'g', 'h'}},
194204
want: "[YWJjZA==, ZWZnaA==]",
195205
},
206+
{
207+
desc: "array float32",
208+
value: []float32{1.23, 2.45},
209+
want: "[1.230000, 2.450000]",
210+
},
196211
{
197212
desc: "array float64",
198213
value: []float64{1.23, 2.45},
@@ -261,7 +276,12 @@ func TestDecodeColumn(t *testing.T) {
261276
want: "NULL",
262277
},
263278
{
264-
desc: "nul array float64",
279+
desc: "null array float32",
280+
value: []float32(nil),
281+
want: "NULL",
282+
},
283+
{
284+
desc: "null array float64",
265285
value: []float64(nil),
266286
want: "NULL",
267287
},

go.mod

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,60 @@ module github.com/cloudspannerecosystem/spanner-cli
33
go 1.19
44

55
require (
6-
cloud.google.com/go v0.111.0
7-
cloud.google.com/go/spanner v1.55.0
6+
cloud.google.com/go v0.112.2
7+
cloud.google.com/go/spanner v1.59.0
88
github.com/apstndb/gsqlsep v0.0.0-20230324124551-0e8335710080
99
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
1010
github.com/google/go-cmp v0.6.0
1111
github.com/jessevdk/go-flags v1.4.0
1212
github.com/olekukonko/tablewriter v0.0.4
1313
github.com/xlab/treeprint v1.0.1-0.20200715141336-10e0bc383e01
14-
google.golang.org/api v0.155.0
15-
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0
16-
google.golang.org/grpc v1.60.1
17-
google.golang.org/protobuf v1.32.0
14+
google.golang.org/api v0.173.0
15+
google.golang.org/grpc v1.65.0
16+
google.golang.org/protobuf v1.34.2
1817
)
1918

2019
require (
21-
cloud.google.com/go/compute v1.23.3 // indirect
22-
cloud.google.com/go/compute/metadata v0.2.3 // indirect
23-
cloud.google.com/go/iam v1.1.5 // indirect
24-
cloud.google.com/go/longrunning v0.5.4 // indirect
20+
cel.dev/expr v0.15.0 // indirect
21+
cloud.google.com/go/auth v0.6.1 // indirect
22+
cloud.google.com/go/auth/oauth2adapt v0.1.0 // indirect
23+
cloud.google.com/go/compute/metadata v0.4.0 // indirect
24+
cloud.google.com/go/iam v1.1.7 // indirect
25+
cloud.google.com/go/longrunning v0.5.6 // indirect
26+
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.0 // indirect
2527
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
26-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
27-
github.com/chzyer/logex v1.1.10 // indirect
28-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
29-
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
30-
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
31-
github.com/envoyproxy/go-control-plane v0.11.1 // indirect
32-
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
28+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
29+
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect
30+
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
31+
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
3332
github.com/felixge/httpsnoop v1.0.4 // indirect
34-
github.com/go-logr/logr v1.3.0 // indirect
33+
github.com/go-logr/logr v1.4.2 // indirect
3534
github.com/go-logr/stdr v1.2.2 // indirect
3635
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
37-
github.com/golang/protobuf v1.5.3 // indirect
36+
github.com/golang/protobuf v1.5.4 // indirect
3837
github.com/google/s2a-go v0.1.7 // indirect
3938
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
40-
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
39+
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
4140
github.com/json-iterator/go v1.1.12 // indirect
4241
github.com/mattn/go-runewidth v0.0.8 // indirect
43-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
42+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4443
github.com/modern-go/reflect2 v1.0.2 // indirect
4544
go.opencensus.io v0.24.0 // indirect
46-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
47-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
48-
go.opentelemetry.io/otel v1.21.0 // indirect
49-
go.opentelemetry.io/otel/metric v1.21.0 // indirect
50-
go.opentelemetry.io/otel/trace v1.21.0 // indirect
51-
golang.org/x/crypto v0.17.0 // indirect
45+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
46+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
47+
go.opentelemetry.io/otel v1.24.0 // indirect
48+
go.opentelemetry.io/otel/metric v1.24.0 // indirect
49+
go.opentelemetry.io/otel/trace v1.24.0 // indirect
50+
golang.org/x/crypto v0.25.0 // indirect
5251
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 // indirect
53-
golang.org/x/net v0.19.0 // indirect
54-
golang.org/x/oauth2 v0.15.0 // indirect
55-
golang.org/x/sync v0.5.0 // indirect
56-
golang.org/x/sys v0.15.0 // indirect
57-
golang.org/x/text v0.14.0 // indirect
52+
golang.org/x/net v0.27.0 // indirect
53+
golang.org/x/oauth2 v0.21.0 // indirect
54+
golang.org/x/sync v0.7.0 // indirect
55+
golang.org/x/sys v0.22.0 // indirect
56+
golang.org/x/text v0.16.0 // indirect
5857
golang.org/x/time v0.5.0 // indirect
5958
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
60-
google.golang.org/appengine v1.6.8 // indirect
61-
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
62-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
59+
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
60+
google.golang.org/genproto/googleapis/api v0.0.0-20240708141625-4ad9e859172b // indirect
61+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b // indirect
6362
)

0 commit comments

Comments
 (0)