Skip to content

Commit

Permalink
map: Fix bug with result container type (#4860)
Browse files Browse the repository at this point in the history
Fix bug in map where the result container type was getting set
of the incorrect value.

Closes #4855
  • Loading branch information
mattnibs authored Nov 5, 2023
1 parent 5ef508c commit 07893a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions runtime/expr/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ func NewMapCall(zctx *zed.Context, e, inner Evaluator) Evaluator {
}

func (a *mapCall) Eval(ectx Context, in *zed.Value) *zed.Value {
v := a.eval.Eval(ectx, in)
if v.IsError() {
return v
val := a.eval.Eval(ectx, in)
if val.IsError() {
return val
}
elems, err := v.Elements()
elems, err := val.Elements()
if err != nil {
return ectx.CopyValue(*a.zctx.WrapError(err.Error(), in))
}
if len(elems) == 0 {
return v
return val
}
a.vals = a.vals[:0]
a.types = a.types[:0]
Expand All @@ -42,7 +42,7 @@ func (a *mapCall) Eval(ectx Context, in *zed.Value) *zed.Value {
}
inner := a.innerType(a.types)
bytes := a.buildVal(inner, a.vals)
if _, ok := zed.TypeUnder(in.Type).(*zed.TypeSet); ok {
if _, ok := zed.TypeUnder(val.Type).(*zed.TypeSet); ok {
return ectx.NewValue(a.zctx.LookupTypeSet(inner), zed.NormalizeSet(bytes))
}
return ectx.NewValue(a.zctx.LookupTypeArray(inner), bytes)
Expand Down
2 changes: 2 additions & 0 deletions runtime/expr/ztests/map.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
script: |
echo '{a:["foo","bar","baz"]}' | zq -z 'a := map(a,upper)' -
echo '{a:|["foo","bar","baz"]|}' | zq -z 'a := map(a,upper)' -
echo '["1","2","3"]' | zq -z 'yield map(this,int64)' -
echo '[1,2,3]' | zq -z -I udf.zed -
Expand All @@ -13,5 +14,6 @@ outputs:
- name: stdout
data: |
{a:["FOO","BAR","BAZ"]}
{a:|["BAR","BAZ","FOO"]|}
[1,2,3]
["1","2","3"]

0 comments on commit 07893a2

Please sign in to comment.