-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ input: | | |
output: | | ||
[2,3,0,1] | ||
|[0,1,2,3]| | ||
[1,2] | ||
|[1,2]| | ||
[1,2,"hi"] | ||
|[1,2,"hi"]| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package expr | ||
|
||
import ( | ||
"github.com/brimdata/super" | ||
"github.com/brimdata/super/vector" | ||
) | ||
|
||
type VectorElem struct { | ||
Value Evaluator | ||
Spread Evaluator | ||
} | ||
|
||
type ArrayExpr struct { | ||
elems []VectorElem | ||
zctx *super.Context | ||
} | ||
|
||
func NewArrayExpr(zctx *super.Context, elems []VectorElem) *ArrayExpr { | ||
return &ArrayExpr{ | ||
elems: elems, | ||
zctx: zctx, | ||
} | ||
} | ||
|
||
func (a *ArrayExpr) Eval(this vector.Any) vector.Any { | ||
var vecs []vector.Any | ||
for _, e := range a.elems { | ||
if e.Spread != nil { | ||
vecs = append(vecs, e.Spread.Eval(this)) | ||
} else { | ||
vecs = append(vecs, e.Value.Eval(this)) | ||
} | ||
} | ||
return vector.Apply(false, a.eval, vecs...) | ||
} | ||
|
||
func (a *ArrayExpr) eval(vecs ...vector.Any) vector.Any { | ||
n := vecs[0].Len() | ||
if n == 0 { | ||
return vector.NewConst(super.Null, 0, nil) | ||
} | ||
spreadOffs := make([][]uint32, len(a.elems)) | ||
viewIndexes := make([][]uint32, len(a.elems)) | ||
for i, elem := range a.elems { | ||
if elem.Spread != nil { | ||
vecs[i], spreadOffs[i], viewIndexes[i] = a.unwrapSpread(vecs[i]) | ||
} | ||
} | ||
offsets := []uint32{0} | ||
var tags []uint32 | ||
for i := range n { | ||
var size uint32 | ||
for tag, spreadOff := range spreadOffs { | ||
if len(spreadOff) == 0 { | ||
tags = append(tags, uint32(tag)) | ||
size++ | ||
continue | ||
} else { | ||
if index := viewIndexes[tag]; index != nil { | ||
i = index[i] | ||
} | ||
off := spreadOff[i] | ||
for end := spreadOff[i+1]; off < end; off++ { | ||
tags = append(tags, uint32(tag)) | ||
size++ | ||
} | ||
} | ||
} | ||
offsets = append(offsets, offsets[i]+size) | ||
} | ||
var typ super.Type | ||
var innerVals vector.Any | ||
if len(vecs) == 1 { | ||
typ = vecs[0].Type() | ||
innerVals = vecs[0] | ||
} else { | ||
var all []super.Type | ||
for _, vec := range vecs { | ||
all = append(all, vec.Type()) | ||
} | ||
types := super.UniqueTypes(all) | ||
if len(types) == 1 { | ||
typ = types[0] | ||
innerVals = vector.NewDynamic(tags, vecs) | ||
} else { | ||
typ = a.zctx.LookupTypeUnion(types) | ||
innerVals = vector.NewUnion(typ.(*super.TypeUnion), tags, vecs, nil) | ||
} | ||
} | ||
return vector.NewArray(a.zctx.LookupTypeArray(typ), offsets, innerVals, nil) | ||
} | ||
|
||
func (a *ArrayExpr) unwrapSpread(vec vector.Any) (vector.Any, []uint32, []uint32) { | ||
switch vec := vec.(type) { | ||
case *vector.Array: | ||
return vec.Values, vec.Offsets, nil | ||
case *vector.Set: | ||
return vec.Values, vec.Offsets, nil | ||
case *vector.View: | ||
vals, offsets, _ := a.unwrapSpread(vec.Any) | ||
return vals, offsets, vec.Index | ||
} | ||
return vec, nil, nil | ||
} | ||
|
||
func viewOfOffsets(index []uint32, offsets []uint32) []uint32 { | ||
var out []uint32 | ||
for _, i := range index { | ||
out = append(out, offsets[i], offsets[i+1]) | ||
} | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
zed: yield [...a,...b] | ||
|
||
vector: true | ||
|
||
input: | | ||
{a:|[1,2]|,b:[0,1],c:"hi"} | ||
{a:[1,2],b:"hi"} | ||
output: | | ||
[1,2,0,1] | ||
[1,2,"hi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters