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

Method Forward

runtime/sam/op/exprswitch/exprswitch.go:46–87  ·  view source on GitHub ↗
(router *op.Router, batch sbuf.Batch)

Source from the content-addressed store, hash-verified

44}
45
46func (s *ExprSwitch) Forward(router *op.Router, batch sbuf.Batch) bool {
47 vals := batch.Values()
48 for i := range vals {
49 val := s.expr.Eval(vals[i])
50 if val.IsMissing() {
51 continue
52 }
53 which, ok := s.cases[string(val.Bytes())]
54 if !ok {
55 which = s.defaultCase
56 }
57 if which == nil {
58 continue
59 }
60 which.vals = append(which.vals, vals[i])
61 }
62 // Send each case that has vals from this batch.
63 // We have vals that point into the current batch so we
64 // ref the batch for each outgoing new batch.
65 for _, c := range s.cases {
66 if len(c.vals) > 0 {
67 // XXX The new slice should come from the
68 // outgoing batch so we don't send these slices
69 // through GC.
70 batch.Ref()
71 out := sbuf.NewBatch(c.vals)
72 c.vals = nil
73 if ok := router.Send(c.route, out, nil); !ok {
74 return false
75 }
76 }
77 }
78 if c := s.defaultCase; c != nil && len(c.vals) > 0 {
79 batch.Ref()
80 out := sbuf.NewArray(c.vals)
81 c.vals = nil
82 if ok := router.Send(c.route, out, nil); !ok {
83 return false
84 }
85 }
86 return true
87}

Callers

nothing calls this directly

Calls 8

NewBatchFunction · 0.92
NewArrayFunction · 0.92
SendMethod · 0.80
ValuesMethod · 0.65
EvalMethod · 0.65
RefMethod · 0.65
IsMissingMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected