Skip to content

Commit

Permalink
Add exist(?, ?|, ?&) operators for agtype
Browse files Browse the repository at this point in the history
- Added exist(?, ?|, ?&) operators for agtype similar to jsonb operators
  in postgresql.
- Allow exist(?, ?|, ?&) operators to be used inside cypher queries.
- Added regression tests.
  • Loading branch information
MuhammadTahaNaveed committed Sep 8, 2023
1 parent b28d06a commit d7a40ff
Show file tree
Hide file tree
Showing 13 changed files with 1,676 additions and 124 deletions.
55 changes: 52 additions & 3 deletions age--1.4.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2980,6 +2980,23 @@ CREATE OPERATOR ? (
JOIN = contjoinsel
);

CREATE FUNCTION ag_catalog.agtype_exists_agtype(agtype, agtype)
RETURNS boolean
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE OPERATOR ? (
LEFTARG = agtype,
RIGHTARG = agtype,
FUNCTION = ag_catalog.agtype_exists_agtype,
COMMUTATOR = '?',
RESTRICT = contsel,
JOIN = contjoinsel
);

CREATE FUNCTION ag_catalog.agtype_exists_any(agtype, text[])
RETURNS boolean
LANGUAGE c
Expand All @@ -2996,6 +3013,22 @@ CREATE OPERATOR ?| (
JOIN = contjoinsel
);

CREATE FUNCTION ag_catalog.agtype_exists_any_agtype(agtype, agtype)
RETURNS boolean
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE OPERATOR ?| (
LEFTARG = agtype,
RIGHTARG = agtype,
FUNCTION = ag_catalog.agtype_exists_any_agtype,
RESTRICT = contsel,
JOIN = contjoinsel
);

CREATE FUNCTION ag_catalog.agtype_exists_all(agtype, text[])
RETURNS boolean
LANGUAGE c
Expand All @@ -3012,6 +3045,22 @@ CREATE OPERATOR ?& (
JOIN = contjoinsel
);

CREATE FUNCTION ag_catalog.agtype_exists_all_agtype(agtype, agtype)
RETURNS boolean
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE OPERATOR ?& (
LEFTARG = agtype,
RIGHTARG = agtype,
FUNCTION = ag_catalog.agtype_exists_all_agtype,
RESTRICT = contsel,
JOIN = contjoinsel
);

--
-- agtype GIN support
--
Expand Down Expand Up @@ -3061,9 +3110,9 @@ PARALLEL SAFE;
CREATE OPERATOR CLASS ag_catalog.gin_agtype_ops
DEFAULT FOR TYPE agtype USING gin AS
OPERATOR 7 @>,
OPERATOR 9 ?(agtype, text),
OPERATOR 10 ?|(agtype, text[]),
OPERATOR 11 ?&(agtype, text[]),
OPERATOR 9 ?(agtype, agtype),
OPERATOR 10 ?|(agtype, agtype),
OPERATOR 11 ?&(agtype, agtype),
FUNCTION 1 ag_catalog.gin_compare_agtype(text,text),
FUNCTION 2 ag_catalog.gin_extract_agtype(agtype, internal),
FUNCTION 3 ag_catalog.gin_extract_agtype_query(agtype, internal, int2,
Expand Down
72 changes: 0 additions & 72 deletions regress/expected/agtype.out
Original file line number Diff line number Diff line change
Expand Up @@ -2762,78 +2762,6 @@ SELECT '{"id": 1}'::agtype @> '{"id": 2}';
f
(1 row)

SELECT agtype_exists('{"id": 1}','id');
agtype_exists
---------------
t
(1 row)

SELECT agtype_exists('{"id": 1}','not_id');
agtype_exists
---------------
f
(1 row)

SELECT '{"id": 1}'::agtype ? 'id';
?column?
----------
t
(1 row)

SELECT '{"id": 1}'::agtype ? 'not_id';
?column?
----------
f
(1 row)

SELECT agtype_exists_any('{"id": 1}', array['id']);
agtype_exists_any
-------------------
t
(1 row)

SELECT agtype_exists_any('{"id": 1}', array['not_id']);
agtype_exists_any
-------------------
f
(1 row)

SELECT '{"id": 1}'::agtype ?| array['id'];
?column?
----------
t
(1 row)

SELECT '{"id": 1}'::agtype ?| array['not_id'];
?column?
----------
f
(1 row)

SELECT agtype_exists_all('{"id": 1}', array['id']);
agtype_exists_all
-------------------
t
(1 row)

SELECT agtype_exists_all('{"id": 1}', array['not_id']);
agtype_exists_all
-------------------
f
(1 row)

SELECT '{"id": 1}'::agtype ?& array['id'];
?column?
----------
t
(1 row)

SELECT '{"id": 1}'::agtype ?& array['not_id'];
?column?
----------
f
(1 row)

--
-- Test STARTS WITH, ENDS WITH, and CONTAINS
--
Expand Down
Loading

0 comments on commit d7a40ff

Please sign in to comment.