Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fuzzystrmatch and other external extensions (#2083) #2099

Merged
merged 1 commit into from
Sep 11, 2024
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
29 changes: 29 additions & 0 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -8696,9 +8696,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 @@ -3509,9 +3509,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
Loading