-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement vector put operator (#5280)
Unlike the sequence put operator, this does not yet support dynamic field names (e.g., "put this[a] := 1") because it is implemented in terms of record expressions.
- Loading branch information
Showing
19 changed files
with
110 additions
and
2 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 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,30 @@ | ||
package expr | ||
|
||
import ( | ||
"github.com/brimdata/zed" | ||
"github.com/brimdata/zed/vector" | ||
) | ||
|
||
// Putter adapts the behavior of recordExpr (obtained from NewRecordExpr) to | ||
// match that of the put operator, which emits an error when an input value is | ||
// not a record. | ||
type Putter struct { | ||
zctx *zed.Context | ||
recordExpr Evaluator | ||
} | ||
|
||
func NewPutter(zctx *zed.Context, recordExpr Evaluator) *Putter { | ||
return &Putter{zctx, recordExpr} | ||
} | ||
|
||
func (p *Putter) Eval(vec vector.Any) vector.Any { | ||
return vector.Apply(false, p.eval, vec) | ||
} | ||
|
||
func (p *Putter) eval(vecs ...vector.Any) vector.Any { | ||
vec := vecs[0] | ||
if vec.Type().Kind() != zed.RecordKind { | ||
return vector.NewWrappedError(p.zctx, "put: not a record", vec) | ||
} | ||
return p.recordExpr.Eval(vec) | ||
} |
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-1.yaml → runtime/ztests/op/put-1.yaml
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
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-2.yaml → runtime/ztests/op/put-2.yaml
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
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-3.yaml → runtime/ztests/op/put-3.yaml
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Tests writing a new record | ||
zed: put r2 := r | ||
|
||
vector: true | ||
|
||
input: | | ||
{r:{s:"hello"}} | ||
{r:{s:"world"}} | ||
|
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-4.yaml → runtime/ztests/op/put-4.yaml
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
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-5.yaml → runtime/ztests/op/put-5.yaml
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
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-implied-1.yaml → runtime/ztests/op/put-implied-1.yaml
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
zed: y := x + 1 | ||
|
||
vector: true | ||
|
||
input: | | ||
{x:1(int32)} | ||
{x:2(int32)} | ||
|
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-implied-2.yaml → runtime/ztests/op/put-implied-2.yaml
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
zed: 'x:=upper(x), y:=lower(x)' | ||
|
||
vector: true | ||
|
||
input: | | ||
{x:"vAlUe1"} | ||
|
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-multi-1.yaml → runtime/ztests/op/put-multi-1.yaml
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Tests multiple output expressions | ||
zed: put a:=1, b:=2 | ||
|
||
vector: true | ||
|
||
input: | | ||
{x:1(int32)} | ||
{x:2(int32)} | ||
|
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-multi-2.yaml → runtime/ztests/op/put-multi-2.yaml
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
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-multi-3.yaml → runtime/ztests/op/put-multi-3.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# creates a new field | ||
zed: put new:=1, x:=x+1 | ||
|
||
vector: true | ||
|
||
input: | | ||
{x:1(int32)} | ||
{x:2(int32)} | ||
|
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,9 @@ | ||
zed: put a:=1 | ||
|
||
vector: true | ||
|
||
input: | | ||
0 | ||
output: | | ||
error({message:"put: not a record",on:0}) |
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-null.yaml → runtime/ztests/op/put-null.yaml
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
zed: put b:=null | ||
|
||
vector: true | ||
|
||
input: | | ||
{a:1(int32)} | ||
|
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
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-overwrite-321.yaml → runtime/ztests/op/put-overwrite-321.yaml
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
zed: put a:=3,b:=2,c:=1 | ||
|
||
vector: true | ||
|
||
input: | | ||
{a:1(int32),b:2(int32)} | ||
|
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/ztests/put-root.yaml → runtime/ztests/op/put-root.yaml
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
zed: yield a | ||
|
||
vector: true | ||
|
||
input: | | ||
{"a": {"a": "a", "b": "b"}, "b": "b"} | ||
|