Skip to content

Commit

Permalink
feat(expr): jsonb IS [NOT] NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjinwu committed Mar 1, 2023
1 parent c75863a commit e3bff44
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
24 changes: 13 additions & 11 deletions e2e_test/batch/types/jsonb.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ select jsonb_array_length('null');
statement ok
drop table t;

query TIT
with t(v1) as (
values (null::jsonb), ('null'), ('[true, 4, "foo"]')
) select
v1 is null,
case when jsonb_typeof(v1) = 'array' then jsonb_array_length(v1) end,
coalesce(v1 -> 1, v1, '"?"')
from t;
----
t NULL "?"
f NULL null
f 3 4

# Tests moved from regress tests due to not matching exactly.

# PostgreSQL sorts shorter key "two" before longer key "three"
Expand All @@ -136,14 +149,3 @@ SELECT '{
true}'::jsonb; -- OK
----
{"one": 1, "three": true, "two": "two"}

# We do not support jsonb IS NULL yet.
query TTTT
SELECT
'{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'ff',
'{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'qq',
-- ('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'Y') IS NULL AS f,
('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb ->> 'Y') IS NULL AS t,
'{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'x';
----
{"a": 12, "b": 16} 123 t [1, 2]
1 change: 1 addition & 0 deletions src/expr/src/sig/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fn build_type_derive_map() -> FuncSigMap {
T::Timestamptz,
T::Time,
T::Interval,
T::Jsonb,
];
let num_types = [
T::Int16,
Expand Down
16 changes: 8 additions & 8 deletions src/tests/regress/data/sql/jsonb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ SELECT test_json ->> 2 FROM test_jsonb WHERE json_type = 'object';
--@ SELECT jsonb_object_keys(test_json) FROM test_jsonb WHERE json_type = 'object';

-- nulls
--@ SELECT (test_json->'field3') IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'object';
SELECT (test_json->'field3') IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'object';
SELECT (test_json->>'field3') IS NULL AS expect_true FROM test_jsonb WHERE json_type = 'object';
--@ SELECT (test_json->3) IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'array';
SELECT (test_json->3) IS NULL AS expect_false FROM test_jsonb WHERE json_type = 'array';
SELECT (test_json->>3) IS NULL AS expect_true FROM test_jsonb WHERE json_type = 'array';

DROP TABLE test_jsonb;
Expand Down Expand Up @@ -933,12 +933,12 @@ SELECT '{"aa":["a","aaa"],"qq":{"a":"12","b":"16","c":["c1","c2"],"d":{"d1":"d1"
SELECT '{"aa":["a","aaa"],"qq":{"a":"12","b":"16","c":["c1","c2",["c3"],{"c4":4}],"d":{"d1":"d1","d2":"d2"}}}'::jsonb;
SELECT '{"ff":["a","aaa"]}'::jsonb;

--@ SELECT
--@ '{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'ff',
--@ '{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'qq',
--@ ('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'Y') IS NULL AS f,
--@ ('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb ->> 'Y') IS NULL AS t,
--@ '{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'x';
SELECT
'{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'ff',
'{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'qq',
('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'Y') IS NULL AS f,
('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb ->> 'Y') IS NULL AS t,
'{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}'::jsonb -> 'x';

-- nested containment
--@ SELECT '{"a":[1,2],"c":"b"}'::jsonb @> '{"a":[1,2]}';
Expand Down

0 comments on commit e3bff44

Please sign in to comment.