Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/sam/expr/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func NewRegexpMatch(re *regexp.Regexp, e Evaluator) *RegexpMatch {
}

func (r *RegexpMatch) Eval(this super.Value) super.Value {
val := r.expr.Eval(this)
val := r.expr.Eval(this).Under()
switch id := val.Type().ID(); id {
case super.IDString:
if val.IsNull() {
Expand Down
2 changes: 2 additions & 0 deletions runtime/sam/expr/fieldnamefinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (f *FieldNameMatcher) Match(typ super.Type) bool {
}
case *super.TypeError:
match = f.Match(typ.Type)
case *super.TypeFusion:
match = f.Match(typ.Type)
}
f.checkedIDs[id] = match
return match
Expand Down
16 changes: 9 additions & 7 deletions runtime/vam/expr/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func NewSearchString(sctx *super.Context, s string, e Evaluator) Evaluator {
}

func (s *search) Eval(this vector.Any) vector.Any {
return vector.Apply(vector.ApplyRipUnions, s.eval, s.e.Eval(this))
return s.applyEval(s.e.Eval(this))
}

func (s *search) applyEval(vec vector.Any) vector.Any {
return vector.Apply(vector.ApplyRipUnions|vector.ApplyRipFusions, s.eval, vec)
}

func (s *search) eval(vecs ...vector.Any) vector.Any {
Expand All @@ -83,7 +87,7 @@ func (s *search) eval(vecs ...vector.Any) vector.Any {
if index != nil {
f = vector.Pick(f, index)
}
if vec2 := s.eval(f); vec2.Kind() != vector.KindNull {
if vec2 := s.applyEval(f); vec2.Kind() != vector.KindNull {
out = vector.Or(out, FlattenBool(vec2))
}
}
Expand All @@ -95,8 +99,6 @@ func (s *search) eval(vecs ...vector.Any) vector.Any {
case *vector.Map:
return vector.Or(s.evalForList(vec.Keys, vec.Offsets, index, n),
s.evalForList(vec.Values, vec.Offsets, index, n))
case *vector.Union:
return vector.Apply(vector.ApplyRipUnions, s.eval, vec)
case *vector.Error:
return s.eval(vec.Vals)
}
Expand All @@ -119,8 +121,8 @@ func (s *search) evalForList(vec vector.Any, offsets, index []uint32, length uin
for k := range n {
index2[k] = k + start
}
view := vector.Pick(vec, index2)
if FlattenBool(s.eval(view)).Bits.TrueCount() > 0 {
vec := s.applyEval(vector.Pick(vec, index2))
if FlattenBool(vec).Bits.TrueCount() > 0 {
out.Set(j)
}
}
Expand Down Expand Up @@ -157,7 +159,7 @@ func NewRegexpMatch(re *regexp.Regexp, e Evaluator) Evaluator {
}

func (r *regexpMatch) Eval(this vector.Any) vector.Any {
return vector.Apply(vector.ApplyRipUnions, r.eval, r.e.Eval(this))
return vector.Apply(vector.ApplyRipUnions|vector.ApplyRipFusions, r.eval, r.e.Eval(this))
}

func (r *regexpMatch) eval(vecs ...vector.Any) vector.Any {
Expand Down
2 changes: 2 additions & 0 deletions runtime/ztests/expr/function/grep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ input: |
{pattern:"z",input:{a:{b:"c"}}}
{pattern:"a",input:"hello"::(string|null)}
{pattern:"a",input:null::(string|null)}
{pattern:"c",input:{a:fusion({b?:"c",d?:_::string},<{b:string}>)}}
{pattern:1,input:""}
{pattern:null,input:"a"}

Expand All @@ -26,5 +27,6 @@ output: |
[true,false]
[true,false]
[true,false]
[true,true]
[error({message:"grep: pattern argument must be a string",on:1}),error({message:"grep: pattern argument must be a string",on:1})]
[error({message:"grep: pattern argument must be a string",on:null}),error({message:"grep: pattern argument must be a string",on:null})]
2 changes: 2 additions & 0 deletions runtime/ztests/expr/regexp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ input: |
"foobazbar"
"xfoobazbar"
"foobazbarx"
fusion("foolbar"::(null|string),<string>)
127.0.0.1
null

Expand All @@ -17,5 +18,6 @@ output: |
true
false
false
true
false
null
2 changes: 2 additions & 0 deletions runtime/ztests/expr/search-glob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ input: |
{a:"foox",b:"there"}
{a:"hello",b:"foox"}
{a:"",b:"foo"}
fusion({a?:_::string,b?:"fool"},<{b:string}>)

output: |
{a:"foox",b:"there"}
{a:"hello",b:"foox"}
{a:"",b:"foo"}
fusion({a?:_::string,b?:"fool"},<{b:string}>)
2 changes: 2 additions & 0 deletions runtime/ztests/expr/search-nested-field-regexp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ input: |
{a:[{bar:"foo"}]}
{a:[{car:"foo"}]}
{a:[{c:"foo"},{b:1}]}
fusion({car:"foo"}::(null|{car:string}),<{car:string}>)
null
{a:[]::[{bar:null}]}
{a:[]::[{b:null}]}

output: |
{a:[{bar:"foo"}]}
{a:[{car:"foo"}]}
fusion({car:"foo"}::(null|{car:string}),<{car:string}>)
{a:[]::[{bar:null}]}
4 changes: 4 additions & 0 deletions runtime/ztests/expr/search-nested-field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ input: |
{a:[{b:"foo"}]}
{a:[{c:"foo"}]}
{a:[{c:"foo"},{b:1}]}
fusion({a:1,b?:_::string},<{a:int64}>)
fusion({a:2,b?:"foo"},<{a:int64,b:string}>)
null
{a:[]::[{b:null}]}
{a:[]::[{c:null}]}

output: |
{a:[{b:"foo"}]}
{a:[{c:"foo"},{b:1}]}
fusion({a:1,b?:_::string},<{a:int64}>)
fusion({a:2,b?:"foo"},<{a:int64,b:string}>)
{a:[]::[{b:null}]}
2 changes: 2 additions & 0 deletions runtime/ztests/expr/search-primitives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ input: |
"foo"
"bar"
"foo"
fusion("foo"::(int64|string),<string>)

output: |
"foo"
"foo"
fusion("foo"::(int64|string),<string>)
13 changes: 11 additions & 2 deletions vector/fusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ func (f *Fusion) Serialize(b *scode.Builder, slot uint32) {
}

func Super(vec Any) Any {
if vec, ok := vec.(*Fusion); ok {
return vec.Values
if vec.Kind() == KindFusion {
var index []uint32
if view, ok := vec.(*View); ok {
index = view.Index
vec = view.Any
}
vals := vec.(*Fusion).Values
if index != nil {
vals = Pick(vals, index)
}
return vals
}
return vec
}
3 changes: 3 additions & 0 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func Walk(typ Type, body scode.Bytes, visit Visitor) error {
return walkMap(typ, body, visit)
case *TypeError:
return Walk(typ.Type, body, visit)
case *TypeFusion:
ftyp, body := typ.DerefFusion(body)
return Walk(ftyp, body, visit)
}
return nil
}
Expand Down
Loading