MCPcopy Create free account
hub / github.com/brimdata/super / castToString

Function castToString

runtime/vam/expr/cast/string.go:16–139  ·  view source on GitHub ↗
(vec vector.Any, index []uint32)

Source from the content-addressed store, hash-verified

14)
15
16func castToString(vec vector.Any, index []uint32) (vector.Any, []uint32, string, bool) {
17 n := lengthOf(vec, index)
18 var bytes []byte
19 offs := []uint32{0}
20 switch vec := vec.(type) {
21 case *vector.Int:
22 switch vec.Type().ID() {
23 case super.IDDuration:
24 offs, bytes = durToString(vec, index, n)
25 case super.IDTime:
26 offs, bytes = timeToString(vec, index, n)
27 default:
28 for i := range n {
29 idx := i
30 if index != nil {
31 idx = index[i]
32 }
33 bytes = strconv.AppendInt(bytes, vec.Values[idx], 10)
34 offs = append(offs, uint32(len(bytes)))
35 }
36 }
37 case *vector.Uint:
38 for i := range n {
39 idx := i
40 if index != nil {
41 idx = index[i]
42 }
43 bytes = strconv.AppendUint(bytes, vec.Values[idx], 10)
44 offs = append(offs, uint32(len(bytes)))
45 }
46 case *vector.Float:
47 for i := range n {
48 idx := i
49 if index != nil {
50 idx = index[i]
51 }
52 v := vec.Values[idx]
53 bitSize := 64
54 switch vec.Type().ID() {
55 case super.IDFloat16:
56 // Discard extra precision.
57 v = float64(float16.Fromfloat32(float32(v)).Float32())
58 bitSize = 32
59 case super.IDFloat32:
60 bitSize = 32
61 }
62 bytes = strconv.AppendFloat(bytes, v, 'g', -1, bitSize)
63 offs = append(offs, uint32(len(bytes)))
64 }
65 case *vector.String:
66 if index == nil {
67 return vec, nil, "", true
68 }
69 for _, idx := range index {
70 bytes = append(bytes, vec.Value(idx)...)
71 offs = append(offs, uint32(len(bytes)))
72 }
73 case *vector.Bytes:

Callers

nothing calls this directly

Calls 15

ResetMethod · 0.95
BytesMethod · 0.95
AnyInterface · 0.92
NewStringFunction · 0.92
PickFunction · 0.92
ReversePickFunction · 0.92
NewValueFunction · 0.92
FormatValueFunction · 0.92
NewBytesTableFunction · 0.92
lengthOfFunction · 0.85
durToStringFunction · 0.85
timeToStringFunction · 0.85

Tested by

no test coverage detected