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

Method parseElem

runtime/sam/expr/function/unflatten.go:69–101  ·  view source on GitHub ↗
(inner super.Type, vb scode.Bytes)

Source from the content-addressed store, hash-verified

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 {
71 inner, vb = union.Untag(vb)
72 }
73 typ := super.TypeRecordOf(inner)
74 if typ == nil || len(typ.Fields) != 2 {
75 return nil, nil, nil, nil
76 }
77 nkey, ok := typ.IndexOfField("key")
78 if !ok {
79 return nil, nil, nil, nil
80 }
81
82 vtyp, ok := typ.TypeOfField("value")
83 if !ok {
84 return nil, nil, nil, nil
85 }
86 it := scode.NewRecordIter(vb, 0)
87 kbytes, _ := it.Next(false)
88 vbytes, _ := it.Next(false)
89 if nkey == 1 {
90 kbytes, vbytes = vbytes, kbytes
91 }
92 ktyp := typ.Fields[nkey].Type
93 if ktyp.ID() == super.IDString {
94 u.path = append(u.path[:0], super.DecodeString(kbytes))
95 return u.path, vtyp, vbytes, nil
96 }
97 if a, ok := super.TypeUnder(ktyp).(*super.TypeArray); ok && a.Type.ID() == super.IDString {
98 return u.decodeKey(kbytes), vtyp, vbytes, nil
99 }
100 return nil, nil, nil, fmt.Errorf("invalid key type %s: expected either string or [string]", sup.FormatType(ktyp))
101}
102
103func (u *Unflatten) decodeKey(b scode.Bytes) field.Path {
104 u.path = u.path[:0]

Callers 1

CallMethod · 0.95

Calls 11

NextMethod · 0.95
decodeKeyMethod · 0.95
TypeUnderFunction · 0.92
TypeRecordOfFunction · 0.92
NewRecordIterFunction · 0.92
DecodeStringFunction · 0.92
FormatTypeFunction · 0.92
UntagMethod · 0.80
TypeOfFieldMethod · 0.80
IDMethod · 0.65
IndexOfFieldMethod · 0.45

Tested by

no test coverage detected