Skip to content

Commit e3c115d

Browse files
authored
Fix fusion values in search expressions (#7001)
1 parent 0d5feeb commit e3c115d

11 files changed

Lines changed: 40 additions & 10 deletions

File tree

runtime/sam/expr/eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func NewRegexpMatch(re *regexp.Regexp, e Evaluator) *RegexpMatch {
213213
}
214214

215215
func (r *RegexpMatch) Eval(this super.Value) super.Value {
216-
val := r.expr.Eval(this)
216+
val := r.expr.Eval(this).Under()
217217
switch id := val.Type().ID(); id {
218218
case super.IDString:
219219
if val.IsNull() {

runtime/sam/expr/fieldnamefinder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ func (f *FieldNameMatcher) Match(typ super.Type) bool {
9999
}
100100
case *super.TypeError:
101101
match = f.Match(typ.Type)
102+
case *super.TypeFusion:
103+
match = f.Match(typ.Type)
102104
}
103105
f.checkedIDs[id] = match
104106
return match

runtime/vam/expr/search.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func NewSearchString(sctx *super.Context, s string, e Evaluator) Evaluator {
5858
}
5959

6060
func (s *search) Eval(this vector.Any) vector.Any {
61-
return vector.Apply(vector.ApplyRipUnions, s.eval, s.e.Eval(this))
61+
return s.applyEval(s.e.Eval(this))
62+
}
63+
64+
func (s *search) applyEval(vec vector.Any) vector.Any {
65+
return vector.Apply(vector.ApplyRipUnions|vector.ApplyRipFusions, s.eval, vec)
6266
}
6367

6468
func (s *search) eval(vecs ...vector.Any) vector.Any {
@@ -83,7 +87,7 @@ func (s *search) eval(vecs ...vector.Any) vector.Any {
8387
if index != nil {
8488
f = vector.Pick(f, index)
8589
}
86-
if vec2 := s.eval(f); vec2.Kind() != vector.KindNull {
90+
if vec2 := s.applyEval(f); vec2.Kind() != vector.KindNull {
8791
out = vector.Or(out, FlattenBool(vec2))
8892
}
8993
}
@@ -95,8 +99,6 @@ func (s *search) eval(vecs ...vector.Any) vector.Any {
9599
case *vector.Map:
96100
return vector.Or(s.evalForList(vec.Keys, vec.Offsets, index, n),
97101
s.evalForList(vec.Values, vec.Offsets, index, n))
98-
case *vector.Union:
99-
return vector.Apply(vector.ApplyRipUnions, s.eval, vec)
100102
case *vector.Error:
101103
return s.eval(vec.Vals)
102104
}
@@ -119,8 +121,8 @@ func (s *search) evalForList(vec vector.Any, offsets, index []uint32, length uin
119121
for k := range n {
120122
index2[k] = k + start
121123
}
122-
view := vector.Pick(vec, index2)
123-
if FlattenBool(s.eval(view)).Bits.TrueCount() > 0 {
124+
vec := s.applyEval(vector.Pick(vec, index2))
125+
if FlattenBool(vec).Bits.TrueCount() > 0 {
124126
out.Set(j)
125127
}
126128
}
@@ -157,7 +159,7 @@ func NewRegexpMatch(re *regexp.Regexp, e Evaluator) Evaluator {
157159
}
158160

159161
func (r *regexpMatch) Eval(this vector.Any) vector.Any {
160-
return vector.Apply(vector.ApplyRipUnions, r.eval, r.e.Eval(this))
162+
return vector.Apply(vector.ApplyRipUnions|vector.ApplyRipFusions, r.eval, r.e.Eval(this))
161163
}
162164

163165
func (r *regexpMatch) eval(vecs ...vector.Any) vector.Any {

runtime/ztests/expr/function/grep.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ input: |
1414
{pattern:"z",input:{a:{b:"c"}}}
1515
{pattern:"a",input:"hello"::(string|null)}
1616
{pattern:"a",input:null::(string|null)}
17+
{pattern:"c",input:{a:fusion({b?:"c",d?:_::string},<{b:string}>)}}
1718
{pattern:1,input:""}
1819
{pattern:null,input:"a"}
1920
@@ -26,5 +27,6 @@ output: |
2627
[true,false]
2728
[true,false]
2829
[true,false]
30+
[true,true]
2931
[error({message:"grep: pattern argument must be a string",on:1}),error({message:"grep: pattern argument must be a string",on:1})]
3032
[error({message:"grep: pattern argument must be a string",on:null}),error({message:"grep: pattern argument must be a string",on:null})]

runtime/ztests/expr/regexp.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ input: |
77
"foobazbar"
88
"xfoobazbar"
99
"foobazbarx"
10+
fusion("foolbar"::(null|string),<string>)
1011
127.0.0.1
1112
null
1213
@@ -17,5 +18,6 @@ output: |
1718
true
1819
false
1920
false
21+
true
2022
false
2123
null

runtime/ztests/expr/search-glob.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ input: |
55
{a:"foox",b:"there"}
66
{a:"hello",b:"foox"}
77
{a:"",b:"foo"}
8+
fusion({a?:_::string,b?:"fool"},<{b:string}>)
89
910
output: |
1011
{a:"foox",b:"there"}
1112
{a:"hello",b:"foox"}
1213
{a:"",b:"foo"}
14+
fusion({a?:_::string,b?:"fool"},<{b:string}>)

runtime/ztests/expr/search-nested-field-regexp.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ input: |
44
{a:[{bar:"foo"}]}
55
{a:[{car:"foo"}]}
66
{a:[{c:"foo"},{b:1}]}
7+
fusion({car:"foo"}::(null|{car:string}),<{car:string}>)
78
null
89
{a:[]::[{bar:null}]}
910
{a:[]::[{b:null}]}
1011
1112
output: |
1213
{a:[{bar:"foo"}]}
1314
{a:[{car:"foo"}]}
15+
fusion({car:"foo"}::(null|{car:string}),<{car:string}>)
1416
{a:[]::[{bar:null}]}

runtime/ztests/expr/search-nested-field.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ input: |
44
{a:[{b:"foo"}]}
55
{a:[{c:"foo"}]}
66
{a:[{c:"foo"},{b:1}]}
7+
fusion({a:1,b?:_::string},<{a:int64}>)
8+
fusion({a:2,b?:"foo"},<{a:int64,b:string}>)
79
null
810
{a:[]::[{b:null}]}
911
{a:[]::[{c:null}]}
1012
1113
output: |
1214
{a:[{b:"foo"}]}
1315
{a:[{c:"foo"},{b:1}]}
16+
fusion({a:1,b?:_::string},<{a:int64}>)
17+
fusion({a:2,b?:"foo"},<{a:int64,b:string}>)
1418
{a:[]::[{b:null}]}

runtime/ztests/expr/search-primitives.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ input: |
44
"foo"
55
"bar"
66
"foo"
7+
fusion("foo"::(int64|string),<string>)
78
89
output: |
910
"foo"
1011
"foo"
12+
fusion("foo"::(int64|string),<string>)

vector/fusion.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@ func (f *Fusion) Serialize(b *scode.Builder, slot uint32) {
4747
}
4848

4949
func Super(vec Any) Any {
50-
if vec, ok := vec.(*Fusion); ok {
51-
return vec.Values
50+
if vec.Kind() == KindFusion {
51+
var index []uint32
52+
if view, ok := vec.(*View); ok {
53+
index = view.Index
54+
vec = view.Any
55+
}
56+
vals := vec.(*Fusion).Values
57+
if index != nil {
58+
vals = Pick(vals, index)
59+
}
60+
return vals
5261
}
5362
return vec
5463
}

0 commit comments

Comments
 (0)