mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
Make is_null/is_not_null DSL functions include new JSON-null type (#883)
* Make is_null/is_not_null DSL functions include new JSON-null type * regression-test files
This commit is contained in:
parent
eb7e29d207
commit
4fb0b716ba
7 changed files with 86 additions and 4 deletions
|
|
@ -194,10 +194,10 @@ func BIF_is_notarray(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
|||
return mlrval.FromBool(!input1.IsArray())
|
||||
}
|
||||
func BIF_is_notnull(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromBool(!input1.IsAbsent() && !input1.IsVoid())
|
||||
return mlrval.FromBool(!input1.IsAbsent() && !input1.IsVoid() && !input1.IsNull())
|
||||
}
|
||||
func BIF_is_null(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromBool(input1.IsAbsent() || input1.IsVoid())
|
||||
return mlrval.FromBool(input1.IsAbsent() || input1.IsVoid() || input1.IsNull())
|
||||
}
|
||||
func BIF_is_numeric(input1 *mlrval.Mlrval) *mlrval.Mlrval {
|
||||
return mlrval.FromBool(input1.IsInt() || input1.IsFloat())
|
||||
|
|
|
|||
|
|
@ -1203,14 +1203,14 @@ strftime_local.`,
|
|||
{
|
||||
name: "is_not_null",
|
||||
class: FUNC_CLASS_TYPING,
|
||||
help: "False if argument is null (empty or absent), true otherwise.",
|
||||
help: "False if argument is null (empty, absent, or JSON null), true otherwise.",
|
||||
unaryFunc: bifs.BIF_is_notnull,
|
||||
},
|
||||
|
||||
{
|
||||
name: "is_null",
|
||||
class: FUNC_CLASS_TYPING,
|
||||
help: "True if argument is null (empty or absent), false otherwise.",
|
||||
help: "True if argument is null (empty, absent, or JSON null), false otherwise.",
|
||||
unaryFunc: bifs.BIF_is_null,
|
||||
},
|
||||
|
||||
|
|
|
|||
1
test/cases/dsl-is-predicates/0098j/cmd
Normal file
1
test/cases/dsl-is-predicates/0098j/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --json put -f ${CASEDIR}/mlr test/input/nullvals.json
|
||||
0
test/cases/dsl-is-predicates/0098j/experr
Normal file
0
test/cases/dsl-is-predicates/0098j/experr
Normal file
43
test/cases/dsl-is-predicates/0098j/expout
Normal file
43
test/cases/dsl-is-predicates/0098j/expout
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
[
|
||||
{
|
||||
"a": "r",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"z": "",
|
||||
"f": true
|
||||
},
|
||||
{
|
||||
"a": "s",
|
||||
"x": 3,
|
||||
"y": 4,
|
||||
"z": "",
|
||||
"f": true
|
||||
},
|
||||
{
|
||||
"a": "t",
|
||||
"x": 5,
|
||||
"y": "",
|
||||
"z": "",
|
||||
"f": true
|
||||
},
|
||||
{
|
||||
"a": "u",
|
||||
"x": "",
|
||||
"y": 6,
|
||||
"f": true
|
||||
},
|
||||
{
|
||||
"a": "v",
|
||||
"x": "",
|
||||
"y": "",
|
||||
"z": "null",
|
||||
"f": false
|
||||
},
|
||||
{
|
||||
"a": "v",
|
||||
"x": "",
|
||||
"y": "",
|
||||
"z": null,
|
||||
"f": true
|
||||
}
|
||||
]
|
||||
1
test/cases/dsl-is-predicates/0098j/mlr
Normal file
1
test/cases/dsl-is-predicates/0098j/mlr
Normal file
|
|
@ -0,0 +1 @@
|
|||
$f=is_null($z)
|
||||
37
test/input/nullvals.json
Normal file
37
test/input/nullvals.json
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
[
|
||||
{
|
||||
"a": "r",
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"z": ""
|
||||
},
|
||||
{
|
||||
"a": "s",
|
||||
"x": 3,
|
||||
"y": 4,
|
||||
"z": ""
|
||||
},
|
||||
{
|
||||
"a": "t",
|
||||
"x": 5,
|
||||
"y": "",
|
||||
"z": ""
|
||||
},
|
||||
{
|
||||
"a": "u",
|
||||
"x": "",
|
||||
"y": 6
|
||||
},
|
||||
{
|
||||
"a": "v",
|
||||
"x": "",
|
||||
"y": "",
|
||||
"z": "null"
|
||||
},
|
||||
{
|
||||
"a": "v",
|
||||
"x": "",
|
||||
"y": "",
|
||||
"z": null
|
||||
}
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue