Skip to content

Commit

Permalink
Fixed the orderability issue #870 and added regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CapnSpek committed Jun 26, 2023
1 parent a3c517c commit 14cade7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
20 changes: 19 additions & 1 deletion regress/expected/agtype.out
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ SELECT agtype_in('{"bool":true}') < agtype_in('{"bool":true, "null": null}');
(1 row)

-- Comparisons between types
-- Object < List < String < Boolean < Integer = Float = Numeric < Null
-- Path < Edge < Vertex < Object < List < String < Boolean < Integer = Float = Numeric < Null
SELECT agtype_in('1') < agtype_in('null');
?column?
----------
Expand Down Expand Up @@ -1590,6 +1590,24 @@ SELECT agtype_in('{"bool":true, "integer":1}') < agtype_in('{"bool":true, "integ
t
(1 row)

SELECT agtype_in('{"id":0, "label": "v", "properties":{"i":0}}::vertex') < agtype_in('{"bool":true, "i":0}');
?column?
----------
t
(1 row)

SELECT agtype_in('{"id":2, "start_id":0, "end_id":1, "label": "e", "properties":{"i":0}}::edge') < agtype_in('{"id":0, "label": "v", "properties":{"i":0}}::vertex');
?column?
----------
t
(1 row)

SELECT agtype_in('[{"id": 0, "label": "v", "properties": {"i": 0}}::vertex, {"id": 2, "start_id": 0, "end_id": 1, "label": "e", "properties": {"i": 0}}::edge, {"id": 1, "label": "v", "properties": {"i": 0}}::vertex]::path') < agtype_in('{"id":2, "start_id":0, "end_id":1, "label": "e", "properties":{"i":0}}::edge');
?column?
----------
t
(1 row)

SELECT agtype_in('1::numeric') < agtype_in('null');
?column?
----------
Expand Down
5 changes: 4 additions & 1 deletion regress/sql/agtype.sql
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ SELECT agtype_in('{"bool":true, "null": null}') = agtype_in('{"null":null, "bool
SELECT agtype_in('{"bool":true}') < agtype_in('{"bool":true, "null": null}');

-- Comparisons between types
-- Object < List < String < Boolean < Integer = Float = Numeric < Null
-- Path < Edge < Vertex < Object < List < String < Boolean < Integer = Float = Numeric < Null
SELECT agtype_in('1') < agtype_in('null');
SELECT agtype_in('NaN') < agtype_in('null');
SELECT agtype_in('Infinity') < agtype_in('null');
Expand All @@ -415,6 +415,9 @@ SELECT agtype_in('[1,3,5,7,9,11]') < agtype_in('"string"');
SELECT agtype_in('{"bool":true, "integer":1}') < agtype_in('[1,3,5,7,9,11]');
SELECT agtype_in('[1, "string"]') < agtype_in('[1, 1]');
SELECT agtype_in('{"bool":true, "integer":1}') < agtype_in('{"bool":true, "integer":null}');
SELECT agtype_in('{"id":0, "label": "v", "properties":{"i":0}}::vertex') < agtype_in('{"bool":true, "i":0}');
SELECT agtype_in('{"id":2, "start_id":0, "end_id":1, "label": "e", "properties":{"i":0}}::edge') < agtype_in('{"id":0, "label": "v", "properties":{"i":0}}::vertex');
SELECT agtype_in('[{"id": 0, "label": "v", "properties": {"i": 0}}::vertex, {"id": 2, "start_id": 0, "end_id": 1, "label": "e", "properties": {"i": 0}}::edge, {"id": 1, "label": "v", "properties": {"i": 0}}::vertex]::path') < agtype_in('{"id":2, "start_id":0, "end_id":1, "label": "e", "properties":{"i":0}}::edge');
SELECT agtype_in('1::numeric') < agtype_in('null');
SELECT agtype_in('true') < agtype_in('1::numeric');

Expand Down
18 changes: 14 additions & 4 deletions src/backend/utils/adt/agtype_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ uint32 get_agtype_length(const agtype_container *agtc, int index)
*/
static int get_type_sort_priority(enum agtype_value_type type)
{
if (type == AGTV_OBJECT)
return 0;
if (type == AGTV_PATH)
return 1;
return 0;
if (type == AGTV_EDGE)
return 2;
return 1;
if (type == AGTV_VERTEX)
return 2;
if (type == AGTV_OBJECT)
return 3;
if (type == AGTV_ARRAY)
return 4;
Expand Down Expand Up @@ -360,6 +360,16 @@ int compare_agtype_containers_orderability(agtype_container *a,
break;
}

/*Correction step because AGTV_ARRAY might be there just because of the container type*/
if(va.type == AGTV_ARRAY && vb.type == AGTV_OBJECT)
{
ra = agtype_iterator_next(&ita, &va, false);
}
else if(va.type == AGTV_OBJECT && vb.type == AGTV_ARRAY)
{
rb = agtype_iterator_next(&itb, &vb, false);
}

Assert(va.type != vb.type);
Assert(va.type != AGTV_BINARY);
Assert(vb.type != AGTV_BINARY);
Expand Down

0 comments on commit 14cade7

Please sign in to comment.