Skip to content

Commit 87abc60

Browse files
jrgemignaniM4rcxs
authored andcommitted
Fix issue 1043: ERROR: container must be an array or object (apache#1046)
Fixed issue 1043 - ERROR: container must be an array or object This was cause by agtype_access_operator not recognizing and decoding a VLE path container. Added regression tests.
1 parent 2947422 commit 87abc60

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

Diff for: regress/expected/cypher_vle.out

+44
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,50 @@ NOTICE: graph "access" has been dropped
10001000

10011001
(1 row)
10021002

1003+
-- issue 1043
1004+
SELECT create_graph('issue_1043');
1005+
NOTICE: graph "issue_1043" has been created
1006+
create_graph
1007+
--------------
1008+
1009+
(1 row)
1010+
1011+
SELECT * FROM cypher('issue_1043', $$ CREATE (n)-[:KNOWS {n:'hello'}]->({n:'hello'}) $$) as (a agtype);
1012+
a
1013+
---
1014+
(0 rows)
1015+
1016+
SELECT * FROM cypher('issue_1043', $$ MATCH (x)<-[y *]-(),({n:y[0].n}) RETURN x $$) as (a agtype);
1017+
a
1018+
----------------------------------------------------------------------------
1019+
{"id": 281474976710658, "label": "", "properties": {"n": "hello"}}::vertex
1020+
(1 row)
1021+
1022+
SELECT * FROM cypher('issue_1043', $$ CREATE (n)-[:KNOWS {n:'hello'}]->({n:'hello'}) $$) as (a agtype);
1023+
a
1024+
---
1025+
(0 rows)
1026+
1027+
SELECT * FROM cypher('issue_1043', $$ MATCH (x)<-[y *]-(),({n:y[0].n}) RETURN x $$) as (a agtype);
1028+
a
1029+
----------------------------------------------------------------------------
1030+
{"id": 281474976710658, "label": "", "properties": {"n": "hello"}}::vertex
1031+
{"id": 281474976710658, "label": "", "properties": {"n": "hello"}}::vertex
1032+
{"id": 281474976710660, "label": "", "properties": {"n": "hello"}}::vertex
1033+
{"id": 281474976710660, "label": "", "properties": {"n": "hello"}}::vertex
1034+
(4 rows)
1035+
1036+
SELECT drop_graph('issue_1043', true);
1037+
NOTICE: drop cascades to 3 other objects
1038+
DETAIL: drop cascades to table issue_1043._ag_label_vertex
1039+
drop cascades to table issue_1043._ag_label_edge
1040+
drop cascades to table issue_1043."KNOWS"
1041+
NOTICE: graph "issue_1043" has been dropped
1042+
drop_graph
1043+
------------
1044+
1045+
(1 row)
1046+
10031047
--
10041048
-- Clean up
10051049
--

Diff for: regress/sql/cypher_vle.sql

+9
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,15 @@ SELECT * FROM cypher('access',$$ MATCH ()-[e*]->() RETURN e[0].arry[2], e[1].arr
330330

331331
SELECT drop_graph('access', true);
332332

333+
-- issue 1043
334+
SELECT create_graph('issue_1043');
335+
SELECT * FROM cypher('issue_1043', $$ CREATE (n)-[:KNOWS {n:'hello'}]->({n:'hello'}) $$) as (a agtype);
336+
SELECT * FROM cypher('issue_1043', $$ MATCH (x)<-[y *]-(),({n:y[0].n}) RETURN x $$) as (a agtype);
337+
SELECT * FROM cypher('issue_1043', $$ CREATE (n)-[:KNOWS {n:'hello'}]->({n:'hello'}) $$) as (a agtype);
338+
SELECT * FROM cypher('issue_1043', $$ MATCH (x)<-[y *]-(),({n:y[0].n}) RETURN x $$) as (a agtype);
339+
340+
SELECT drop_graph('issue_1043', true);
341+
333342
--
334343
-- Clean up
335344
--

Diff for: src/backend/utils/adt/agtype.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -3486,8 +3486,25 @@ Datum agtype_access_operator(PG_FUNCTION_ARGS)
34863486
/* get the container argument. It could be an object or array */
34873487
container = DATUM_GET_AGTYPE_P(args[0]);
34883488

3489+
/* if it is a binary container, check for a VLE vpc */
3490+
if (AGT_ROOT_IS_BINARY(container))
3491+
{
3492+
if (AGT_ROOT_BINARY_FLAGS(container) == AGT_FBINARY_TYPE_VLE_PATH)
3493+
{
3494+
/* retrieve an array of edges from the vpc */
3495+
container_value = agtv_materialize_vle_edges(container);
3496+
/* clear the container reference */
3497+
container = NULL;
3498+
}
3499+
else
3500+
{
3501+
ereport(ERROR,
3502+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3503+
errmsg("binary container must be a VLE vpc")));
3504+
}
3505+
}
34893506
/* if it is a scalar, open it and pull out the value */
3490-
if (AGT_ROOT_IS_SCALAR(container))
3507+
else if (AGT_ROOT_IS_SCALAR(container))
34913508
{
34923509
container_value = get_ith_agtype_value_from_container(&container->root,
34933510
0);

0 commit comments

Comments
 (0)