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
11 changes: 9 additions & 2 deletions runtime/sam/expr/agg/fuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (f *Fuser) fuse(a, b super.Type) super.Type {
// First change all fields to optional that are in "a" but not in "b".
for k, field := range fields {
if _, ok := indexOfField(b.Fields, field.Name); !ok {
fields[k].Type = f.sctx.Option(fields[k].Type)
fields[k].Type = f.makeOption(fields[k].Type)
}
}
// Now fuse all the fields in "b" that are also in "a" and add the fields
Expand All @@ -70,7 +70,7 @@ func (f *Fuser) fuse(a, b super.Type) super.Type {
if ok {
fields[i].Type = f.fuse(fields[i].Type, field.Type)
} else {
typ := f.sctx.Option(field.Type)
typ := f.makeOption(field.Type)
fields = append(fields, super.NewField(field.Name, typ))
}
}
Expand Down Expand Up @@ -144,6 +144,13 @@ func (f *Fuser) fuse(a, b super.Type) super.Type {
return f.fusion(union)
}

func (f *Fuser) makeOption(t super.Type) super.Type {
if fusion, ok := t.(*super.TypeFusion); ok {
return f.sctx.LookupTypeFusion(f.makeOption(fusion.Type))
}
return f.sctx.Option(t)
}

func isAll(t super.Type) bool {
_, ok := t.(*super.TypeOfAll)
return ok
Expand Down
11 changes: 11 additions & 0 deletions runtime/ztests/expr/fuser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ input: &input |
[{id:1,s:"foo"},{id:2,s:null}]

output: *input

---

spq: fuse | defuse(this)

input: &input |
{x:1,y:{z:"foo"}}
{x:2,y:{z:"bar",w:true}}
{x:3}

output: *input
Loading