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

Method Call

runtime/vam/expr/function/regexp.go:20–59  ·  view source on GitHub ↗
(args ...vector.Any)

Source from the content-addressed store, hash-verified

18}
19
20func (r *Regexp) Call(args ...vector.Any) vector.Any {
21 if vec, ok := expr.CheckForNullThenError(args); ok {
22 return vec
23 }
24 args = underAll(args)
25 regVec, inputVec := args[0], args[1]
26 if regVec.Type().ID() != super.IDString {
27 return vector.NewWrappedError(r.sctx, "regexp: string required for first arg", args[0])
28 }
29 if inputVec.Type().ID() != super.IDString {
30 return vector.NewWrappedError(r.sctx, "regexp: string required for second arg", args[1])
31 }
32 errMsg := vector.NewStringEmpty(0)
33 var errs []uint32
34 inner := vector.NewStringEmpty(0)
35 out := vector.NewArray(r.sctx.LookupTypeArray(super.TypeString), []uint32{0}, inner)
36 for i := range regVec.Len() {
37 re := vector.StringValue(regVec, i)
38 if r.restr != re {
39 r.restr = re
40 r.re, r.err = regexp.Compile(r.restr)
41 }
42 if r.err != nil {
43 errMsg.Append(regexpErrMsg("regexp", r.err))
44 errs = append(errs, i)
45 continue
46 }
47 s := vector.StringValue(inputVec, i)
48 match := r.re.FindStringSubmatch(s)
49 for _, b := range match {
50 inner.Append(b)
51 }
52 out.Offsets = append(out.Offsets, inner.Len())
53 }
54 c := vector.NewCombiner(out)
55 if len(errs) > 0 {
56 c.Add(errs, vector.NewVecWrappedError(r.sctx, errMsg, vector.Pick(regVec, errs)))
57 }
58 return c.Result()
59}
60
61type RegexpReplace struct {
62 sctx *super.Context

Callers

nothing calls this directly

Calls 15

AddMethod · 0.95
ResultMethod · 0.95
CheckForNullThenErrorFunction · 0.92
NewWrappedErrorFunction · 0.92
NewStringEmptyFunction · 0.92
NewArrayFunction · 0.92
StringValueFunction · 0.92
NewCombinerFunction · 0.92
NewVecWrappedErrorFunction · 0.92
PickFunction · 0.92
regexpErrMsgFunction · 0.85
LookupTypeArrayMethod · 0.80

Tested by

no test coverage detected