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

Method eval

runtime/sam/expr/function/defuse.go:28–105  ·  view source on GitHub ↗
(in super.Value)

Source from the content-addressed store, hash-verified

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

Callers 2

CallMethod · 0.95
parseArrayOrSetMethod · 0.95

Calls 15

hasFusionMethod · 0.95
BeginContainerMethod · 0.95
NextMethod · 0.95
AppendMethod · 0.95
EndContainerWithNonesMethod · 0.95
BytesMethod · 0.95
parseArrayOrSetMethod · 0.95
unifyMethod · 0.95
DoneMethod · 0.95
unifyTypeMethod · 0.95
NewRecordIterFunction · 0.92
NewValueFunction · 0.92

Tested by

no test coverage detected