Skip to content

Commit d143855

Browse files
committed
(sql,pgtap,docqueries) pgr_topologicalSort: Standardizing output
1 parent 70ea35a commit d143855

5 files changed

Lines changed: 50 additions & 72 deletions

File tree

docqueries/ordering/topologicalSort.result

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ SELECT * FROM pgr_topologicalsort(
99
UNION
1010
SELECT id, target, source, reverse_cost
1111
FROM edges WHERE cost < 0$$);
12-
seq | sorted_v
13-
-----+----------
14-
1 | 1
15-
2 | 5
16-
3 | 2
17-
4 | 4
18-
5 | 3
19-
6 | 13
20-
7 | 14
21-
8 | 15
22-
9 | 10
23-
10 | 6
24-
11 | 7
25-
12 | 8
26-
13 | 9
27-
14 | 11
28-
15 | 16
29-
16 | 12
30-
17 | 17
12+
seq | node
13+
-----+------
14+
1 | 1
15+
2 | 5
16+
3 | 2
17+
4 | 4
18+
5 | 3
19+
6 | 13
20+
7 | 14
21+
8 | 15
22+
9 | 10
23+
10 | 6
24+
11 | 7
25+
12 | 8
26+
13 | 9
27+
14 | 11
28+
15 | 16
29+
16 | 12
30+
17 | 17
3131
(17 rows)
3232

3333
/* -- q2 */
@@ -37,25 +37,25 @@ SELECT * FROM pgr_topologicalsort(
3737
UNION
3838
SELECT id, source, target, -1, reverse_cost
3939
FROM edges WHERE cost < 0$$);
40-
seq | sorted_v
41-
-----+----------
42-
1 | 5
43-
2 | 2
44-
3 | 4
45-
4 | 13
46-
5 | 14
47-
6 | 1
48-
7 | 3
49-
8 | 15
50-
9 | 10
51-
10 | 6
52-
11 | 7
53-
12 | 8
54-
13 | 9
55-
14 | 11
56-
15 | 12
57-
16 | 16
58-
17 | 17
40+
seq | node
41+
-----+------
42+
1 | 5
43+
2 | 2
44+
3 | 4
45+
4 | 13
46+
5 | 14
47+
6 | 1
48+
7 | 3
49+
8 | 15
50+
9 | 10
51+
10 | 6
52+
11 | 7
53+
12 | 8
54+
13 | 9
55+
14 | 11
56+
15 | 12
57+
16 | 16
58+
17 | 17
5959
(17 rows)
6060

6161
/* -- q3 */

pgtap/ordering/topologicalSort/no_crash_test.pg

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
BEGIN;
2121

2222
UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost);
23-
SELECT plan(5);
24-
25-
CREATE TABLE edges1 (
26-
id serial,
27-
source integer,
28-
target integer,
29-
cost double precision,
30-
reverse_cost double precision
31-
);
32-
INSERT INTO edges1 (source,target,cost,reverse_cost) VALUES ( 1, 2,0,0);
33-
INSERT INTO edges1 (source,target,cost,reverse_cost) VALUES (2,3,0,0);
23+
SELECT plan(4);
3424

3525
SELECT has_function('pgr_topologicalsort');
36-
3726
SELECT function_returns('pgr_topologicalsort', ARRAY['text'], 'setof record');
3827

3928
-- flags
@@ -53,24 +42,5 @@ SELECT lives_ok(
5342
'4: Documentation says works with no flags');
5443

5544

56-
-- prepare for testing return types
57-
58-
PREPARE all_return AS
59-
SELECT
60-
'integer'::text AS t1,
61-
'bigint'::text AS t2;
62-
63-
PREPARE q1 AS
64-
SELECT pg_typeof(seq)::text AS t1,
65-
pg_typeof(sorted_v)::text AS t2
66-
FROM (
67-
SELECT * FROM pgr_topologicalsort(
68-
'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id = 2'
69-
) ) AS a
70-
limit 1;
71-
72-
73-
SELECT set_eq('q1', 'all_return', 'Expected returning, columns names & types');
74-
7545
SELECT * FROM finish();
7646
ROLLBACK;

pgtap/ordering/topologicalSort/types_check.pg

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
********************************************************************PGR-GNU*/
2020
BEGIN;
2121

22-
SELECT plan(5);
22+
SELECT CASE WHEN min_version('4.0.0') THEN plan(5) ELSE plan(4) END;
2323

2424
CREATE OR REPLACE FUNCTION types_check()
2525
RETURNS SETOF TEXT AS
@@ -30,9 +30,15 @@ BEGIN
3030
RETURN QUERY SELECT has_function('pgr_topologicalsort', ARRAY['text']);
3131
RETURN QUERY SELECT function_returns('pgr_topologicalsort', ARRAY['text'], 'setof record');
3232

33+
IF NOT min_version('4.0.0') THEN
34+
RETURN QUERY
35+
SELECT skip(1, 'pgr_topologicalsort: testing only signatures standardaized in v4.0.0.');
36+
RETURN;
37+
END IF;
38+
3339
RETURN QUERY
3440
SELECT function_args_eq('pgr_topologicalsort',
35-
$$SELECT '{"","seq","sorted_v"}'::TEXT[] $$
41+
$$SELECT '{"",seq,node}'::TEXT[] $$
3642
);
3743

3844
RETURN QUERY

sql/scripts/build-extension-update-files.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ sub generate_upgrade_script {
303303
push @commands, drop_special_case_function("pgr_binarybreadthfirstsearch(text,anyarray,bigint,boolean)");
304304
push @commands, drop_special_case_function("pgr_binarybreadthfirstsearch(text,bigint,anyarray,boolean)");
305305

306+
push @commands, drop_special_case_function("pgr_topologicalsort(text)");
307+
push @commands, drop_special_case_function("pgr_transitiveclosure(text)");
306308

307309
push @commands, drop_special_case_function("pgr_dagshortestpath(text,bigint,bigint)");
308310
push @commands, drop_special_case_function("pgr_dagshortestpath(text,bigint,anyarray)");

sql/topologicalSort/topologicalSort.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CREATE FUNCTION pgr_topologicalSort(
3434
TEXT, -- edges_sql (required)
3535

3636
OUT seq INTEGER,
37-
OUT sorted_v BIGINT)
37+
OUT node BIGINT)
3838
RETURNS SETOF RECORD AS
3939
$BODY$
4040
SELECT seq, sorted_v

0 commit comments

Comments
 (0)