-
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.
This commit add the quiet function and support for error("quiet") in the yield operator. Quiet errors are not supported elsewhere including cut and put.
- Loading branch information
Showing
7 changed files
with
116 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package function | ||
|
||
import ( | ||
"github.com/brimdata/zed" | ||
"github.com/brimdata/zed/vector" | ||
) | ||
|
||
// https://github.com/brimdata/zed/blob/main/docs/language/functions.md#quiet | ||
type Quiet struct { | ||
zctx *zed.Context | ||
} | ||
|
||
func (q *Quiet) Call(args ...vector.Any) vector.Any { | ||
arg, ok := args[0].(*vector.Error) | ||
if !ok { | ||
return args[0] | ||
} | ||
if _, ok := arg.Typ.Type.(*zed.TypeOfString); !ok { | ||
return args[0] | ||
} | ||
n := arg.Len() | ||
vec := vector.NewStringEmpty(n, vector.NewBoolEmpty(n, nil)) | ||
for i := uint32(0); i < n; i++ { | ||
s, isnull := vector.StringValue(arg.Vals, i) | ||
if isnull { | ||
vec.Nulls.Set(i) | ||
} | ||
if s == "missing" { | ||
s = "quiet" | ||
} | ||
vec.Append(s) | ||
} | ||
return vector.NewError(arg.Typ, vec, arg.Nulls) | ||
} |
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,19 @@ | ||
zed: quiet(this) | ||
|
||
vector: true | ||
|
||
input: | | ||
error("missing") | ||
error("missing")(=foo) | ||
error("missing"(=bar)) | ||
null(error(string)) | ||
error(null(string)) | ||
error("quiet") | ||
error({x:"missing"}) | ||
output: | | ||
error("missing")(=foo) | ||
error("missing")(error(bar=string)) | ||
null(error(string)) | ||
null(error(string)) | ||
error({x:"missing"}) |
2 changes: 2 additions & 0 deletions
2
runtime/sam/op/yield/ztests/quiet.yaml → runtime/ztests/op/yield-quiet.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 quiet(a) | ||
|
||
vector: true | ||
|
||
input: | | ||
{a:1} | ||
{b:1} | ||
|
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