Skip to content

Commit

Permalink
Add support for fuzzystrmatch and other external extensions
Browse files Browse the repository at this point in the history
Added support for the fuzzystrmatch extension and for other
external extensions.

Added support for typecasting `::pg_text` to TEXTOID.

Added regression tests.

   modified:   sql/agtype_coercions.sql
   modified:   src/backend/parser/cypher_expr.c
   modified:   src/backend/utils/adt/agtype.c
   modified:   regress/expected/expr.out
   modified:   regress/sql/expr.sql
  • Loading branch information
jrgemignani committed Aug 30, 2024
1 parent 9c0960e commit aff719d
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 9 deletions.
29 changes: 29 additions & 0 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -8767,9 +8767,38 @@ SELECT * FROM cypher('issue_1988', $$
{"id": 844424930131969, "label": "Part", "properties": {"set": "set", "match": "match", "merge": "merge", "create": "create", "delete": "delete", "part_num": 123}}::vertex
(4 rows)

--
-- Test external extension function logic for fuzzystrmatch
--
SELECT * FROM create_graph('fuzzystrmatch');
NOTICE: graph "fuzzystrmatch" has been created
create_graph
--------------

(1 row)

-- These should fail with extension not installed
SELECT * FROM cypher('fuzzystrmatch', $$ RETURN soundex("hello world!") $$) AS (result agtype);
ERROR: extension fuzzystrmatch is not installed for function soundex
LINE 1: SELECT * FROM cypher('fuzzystrmatch', $$ RETURN soundex("hel...
^
SELECT * FROM cypher('fuzzystrmatch', $$ RETURN difference("hello world!", "hello world!") $$) AS (result agtype);
ERROR: extension fuzzystrmatch is not installed for function difference
LINE 1: SELECT * FROM cypher('fuzzystrmatch', $$ RETURN difference("...
^
--
-- Cleanup
--
SELECT * FROM drop_graph('fuzzystrmatch', true);
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table fuzzystrmatch._ag_label_vertex
drop cascades to table fuzzystrmatch._ag_label_edge
NOTICE: graph "fuzzystrmatch" has been dropped
drop_graph
------------

(1 row)

SELECT * FROM drop_graph('issue_1988', true);
NOTICE: drop cascades to 4 other objects
DETAIL: drop cascades to table issue_1988._ag_label_vertex
Expand Down
9 changes: 9 additions & 0 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3536,9 +3536,18 @@ SELECT * FROM cypher('issue_1988', $$
SELECT * FROM cypher('issue_1988', $$
MATCH (p) RETURN p $$) as (p agtype);

--
-- Test external extension function logic for fuzzystrmatch
--
SELECT * FROM create_graph('fuzzystrmatch');
-- These should fail with extension not installed
SELECT * FROM cypher('fuzzystrmatch', $$ RETURN soundex("hello world!") $$) AS (result agtype);
SELECT * FROM cypher('fuzzystrmatch', $$ RETURN difference("hello world!", "hello world!") $$) AS (result agtype);

--
-- Cleanup
--
SELECT * FROM drop_graph('fuzzystrmatch', true);
SELECT * FROM drop_graph('issue_1988', true);
SELECT * FROM drop_graph('issue_1953', true);
SELECT * FROM drop_graph('expanded_map', true);
Expand Down
25 changes: 23 additions & 2 deletions sql/agtype_coercions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ AS 'MODULE_PATHNAME';
CREATE CAST (agtype AS text)
WITH FUNCTION ag_catalog.agtype_to_text(agtype);

-- text -> agtype
CREATE FUNCTION ag_catalog.text_to_agtype(text)
RETURNS agtype
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

-- agtype -> boolean (implicit)
CREATE FUNCTION ag_catalog.agtype_to_bool(agtype)
RETURNS boolean
Expand Down Expand Up @@ -69,7 +78,7 @@ AS 'MODULE_PATHNAME';
CREATE CAST (float8 AS agtype)
WITH FUNCTION ag_catalog.float8_to_agtype(float8);

-- agtype -> float8 (implicit)
-- agtype -> float8 (exmplicit)
CREATE FUNCTION ag_catalog.agtype_to_float8(agtype)
RETURNS float8
LANGUAGE c
Expand Down Expand Up @@ -106,6 +115,18 @@ CREATE CAST (agtype AS bigint)
WITH FUNCTION ag_catalog.agtype_to_int8(variadic "any")
AS ASSIGNMENT;

-- int4 -> agtype (explicit)
CREATE FUNCTION ag_catalog.int4_to_agtype(int4)
RETURNS agtype
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE CAST (int4 AS agtype)
WITH FUNCTION ag_catalog.int4_to_agtype(int4);

-- agtype -> int4
CREATE FUNCTION ag_catalog.agtype_to_int4(variadic "any")
RETURNS int
Expand Down Expand Up @@ -151,4 +172,4 @@ PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE CAST (agtype AS json)
WITH FUNCTION ag_catalog.agtype_to_json(agtype);
WITH FUNCTION ag_catalog.agtype_to_json(agtype);
Loading

0 comments on commit aff719d

Please sign in to comment.