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
4 changes: 2 additions & 2 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@
- [error](super-sql/functions/errors/error.md)
- [has_error](super-sql/functions/errors/has_error.md)
- [is_error](super-sql/functions/errors/is_error.md)
- [missing](super-sql/functions/errors/missing.md)
- [Generics](super-sql/functions/generics/intro.md)
- [coalesce](super-sql/functions/generics/coalesce.md)
- [compare](super-sql/functions/generics/compare.md)
- [has](super-sql/functions/generics/has.md)
- [is_ok](super-sql/functions/generics/is_ok.md)
- [len](super-sql/functions/generics/len.md)
- [map](super-sql/functions/generics/map.md)
- [nullif](super-sql/functions/generics/nullif.md)
- [ok](super-sql/functions/generics/ok.md)
- [under](super-sql/functions/generics/under.md)
- [Math](super-sql/functions/math/intro.md)
- [abs](super-sql/functions/math/abs.md)
Expand Down
4 changes: 2 additions & 2 deletions book/src/command/super.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ This can be especially handy when you are learning the language and its

For example, this query
```mdtest-command
super -C -c 'has(foo)'
super -C -c 'is_ok(foo)'
```
is an implied [where](../super-sql/operators/where.md) operator, which matches values
that have a field `foo`, i.e.,
```mdtest-output
where has(foo)
where is_ok(foo)
```
while this query
```mdtest-command
Expand Down
7 changes: 3 additions & 4 deletions book/src/super-sql/expressions/comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ _Various scalar comparisons_

```mdtest-spq
# spq
values 1 > 2, 1 < 2, "b" > "a", 1 > "a", 1 > error("missing")
values 1 > 2, 1 < 2, "b" > "a", 1 > "a"
# input

# expected output
false
true
true
false
error("missing")
```

---
Expand All @@ -104,12 +103,12 @@ values {isNull:this is null,isNotNull:this is not null}
1
null
2
error("missing")
none
# expected output
{isNull:false,isNotNull:true}
{isNull:true,isNotNull:false}
{isNull:false,isNotNull:true}
{isNull:error("missing"),isNotNull:error("missing")}
{isNull:false,isNotNull:true}
```

---
Expand Down
15 changes: 0 additions & 15 deletions book/src/super-sql/functions/errors/error.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,3 @@ error("exception")
{that:error("exception"),err:true,kind:"error"}
{that:"exception",err:false,kind:"primitive"}
```

---

_Comparison of a missing error results in a missing error even if they
are the same missing errors so as to not allow field comparisons of two
missing fields to succeed_

```mdtest-spq
# spq
badfield:=x | values badfield==error("missing")
# input
{}
# expected output
error("missing")
```
84 changes: 0 additions & 84 deletions book/src/super-sql/functions/errors/missing.md

This file was deleted.

96 changes: 0 additions & 96 deletions book/src/super-sql/functions/generics/has.md

This file was deleted.

85 changes: 85 additions & 0 deletions book/src/super-sql/functions/generics/is_ok.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# is_ok

test the validity of values

## Synopsis

```
is_ok(val: any) -> bool
```

## Description

The `is_ok` function is inspired by the Rust language pattern of the same name
and returns true when `val` is not `none` or an error.
It is a shortcut for `ok(val)!=none`.

This function is often used to determine the existence of fields in a
record, e.g., `is_ok(x)` is true when `this` is a record and has
the field `x`, provided its value is not an error or none.

It's also useful in shaping messy data when applying conditional logic based on the
presence of certain fields:
```
switch
case a.is_ok() ( ... )
case b.is_ok() ( ... )
default ( ... )
```

## Examples

---

```mdtest-spq
# spq
values {yes:is_ok(foo),no:is_ok(bar)}
# input
{foo:10}
# expected output
{yes:true,no:false}
```

---

```mdtest-spq
# spq
values {yes: foo[1].is_ok(),no:foo[4].is_ok()}
# input
{foo:[1,2,3]}
# expected output
{yes:true,no:false}
```

---

```mdtest-spq
# spq
values {yes:foo.bar.is_ok(),no:foo.baz.is_ok()}
# input
{foo:{bar:"value"}}
# expected output
{yes:true,no:false}
```

---

```mdtest-spq
# spq
values {yes:is_ok(foo+1),no:is_ok(bar+1)}
# input
{foo:10}
# expected output
{yes:true,no:false}
```

---

```mdtest-spq
# spq
values bar.is_ok()
# input
1
# expected output
false
```
Loading
Loading