-
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
111 additions
and
19 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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.Vals.Type().(*zed.TypeOfString); !ok { | ||
return args[0] | ||
} | ||
if c, ok := arg.Vals.(*vector.Const); ok { | ||
// Fast path | ||
if s, _ := c.AsString(); s == "missing" { | ||
return vector.NewStringError(q.zctx, "quiet", c.Len()) | ||
} | ||
return args[0] | ||
} | ||
n := arg.Len() | ||
vec := vector.NewStringEmpty(n, vector.NewBoolEmpty(n, nil)) | ||
for i := uint32(0); i < n; i++ { | ||
s, null := vector.StringValue(arg.Vals, i) | ||
if null { | ||
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,23 @@ | ||
zed: quiet(this) | ||
|
||
vector: true | ||
|
||
input: | | ||
1 | ||
[3,2,1,0] | ||
error("missing") | ||
error("missing")(=foo) | ||
error("missing"(=bar)) | ||
null(error(string)) | ||
error(null(string)) | ||
error("quiet") | ||
error({x:"missing"}) | ||
output: | | ||
1 | ||
[3,2,1,0] | ||
error("missing")(=foo) | ||
error("missing")(error(bar=string)) | ||
null(error(string)) | ||
null(error(string)) | ||
error({x:"missing"}) |
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