8000 Fix issue #1302 - crash on NULL input to UNWIND by MuhammadTahaNaveed · Pull Request #1304 · apache/age · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Fix issue #1302 - crash on NULL input to UNWIND #1304

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

Merged
merged 1 commit into from
Oct 26, 2023
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
69 changes: 69 additions & 0 deletions regress/expected/cypher_unwind.out
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,65 @@ $$) as (i agtype);
{"id": 281474976710659, "label": "", "properties": {"a": [7, 8, 9], "name": "node3", "type": "vertex"}}::vertex
(3 rows)

--
-- Issue 1302
--
SELECT create_graph('issue_1302');
NOTICE: graph "issue_1302" has been created
create_graph
--------------

(1 row)

SELECT * FROM cypher('cypher_unwind', $$
CREATE (agtype {name: 'node1', a: [1, 2, 3]}),
(m {name: 'node2', a: [4, 5, 6]}),
(o {name: 'node3', a: [7, 8, 9]}),
(n)-[:KNOWS]->(m),
(m)-[:KNOWS]->(o)
$$) as (i agtype);
i
---
(0 rows)

SELECT * FROM cypher('cypher_unwind', $$
MATCH (n)
WITH n.a AS a
UNWIND a AS i
RETURN *
$$) as (i agtype, j agtype);
i | j
-----------+---
[1, 2, 3] | 1
[1, 2, 3] | 2
[1, 2, 3] | 3
[4, 5, 6] | 4
[4, 5, 6] | 5
[4, 5, 6] | 6
[7, 8, 9] | 7
[7, 8, 9] | 8
[7, 8, 9] | 9
[1, 2, 3] | 1
[1, 2, 3] | 2
[1, 2, 3] | 3
[4, 5, 6] | 4
[4, 5, 6] | 5
[4, 5, 6] | 6
[7, 8, 9] | 7
[7, 8, 9] | 8
[7, 8, 9] | 9
|
(19 rows)

SELECT * FROM cypher('cypher_unwind', $$
UNWIND NULL as i
RETURN i
$$) as (i agtype);
i
---

(1 row)

--
-- Clean up
--
Expand All @@ -214,3 +273,13 @@ NOTICE: graph "cypher_unwind" has been dropped

(1 row)

SELECT drop_graph('issue_1302', true);
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table issue_1302._ag_label_vertex
drop cascades to table issue_1302._ag_label_edge
NOTICE: graph "issue_1302" has been dropped
drop_graph
------------

(1 row)

29 changes: 28 additions & 1 deletion regress/sql/cypher_unwind.sql
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,35 @@ SELECT * FROM cypher('cypher_unwind', $$
RETURN n
$$) as (i agtype);

--
-- Issue 1302
--

SELECT create_graph('issue_1302');

SELECT * FROM cypher('cypher_unwind', $$
CREATE (agtype {name: 'node1', a: [1, 2, 3]}),
(m {name: 'node2', a: [4, 5, 6]}),
(o {name: 'node3', a: [7, 8, 9]}),
(n)-[:KNOWS]->(m),
(m)-[:KNOWS]->(o)
$$) as (i agtype);

SELECT * FROM cypher('cypher_unwind', $$
MATCH (n)
WITH n.a AS a
UNWIND a AS i
RETURN *
$$) as (i agtype, j agtype);

SELECT * FROM cypher('cypher_unwind', $$
UNWIND NULL as i
RETURN i
$$) as (i agtype);

--
-- Clean up
--

SELECT drop_graph('cypher_unwind', true);
SELECT drop_graph('cypher_unwind', true);
SELECT drop_graph('issue_1302', true);
9 changes: 8 additions & 1 deletion src/backend/utils/adt/agtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -10949,7 +10949,7 @@ PG_FUNCTION_INFO_V1(age_unnest);
*/
Datum age_unnest(PG_FUNCTION_ARGS)
{
agtype *agtype_arg = AG_GET_ARG_AGTYPE_P(0);
agtype *agtype_arg = NULL;
ReturnSetInfo *rsi;
Tuplestorestate *tuple_store;
TupleDesc tupdesc;
Expand All @@ -10960,6 +10960,13 @@ Datum age_unnest(PG_FUNCTION_ARGS)
agtype_value v;
agtype_iterator_token r;

// check for null
if (PG_ARGISNULL(0))
{
PG_RETURN_NULL();
}

agtype_arg = AG_GET_ARG_AGTYPE_P(0);
if (!AGT_ROOT_IS_ARRAY(agtype_arg))
{
ereport(ERROR,
Expand Down
0