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

Method Call

runtime/sam/expr/function/unflatten.go:30–67  ·  view source on GitHub ↗
(args []super.Value)

Source from the content-addressed store, hash-verified

28}
29
30func (u *Unflatten) Call(args []super.Value) super.Value {
31 val := args[0]
32 array, ok := super.TypeUnder(val.Type()).(*super.TypeArray)
33 if !ok {
34 return val
35 }
36 u.recordCache.reset()
37 root := u.recordCache.new()
38 u.types = u.types[:0]
39 u.values = u.values[:0]
40 for it := val.Bytes().Iter(); !it.Done(); {
41 bytes := it.Next()
42 path, typ, vb, err := u.parseElem(array.Type, bytes)
43 if err != nil {
44 return u.sctx.WrapError(err.Error(), super.NewValue(array.Type, bytes))
45 }
46 if typ == nil {
47 continue
48 }
49 if removed := root.addPath(&u.recordCache, path); removed > 0 {
50 u.types = u.types[:len(u.types)-removed]
51 u.values = u.values[:len(u.values)-removed]
52 }
53 u.types = append(u.types, typ)
54 u.values = append(u.values, vb)
55 }
56 u.builder.Reset()
57 types, values := u.types, u.values
58 typ, err := root.build(u.sctx, &u.builder, func() (super.Type, scode.Bytes) {
59 typ, value := types[0], values[0]
60 types, values = types[1:], values[1:]
61 return typ, value
62 })
63 if err != nil {
64 return u.sctx.WrapError(err.Error(), val)
65 }
66 return super.NewValue(typ, u.builder.Bytes())
67}
68
69func (u *Unflatten) parseElem(inner super.Type, vb scode.Bytes) (field.Path, super.Type, scode.Bytes, error) {
70 if union, ok := super.TypeUnder(inner).(*super.TypeUnion); ok {

Callers

nothing calls this directly

Calls 15

parseElemMethod · 0.95
TypeUnderFunction · 0.92
NewValueFunction · 0.92
newMethod · 0.80
IterMethod · 0.80
WrapErrorMethod · 0.80
addPathMethod · 0.80
TypeMethod · 0.65
resetMethod · 0.45
BytesMethod · 0.45
DoneMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected