Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
for _, v := range vs {
decoded = append(decoded, nullBytesToString(v))
}
case sppb.TypeCode_FLOAT32:
var vs []spanner.NullFloat32
if err := column.Decode(&vs); err != nil {
return "", err
}
if vs == nil {
return "NULL", nil
}
for _, v := range vs {
decoded = append(decoded, nullFloat32ToString(v))
}
case sppb.TypeCode_FLOAT64:
var vs []spanner.NullFloat64
if err := column.Decode(&vs); err != nil {
Expand Down Expand Up @@ -178,6 +189,12 @@ func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
return "", err
}
return nullBytesToString(v), nil
case sppb.TypeCode_FLOAT32:
var v spanner.NullFloat32
if err := column.Decode(&v); err != nil {
return "", err
}
return nullFloat32ToString(v), nil
case sppb.TypeCode_FLOAT64:
var v spanner.NullFloat64
if err := column.Decode(&v); err != nil {
Expand Down Expand Up @@ -241,6 +258,14 @@ func nullBytesToString(v []byte) string {
}
}

func nullFloat32ToString(v spanner.NullFloat32) string {
if v.Valid {
return fmt.Sprintf("%f", v.Float32)
} else {
return "NULL"
}
}

func nullFloat64ToString(v spanner.NullFloat64) string {
if v.Valid {
return fmt.Sprintf("%f", v.Float64)
Expand Down
22 changes: 21 additions & 1 deletion decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func TestDecodeColumn(t *testing.T) {
value: []byte{'a', 'b', 'c', 'd'},
want: "YWJjZA==", // base64 encoded 'abc'
},
{
desc: "float32",
value: float32(1.23),
want: "1.230000",
},
{
desc: "float64",
value: 1.23,
Expand Down Expand Up @@ -141,6 +146,11 @@ func TestDecodeColumn(t *testing.T) {
value: []byte(nil),
want: "NULL",
},
{
desc: "null float32",
value: spanner.NullFloat32{Float32: 0, Valid: false},
want: "NULL",
},
{
desc: "null float64",
value: spanner.NullFloat64{Float64: 0, Valid: false},
Expand Down Expand Up @@ -193,6 +203,11 @@ func TestDecodeColumn(t *testing.T) {
value: [][]byte{{'a', 'b', 'c', 'd'}, {'e', 'f', 'g', 'h'}},
want: "[YWJjZA==, ZWZnaA==]",
},
{
desc: "array float32",
value: []float32{1.23, 2.45},
want: "[1.230000, 2.450000]",
},
{
desc: "array float64",
value: []float64{1.23, 2.45},
Expand Down Expand Up @@ -261,7 +276,12 @@ func TestDecodeColumn(t *testing.T) {
want: "NULL",
},
{
desc: "nul array float64",
desc: "null array float32",
value: []float32(nil),
want: "NULL",
},
{
desc: "null array float64",
value: []float64(nil),
want: "NULL",
},
Expand Down
69 changes: 34 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,60 @@ module github.com/cloudspannerecosystem/spanner-cli
go 1.19

require (
cloud.google.com/go v0.111.0
cloud.google.com/go/spanner v1.55.0
cloud.google.com/go v0.112.2
cloud.google.com/go/spanner v1.59.0
github.com/apstndb/gsqlsep v0.0.0-20230324124551-0e8335710080
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/google/go-cmp v0.6.0
github.com/jessevdk/go-flags v1.4.0
github.com/olekukonko/tablewriter v0.0.4
github.com/xlab/treeprint v1.0.1-0.20200715141336-10e0bc383e01
google.golang.org/api v0.155.0
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
google.golang.org/api v0.173.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
)

require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
cel.dev/expr v0.15.0 // indirect
cloud.google.com/go/auth v0.6.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.1.0 // indirect
cloud.google.com/go/compute/metadata v0.4.0 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/longrunning v0.5.6 // indirect
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/envoyproxy/go-control-plane v0.11.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-runewidth v0.0.8 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b // indirect
)
Loading