Skip to content

Commit 14cade7

Browse files
author
capnspek
committed
Fixed the orderability issue #870 and added regression tests
1 parent a3c517c commit 14cade7

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

regress/expected/agtype.out

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ SELECT agtype_in('{"bool":true}') < agtype_in('{"bool":true, "null": null}');
15231523
(1 row)
15241524

15251525
-- Comparisons between types
1526-
-- Object < List < String < Boolean < Integer = Float = Numeric < Null
1526+
-- Path < Edge < Vertex < Object < List < String < Boolean < Integer = Float = Numeric < Null
15271527
SELECT agtype_in('1') < agtype_in('null');
15281528
?column?
15291529
----------
@@ -1590,6 +1590,24 @@ SELECT agtype_in('{"bool":true, "integer":1}') < agtype_in('{"bool":true, "integ
15901590
t
15911591
(1 row)
15921592

1593+
SELECT agtype_in('{"id":0, "label": "v", "properties":{"i":0}}::vertex') < agtype_in('{"bool":true, "i":0}');
1594+
?column?
1595+
----------
1596+
t
1597+
(1 row)
1598+
1599+
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');
1600+
?column?
1601+
----------
1602+
t
1603+
(1 row)
1604+
1605+
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');
1606+
?column?
1607+
----------
1608+
t
1609+
(1 row)
1610+
15931611
SELECT agtype_in('1::numeric') < agtype_in('null');
15941612
?column?
15951613
----------

regress/sql/agtype.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ SELECT agtype_in('{"bool":true, "null": null}') = agtype_in('{"null":null, "bool
403403
SELECT agtype_in('{"bool":true}') < agtype_in('{"bool":true, "null": null}');
404404

405405
-- Comparisons between types
406-
-- Object < List < String < Boolean < Integer = Float = Numeric < Null
406+
-- Path < Edge < Vertex < Object < List < String < Boolean < Integer = Float = Numeric < Null
407407
SELECT agtype_in('1') < agtype_in('null');
408408
SELECT agtype_in('NaN') < agtype_in('null');
409409
SELECT agtype_in('Infinity') < agtype_in('null');
@@ -415,6 +415,9 @@ SELECT agtype_in('[1,3,5,7,9,11]') < agtype_in('"string"');
415415
SELECT agtype_in('{"bool":true, "integer":1}') < agtype_in('[1,3,5,7,9,11]');
416416
SELECT agtype_in('[1, "string"]') < agtype_in('[1, 1]');
417417
SELECT agtype_in('{"bool":true, "integer":1}') < agtype_in('{"bool":true, "integer":null}');
418+
SELECT agtype_in('{"id":0, "label": "v", "properties":{"i":0}}::vertex') < agtype_in('{"bool":true, "i":0}');
419+
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');
420+
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');
418421
SELECT agtype_in('1::numeric') < agtype_in('null');
419422
SELECT agtype_in('true') < agtype_in('1::numeric');
420423

src/backend/utils/adt/agtype_util.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ uint32 get_agtype_length(const agtype_container *agtc, int index)
197197
*/
198198
static int get_type_sort_priority(enum agtype_value_type type)
199199
{
200-
if (type == AGTV_OBJECT)
201-
return 0;
202200
if (type == AGTV_PATH)
203-
return 1;
201+
return 0;
204202
if (type == AGTV_EDGE)
205-
return 2;
203+
return 1;
206204
if (type == AGTV_VERTEX)
205+
return 2;
206+
if (type == AGTV_OBJECT)
207207
return 3;
208208
if (type == AGTV_ARRAY)
209209
return 4;
@@ -360,6 +360,16 @@ int compare_agtype_containers_orderability(agtype_container *a,
360360
break;
361361
}
362362

363+
/*Correction step because AGTV_ARRAY might be there just because of the container type*/
364+
if(va.type == AGTV_ARRAY && vb.type == AGTV_OBJECT)
365+
{
366+
ra = agtype_iterator_next(&ita, &va, false);
367+
}
368+
else if(va.type == AGTV_OBJECT && vb.type == AGTV_ARRAY)
369+
{
370+
rb = agtype_iterator_next(&itb, &vb, false);
371+
}
372+
363373
Assert(va.type != vb.type);
364374
Assert(va.type != AGTV_BINARY);
365375
Assert(vb.type != AGTV_BINARY);

0 commit comments

Comments
 (0)