Skip to content
Open
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
20 changes: 18 additions & 2 deletions runtime/vam/expr/function/upcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,38 @@ func (u *Upcast) toUnion(vec vector.Any, to *super.TypeUnion) vector.Any {
if unionVec, ok := vec.(*vector.Union); ok {
types := map[super.Type]struct{}{}
values := make([]vector.Any, 0, len(to.Types))
var needMerge bool
for _, vec := range unionVec.Values() {
vec = u.toUnionValue(vec, to)
if vec == nil {
return nil
}
types[vec.Type()] = struct{}{}
typ := vec.Type()
if _, ok := types[typ]; !ok {
needMerge = true
}
types[typ] = struct{}{}
values = append(values, vec)
}
tags := unionVec.Tags()
if needMerge {
mergedVec := vbuild.MergeSameTypesInDynamic(vector.NewDynamic(tags, values))
if d, ok := mergedVec.(*vector.Dynamic); ok {
tags, values = d.Tags, d.Values
} else {
tags = make([]uint32, mergedVec.Len())
values = values[:1]
values[0] = mergedVec
}
}
for _, typ := range to.Types {
if _, ok := types[typ]; !ok {
values = append(values, vector.NewEmpty(typ))
}
}
//XXX We should copy RLE instead of making tags when we can.
// This will be addressed in a subsequent PR.
return vector.NewUnion(to, unionVec.Tags(), values)
return vector.NewUnion(to, tags, values)
}
values := u.toUnionValue(vec, to)
if values == nil {
Expand Down
4 changes: 3 additions & 1 deletion runtime/vam/expr/unblend.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ func SlotTypesInList(sctx *super.Context, inner vector.Any, offsets []uint32) []
var alltypes []super.Type
if dynamic != nil {
for _, val := range dynamic.Values {
alltypes = append(alltypes, val.Type())
if val != nil {
alltypes = append(alltypes, val.Type())
}
}
} else {
alltypes = []super.Type{inner.Type()}
Expand Down
10 changes: 10 additions & 0 deletions runtime/ztests/expr/function/defuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ output: *input

spq: fuse | defuse(this)

input: &input |
1::(int64|[int64]|[string])
[2]::(int64|[int64]|[string])

output: *input

---

spq: fuse | defuse(this)

input: &input |
[{a:1}]
[{a:3},{b:3}]
Expand Down
Loading