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

Method eval

runtime/sam/expr/function/unblend.go:20–85  ·  view source on GitHub ↗
(in super.Value)

Source from the content-addressed store, hash-verified

18}
19
20func (u *unblend) eval(in super.Value) super.Value {
21 switch typ := in.Type().(type) {
22 case *super.TypeRecord:
23 var fields []super.Field
24 var elems []super.Value
25 it := scode.NewRecordIter(in.Bytes(), typ.Opts)
26 for _, f := range typ.Fields {
27 bytes, none := it.Next(f.Opt)
28 if none {
29 continue
30 }
31 val := u.eval(super.NewValue(f.Type, bytes))
32 elems = append(elems, val)
33 fields = append(fields, super.NewField(f.Name, val.Type()))
34 }
35 var b scode.Builder
36 for _, e := range elems {
37 b.Append(e.Bytes())
38 }
39 return super.NewValue(u.sctx.MustLookupTypeRecord(fields), b.Bytes())
40 case *super.TypeArray:
41 elems := u.arrayOrSet(typ.Type, in.Bytes())
42 if len(elems) == 0 {
43 typ := u.sctx.LookupTypeArray(super.TypeNull)
44 return super.NewValue(typ, nil)
45 }
46 elemType, bytes := u.unify(elems)
47 return super.NewValue(u.sctx.LookupTypeArray(elemType), bytes)
48 case *super.TypeSet:
49 elems := u.arrayOrSet(typ.Type, in.Bytes())
50 if len(elems) == 0 {
51 typ := u.sctx.LookupTypeArray(super.TypeNull)
52 return super.NewValue(typ, nil)
53 }
54 elemType, bytes := u.unify(elems)
55 return super.NewValue(u.sctx.LookupTypeSet(elemType), bytes)
56 case *super.TypeMap:
57 var keys, vals []super.Value
58 for it := in.Bytes().Iter(); !it.Done(); {
59 keys = append(keys, super.NewValue(typ, it.Next()))
60 vals = append(vals, super.NewValue(typ, it.Next()))
61 }
62 keyType := u.unifyType(keys)
63 valType := u.unifyType(vals)
64 var b scode.Builder
65 for k, key := range keys {
66 if u, ok := keyType.(*super.TypeUnion); ok {
67 super.BuildUnion(&b, u.TagOf(u), key.Bytes())
68 } else {
69 b.Append(key.Bytes())
70 }
71 val := vals[k]
72 if u, ok := valType.(*super.TypeUnion); ok {
73 super.BuildUnion(&b, u.TagOf(u), val.Bytes())
74 } else {
75 b.Append(val.Bytes())
76 }
77 }

Callers 2

CallMethod · 0.95
arrayOrSetMethod · 0.95

Calls 15

NextMethod · 0.95
AppendMethod · 0.95
BytesMethod · 0.95
arrayOrSetMethod · 0.95
unifyMethod · 0.95
DoneMethod · 0.95
unifyTypeMethod · 0.95
NewRecordIterFunction · 0.92
NewValueFunction · 0.92
NewFieldFunction · 0.92
BuildUnionFunction · 0.92
MustLookupTypeRecordMethod · 0.80

Tested by

no test coverage detected