MCPcopy Index your code
hub / github.com/cloudspannerecosystem/spanner-cli / DecodeColumn

Function DecodeColumn

decoder.go:45–277  ·  view source on GitHub ↗
(column spanner.GenericColumnValue)

Source from the content-addressed store, hash-verified

43}
44
45func DecodeColumn(column spanner.GenericColumnValue) (string, error) {
46 // Allowable types: https://cloud.google.com/spanner/docs/data-types#allowable-types
47 switch column.Type.Code {
48 case sppb.TypeCode_ARRAY:
49 var decoded []string
50 switch column.Type.GetArrayElementType().Code {
51 case sppb.TypeCode_BOOL:
52 var vs []spanner.NullBool
53 if err := column.Decode(&vs); err != nil {
54 return "", err
55 }
56 if vs == nil {
57 return "NULL", nil
58 }
59 for _, v := range vs {
60 decoded = append(decoded, nullBoolToString(v))
61 }
62 case sppb.TypeCode_BYTES, sppb.TypeCode_PROTO:
63 var vs [][]byte
64 if err := column.Decode(&vs); err != nil {
65 return "", err
66 }
67 if vs == nil {
68 return "NULL", nil
69 }
70 for _, v := range vs {
71 decoded = append(decoded, nullBytesToString(v))
72 }
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 }
84 case sppb.TypeCode_FLOAT64:
85 var vs []spanner.NullFloat64
86 if err := column.Decode(&vs); err != nil {
87 return "", err
88 }
89 if vs == nil {
90 return "NULL", nil
91 }
92 for _, v := range vs {
93 decoded = append(decoded, nullFloat64ToString(v))
94 }
95 case sppb.TypeCode_INT64, sppb.TypeCode_ENUM:
96 var vs []spanner.NullInt64
97 if err := column.Decode(&vs); err != nil {
98 return "", err
99 }
100 if vs == nil {
101 return "NULL", nil
102 }

Callers 2

DecodeRowFunction · 0.85
TestDecodeColumnFunction · 0.85

Calls 13

nullBoolToStringFunction · 0.85
nullBytesToStringFunction · 0.85
nullFloat32ToStringFunction · 0.85
nullFloat64ToStringFunction · 0.85
nullInt64ToStringFunction · 0.85
nullNumericToStringFunction · 0.85
nullStringToStringFunction · 0.85
nullTimeToStringFunction · 0.85
nullDateToStringFunction · 0.85
DecodeRowFunction · 0.85
nullJSONToStringFunction · 0.85
nullIntervalToStringFunction · 0.85

Tested by 1

TestDecodeColumnFunction · 0.68