diff --git a/NEWS.md b/NEWS.md index a22b830a150..67c68431046 100644 --- a/NEWS.md +++ b/NEWS.md @@ -70,6 +70,11 @@ milestone for 4.0.0 * pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean) * pgr_withpointsdd(text,text,bigint,double precision,boolean,character,boolean) +* [#2895](https://github.com/pgRouting/pgrouting/issues/2895): + pgr_withPointsKSP + + * pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) + **Removal of SQL deprecated functions** * [#2681](https://github.com/pgRouting/pgrouting/issues/2681): @@ -105,8 +110,11 @@ milestone for 4.0.0 * _pgr_trsp(text,text,bigint,anyarray,boolean) * _pgr_trsp(text,text,bigint,bigint,boolean) * _pgr_trspviavertices(text,integer[],boolean,boolean,text) -* _pgr_withpointsvia(text,bigint[],double precision[],boolean) * _pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean) +* _pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean,boolean) +* _pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) +* _pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean) +* _pgr_withpointsvia(text,bigint[],double precision[],boolean) * _trsp(text,text,anyarray,anyarray,boolean) * _v4trsp(text,text,anyarray,anyarray,boolean) * _v4trsp(text,text,text,boolean) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 8547db746ff..cf31e6b5fbd 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -100,6 +100,11 @@ milestone for 4.0.0 * pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean) * pgr_withpointsdd(text,text,bigint,double precision,boolean,character,boolean) +* `#2895 `__: + pgr_withPointsKSP + + * pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) + .. rubric:: Removal of SQL deprecated functions * `#2681 `__: @@ -135,8 +140,11 @@ milestone for 4.0.0 * _pgr_trsp(text,text,bigint,anyarray,boolean) * _pgr_trsp(text,text,bigint,bigint,boolean) * _pgr_trspviavertices(text,integer[],boolean,boolean,text) -* _pgr_withpointsvia(text,bigint[],double precision[],boolean) * _pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean) +* _pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean,boolean) +* _pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) +* _pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean) +* _pgr_withpointsvia(text,bigint[],double precision[],boolean) * _trsp(text,text,anyarray,anyarray,boolean) * _v4trsp(text,text,anyarray,anyarray,boolean) * _v4trsp(text,text,text,boolean) diff --git a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po index 3c1807aa3f5..89d4b970e71 100644 --- a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v3.8\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-05-21 22:35+0000\n" +"POT-Creation-Date: 2025-05-22 03:51+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4037,6 +4037,14 @@ msgid "" "precision,boolean,character,boolean)" msgstr "" +msgid "" +"`#2895 `__: " +"pgr_withPointsKSP" +msgstr "" + +msgid "pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean)" +msgstr "" + msgid "Removal of SQL deprecated functions" msgstr "" @@ -4127,14 +4135,23 @@ msgstr "" msgid "_pgr_trspviavertices(text,integer[],boolean,boolean,text)" msgstr "" -msgid "_pgr_withpointsvia(text,bigint[],double precision[],boolean)" -msgstr "" - msgid "" "_pgr_withpointsdd(text,text,anyarray,double " "precision,boolean,character,boolean,boolean)" msgstr "" +msgid "_pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean,boolean)" +msgstr "" + +msgid "_pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean)" +msgstr "" + +msgid "_pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean)" +msgstr "" + +msgid "_pgr_withpointsvia(text,bigint[],double precision[],boolean)" +msgstr "" + msgid "_trsp(text,text,anyarray,anyarray,boolean)" msgstr "" diff --git a/locale/pot/pgrouting_doc_strings.pot b/locale/pot/pgrouting_doc_strings.pot index 98d145e7e01..917724f0e91 100644 --- a/locale/pot/pgrouting_doc_strings.pot +++ b/locale/pot/pgrouting_doc_strings.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v4.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-05-21 22:35+0000\n" +"POT-Creation-Date: 2025-05-22 03:51+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3622,6 +3622,12 @@ msgstr "" msgid "pgr_withpointsdd(text,text,bigint,double precision,boolean,character,boolean)" msgstr "" +msgid "`#2895 `__: pgr_withPointsKSP" +msgstr "" + +msgid "pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean)" +msgstr "" + msgid "Removal of SQL deprecated functions" msgstr "" @@ -3694,10 +3700,19 @@ msgstr "" msgid "_pgr_trspviavertices(text,integer[],boolean,boolean,text)" msgstr "" -msgid "_pgr_withpointsvia(text,bigint[],double precision[],boolean)" +msgid "_pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean)" msgstr "" -msgid "_pgr_withpointsdd(text,text,anyarray,double precision,boolean,character,boolean,boolean)" +msgid "_pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean,boolean)" +msgstr "" + +msgid "_pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean)" +msgstr "" + +msgid "_pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean)" +msgstr "" + +msgid "_pgr_withpointsvia(text,bigint[],double precision[],boolean)" msgstr "" msgid "_trsp(text,text,anyarray,anyarray,boolean)" diff --git a/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg b/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg index 9dcd0f7d6d2..83363691b2d 100644 --- a/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg +++ b/pgtap/ksp/withPointsKSP/edge_cases/point_in_vertex.pg @@ -29,18 +29,17 @@ CREATE OR REPLACE FUNCTION test_vertex_points() RETURNS SETOF TEXT AS $BODY$ BEGIN - IF NOT min_version('3.6.0') THEN - RETURN QUERY SELECT skip(1, 'Signature added on 3.6.0'); - RETURN; - END IF; - + IF NOT min_version('3.6.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_withPointsKSP testing only valid signatures on 4.0.0'); + RETURN; + END IF; PREPARE dijkstra1(BIGINT, BIGINT) AS SELECT agg_cost::TEXT FROM pgr_KSP( $$SELECT id, source, target, cost, reverse_cost FROM four_edges$$, $1, $2, 3, true) WHERE edge < 0; --- its a straigh line and one extreme are reachable +-- its a straight line and one extreme are reachable RETURN QUERY SELECT results_eq($$dijkstra1(5,9)$$, ARRAY[4]::TEXT[]); RETURN QUERY SELECT results_eq($$dijkstra1(9,5)$$, ARRAY[4]::TEXT[]); diff --git a/pgtap/ksp/withPointsKSP/inner_query.pg b/pgtap/ksp/withPointsKSP/inner_query.pg index 463f56749b6..ee44ff747c0 100644 --- a/pgtap/ksp/withPointsKSP/inner_query.pg +++ b/pgtap/ksp/withPointsKSP/inner_query.pg @@ -20,12 +20,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. BEGIN; UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT CASE WHEN min_version('3.6.0') THEN plan(684) ELSE plan(252) END; +SELECT CASE WHEN min_version('3.6.0') THEN plan(432) ELSE plan(1) END; CREATE OR REPLACE FUNCTION withPointsKSP_inner_query() RETURNS SETOF TEXT AS $BODY$ BEGIN - IF min_version('3.6.0') THEN + + IF NOT min_version('3.6.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_withPointsKSP testing only valid signatures on 4.0.0'); + RETURN; + END IF; + -- ONE TO ONE RETURN QUERY SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, 6, 10, 1, $$r$$,true)'); RETURN QUERY SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edges$$,', ', 6, 10, 1, $$l$$, true)'); @@ -42,17 +47,7 @@ BEGIN RETURN QUERY SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, $$SELECT * FROM combinations$$, 2, $$r$$, true)'); RETURN QUERY SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edges$$,', ', $$SELECT * FROM combinations$$, 2, $$r$$, true)'); RETURN QUERY SELECT innerquery_combinations('pgr_withPointsKSP($$SELECT * FROM edges$$, $$SELECT * from pointsOfInterest$$,',', 2, $$r$$, true)'); - END IF; - /* TODO Remove on v4*/ - -- ONE TO ONE - SET client_min_messages TO ERROR; - RETURN QUERY SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, 5, 10, 2, driving_side => $$r$$, directed => true)'); - RETURN QUERY SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edges$$,', ', 6, 10, 2, driving_side => $$r$$, directed => true)'); - RETURN QUERY SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, 5, 10, 2, true, true, $$r$$)'); - RETURN QUERY SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edges$$,', ', 6, 10, 2, true, true, $$r$$)'); - RETURN QUERY SELECT style_dijkstra('pgr_withPointsKSP(', ', $$SELECT * from pointsOfInterest$$, 5, 10, 2, true)'); - RETURN QUERY SELECT innerquery_points('pgr_withPointsKSP($$SELECT * FROM edges$$,', ', 6, 10, 2, true)'); - SET client_min_messages TO NOTICE; + END $BODY$ LANGUAGE plpgsql VOLATILE; diff --git a/pgtap/ksp/withPointsKSP/no_crash_test.pg b/pgtap/ksp/withPointsKSP/no_crash_test.pg index 56a7629acfa..30ab7c9f934 100644 --- a/pgtap/ksp/withPointsKSP/no_crash_test.pg +++ b/pgtap/ksp/withPointsKSP/no_crash_test.pg @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. BEGIN; UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT CASE WHEN min_version('3.6.0') THEN plan(164) ELSE plan(26) END; +SELECT CASE WHEN min_version('3.6.0') THEN plan(137) ELSE plan(1) END; PREPARE edges AS SELECT id, source, target, cost, reverse_cost FROM edges; @@ -33,9 +33,6 @@ SELECT array_agg(id) FROM vertices WHERE id IN (-1); PREPARE null_ret_arr AS SELECT array_agg(id) FROM vertices WHERE id IN (-1); -SELECT isnt_empty('edges', 'Should be not empty to tests be meaningful'); -SELECT set_eq('null_ret', 'SELECT NULL::BIGINT[]', 'Should be empty to tests be meaningful'); - CREATE OR REPLACE FUNCTION test_function() RETURNS SETOF TEXT AS $BODY$ @@ -43,7 +40,13 @@ DECLARE params TEXT[]; subs TEXT[]; BEGIN -IF min_version('3.6.0') THEN + + IF NOT min_version('3.6.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_withPointsKSP testing only valid signatures on 4.0.0'); + RETURN; + END IF; + + RETURN QUERY SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','character','boolean','boolean','boolean']); -- one to one params = ARRAY[ '$$edges$$', @@ -168,11 +171,6 @@ IF min_version('3.6.0') THEN PREPARE combinations AS SELECT source, target FROM combinations; - RETURN QUERY - SELECT isnt_empty('combinations', 'Should be not empty to tests be meaningful'); - RETURN QUERY - SELECT is_empty('null_combinations', 'Should be empty to tests be meaningful'); - params = ARRAY['$$edges$$', '$$SELECT pid, edge_id, fraction from pointsOfInterest$$', '$$combinations$$', @@ -197,35 +195,6 @@ IF min_version('3.6.0') THEN 'NULL' ]::TEXT[]; RETURN query SELECT * FROM no_crash_test('pgr_withPointsKSP', params, subs); -END IF; - -/* TODO remove tests on v4*/ - -- 1 to distance - params = ARRAY[ - '$$SELECT id, source, target, cost, reverse_cost FROM edges$$', - '$$SELECT pid, edge_id, fraction from pointsOfInterest$$', - '5', - '6', - '2' - ]::TEXT[]; - subs = ARRAY[ - 'NULL', - 'NULL', - '(SELECT id FROM vertices WHERE id IN (-1))', - '(SELECT id FROM vertices WHERE id IN (-1))', - 'NULL' - ]::TEXT[]; - - RETURN query SELECT * FROM no_crash_test('pgr_withPointsKSP', params, subs); - - subs = ARRAY[ - 'NULL', - 'NULL', - 'NULL::BIGINT', - 'NULL::BIGINT', - 'NULL' - ]::TEXT[]; - RETURN query SELECT * FROM no_crash_test('pgr_withPointsKSP', params, subs); END $BODY$ diff --git a/pgtap/ksp/withPointsKSP/types_check.pg b/pgtap/ksp/withPointsKSP/types_check.pg index bb5ee0127d6..a3a29b84869 100644 --- a/pgtap/ksp/withPointsKSP/types_check.pg +++ b/pgtap/ksp/withPointsKSP/types_check.pg @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ BEGIN; -SELECT CASE WHEN min_version('3.6.0') THEN plan(15) ELSE plan(5) END; +SELECT CASE WHEN min_version('3.6.0') THEN plan(13) ELSE plan(2) END; SELECT has_function('pgr_withpointsksp'); @@ -25,7 +25,12 @@ CREATE FUNCTION withPointsKSP_types_check() RETURNS SETOF TEXT AS $BODY$ BEGIN - IF min_version('3.6.0') THEN + + IF NOT min_version('3.6.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_withPointsKSP testing only valid signatures on 4.0.0'); + RETURN; + END IF; + RETURN QUERY SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','character','boolean','boolean','boolean']); RETURN QUERY SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','anyarray','integer','character','boolean','boolean','boolean']); RETURN QUERY SELECT has_function('pgr_withpointsksp',ARRAY['text','text','anyarray','bigint','integer','character','boolean','boolean','boolean']); @@ -37,42 +42,42 @@ BEGIN RETURN QUERY SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','anyarray','bigint','integer','character','boolean','boolean','boolean'],'setof record'); RETURN QUERY SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','anyarray','anyarray','integer','character','boolean','boolean','boolean'],'setof record'); RETURN QUERY SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','text','integer','character','boolean','boolean','boolean'],'setof record'); - END IF; - /*Remove last 1 row on v4*/ - RETURN QUERY SELECT CASE WHEN min_version('3.6.0') - THEN collect_tap( - function_args_eq('pgr_withpointsksp', - $$VALUES - ('{"","","","","","","directed","heap_paths","details","seq","path_id","path_seq","start_vid","end_vid","node","edge","cost","agg_cost"}'::TEXT[]), - ('{"","","","","","directed","heap_paths","details","seq","path_id","path_seq","start_vid","end_vid","node","edge","cost","agg_cost"}'::TEXT[]), - ('{"","","","","","directed","heap_paths","driving_side","details","seq","path_id","path_seq","node","edge","cost","agg_cost"}'::TEXT[]) - $$), + IF min_version('4.0.0') THEN + + RETURN QUERY SELECT function_args_eq('pgr_withpointsksp', + $$VALUES + ('{"","","","","","",directed,heap_paths,details,seq,path_id,path_seq,start_vid,end_vid,node,edge,cost,agg_cost}'::TEXT[]), + ('{"","","","","",directed,heap_paths,details,seq,path_id,path_seq,start_vid,end_vid,node,edge,cost,agg_cost}'::TEXT[]) + $$); + + RETURN QUERY SELECT function_types_eq('pgr_withpointsksp', + $$VALUES + ('{text,text,int8,int8,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,int8,anyarray,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,anyarray,int8,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,anyarray,anyarray,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,text,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]) + $$); - function_types_eq('pgr_withpointsksp', - $$VALUES - ('{text,text,int8,int8,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), - ('{text,text,int8,anyarray,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), - ('{text,text,anyarray,int8,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), - ('{text,text,anyarray,anyarray,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), - ('{text,text,text,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), - ('{text,text,int8,int8,int4,bool,bool,bpchar,bool,int4,int4,int4,int8,int8,float8,float8}'::TEXT[]) - $$) - ) - ELSE collect_tap( + ELSE - function_args_eq('pgr_withpointsksp', - $$SELECT '{"","","","","","directed","heap_paths","driving_side","details","seq","path_id","path_seq","node","edge","cost","agg_cost"}'::TEXT[] $$ - ), + RETURN QUERY SELECT function_args_has('pgr_withpointsksp', + $$VALUES + ('{"","","","","","",directed,heap_paths,details,seq,path_id,path_seq,start_vid,end_vid,node,edge,cost,agg_cost}'::TEXT[]), + ('{"","","","","",directed,heap_paths,details,seq,path_id,path_seq,start_vid,end_vid,node,edge,cost,agg_cost}'::TEXT[]) + $$); - function_types_eq('pgr_withpointsksp', - $$VALUES ('{text,text,int8,int8,int4,bool,bool,bpchar,bool,int4,int4,int4,int8,int8,float8,float8}'::TEXT[])$$ - ) - )END; + RETURN QUERY SELECT function_types_has('pgr_withpointsksp', + $$VALUES + ('{text,text,int8,int8,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,int8,anyarray,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,anyarray,int8,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,anyarray,anyarray,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]), + ('{text,text,text,int4,bpchar,bool,bool,bool,int4,int4,int4,int8,int8,int8,int8,float8,float8}'::TEXT[]) + $$); - /* TODO remove on v4*/ - RETURN QUERY SELECT has_function('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','boolean','boolean','character','boolean']); - RETURN QUERY SELECT function_returns('pgr_withpointsksp',ARRAY['text','text','bigint','bigint','integer','boolean','boolean','character','boolean'],'setof record'); + END IF; END $BODY$ LANGUAGE plpgsql VOLATILE; diff --git a/sql/ksp/_withPointsKSP.sql b/sql/ksp/_withPointsKSP.sql index 8c5e1c709ff..201f1b0a504 100644 --- a/sql/ksp/_withPointsKSP.sql +++ b/sql/ksp/_withPointsKSP.sql @@ -26,11 +26,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ -------------------- --- pgr_withPointsKSP +-- pgr_withPointsKSP: -------------------- ---v3.6 -CREATE FUNCTION _pgr_withPointsKSP( +--v4.0 +CREATE FUNCTION _pgr_withPointsKSP_v4( TEXT, -- edges TEXT, -- points ANYARRAY, -- departures @@ -41,7 +41,6 @@ CREATE FUNCTION _pgr_withPointsKSP( BOOLEAN, -- directed BOOLEAN, -- heaps BOOLEAN, -- details - BOOLEAN, -- new ksp OUT seq INTEGER, OUT path_id INTEGER, @@ -56,8 +55,8 @@ RETURNS SETOF RECORD AS 'MODULE_PATHNAME' LANGUAGE c STABLE STRICT; ---v3.6 -CREATE FUNCTION _pgr_withPointsKSP( +--v4.0 +CREATE FUNCTION _pgr_withPointsKSP_v4( TEXT, -- edges TEXT, -- points TEXT, -- combinations @@ -81,34 +80,8 @@ RETURNS SETOF RECORD AS 'MODULE_PATHNAME' LANGUAGE c STABLE STRICT; -COMMENT ON FUNCTION _pgr_withPointsKSP(TEXT, TEXT, ANYARRAY, ANYARRAY, INTEGER, CHAR, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) +COMMENT ON FUNCTION _pgr_withPointsKSP_v4(TEXT, TEXT, ANYARRAY, ANYARRAY, INTEGER, CHAR, BOOLEAN, BOOLEAN, BOOLEAN) IS 'pgRouting internal function'; -COMMENT ON FUNCTION _pgr_withPointsKSP(TEXT, TEXT, TEXT, INTEGER, CHAR, BOOLEAN, BOOLEAN, BOOLEAN) +COMMENT ON FUNCTION _pgr_withPointsKSP_v4(TEXT, TEXT, TEXT, INTEGER, CHAR, BOOLEAN, BOOLEAN, BOOLEAN) IS 'pgRouting internal function'; - -/*TODO remove on v4*/ ---v3.0 -CREATE FUNCTION _pgr_withPointsKSP( - edges_sql TEXT, - points_sql TEXT, - start_pid BIGINT, - end_pid BIGINT, - k INTEGER, - - directed BOOLEAN, - heap_paths BOOLEAN, - driving_side CHAR, - details BOOLEAN, - - OUT seq INTEGER, OUT path_id INTEGER, OUT path_seq INTEGER, - OUT node BIGINT, OUT edge BIGINT, - OUT cost FLOAT, OUT agg_cost FLOAT) - RETURNS SETOF RECORD AS - 'MODULE_PATHNAME' - LANGUAGE c STABLE STRICT; - --- COMMENTS - -COMMENT ON FUNCTION _pgr_withPointsKSP(TEXT, TEXT, BIGINT, BIGINT, INTEGER, BOOLEAN, BOOLEAN, CHAR, BOOLEAN) -IS 'pgRouting internal function deprecated on v3.6.0'; diff --git a/sql/ksp/withPointsKSP.sql b/sql/ksp/withPointsKSP.sql index 62148219cd2..035a20ff944 100644 --- a/sql/ksp/withPointsKSP.sql +++ b/sql/ksp/withPointsKSP.sql @@ -51,7 +51,7 @@ CREATE FUNCTION pgr_withPointsKSP( RETURNS SETOF RECORD AS $BODY$ SELECT seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), ARRAY[$3]::BIGINT[], ARRAY[$4]::BIGINT[], $5, $6, $7, $8, $9, true); + FROM _pgr_withPointsKSP_v4(_pgr_get_statement($1), _pgr_get_statement($2), ARRAY[$3]::BIGINT[], ARRAY[$4]::BIGINT[], $5, $6, $7, $8, $9); $BODY$ LANGUAGE SQL VOLATILE STRICT COST 100 @@ -83,7 +83,7 @@ CREATE FUNCTION pgr_withPointsKSP( RETURNS SETOF RECORD AS $BODY$ SELECT seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), ARRAY[$3]::BIGINT[], $4::BIGINT[], $5, $6, $7, $8, $9, true); + FROM _pgr_withPointsKSP_v4(_pgr_get_statement($1), _pgr_get_statement($2), ARRAY[$3]::BIGINT[], $4::BIGINT[], $5, $6, $7, $8, $9); $BODY$ LANGUAGE SQL VOLATILE STRICT COST 100 @@ -115,7 +115,7 @@ CREATE FUNCTION pgr_withPointsKSP( RETURNS SETOF RECORD AS $BODY$ SELECT seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), $3::BIGINT[], ARRAY[$4]::BIGINT[], $5, $6, $7, $8, $9, true); + FROM _pgr_withPointsKSP_v4(_pgr_get_statement($1), _pgr_get_statement($2), $3::BIGINT[], ARRAY[$4]::BIGINT[], $5, $6, $7, $8, $9); $BODY$ LANGUAGE SQL VOLATILE STRICT COST 100 @@ -147,7 +147,7 @@ CREATE FUNCTION pgr_withPointsKSP( RETURNS SETOF RECORD AS $BODY$ SELECT seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), $3::BIGINT[], $4::BIGINT[], $5, $6, $7, $8, $9, true); + FROM _pgr_withPointsKSP_v4(_pgr_get_statement($1), _pgr_get_statement($2), $3::BIGINT[], $4::BIGINT[], $5, $6, $7, $8, $9); $BODY$ LANGUAGE SQL VOLATILE STRICT COST 100 @@ -178,7 +178,7 @@ CREATE FUNCTION pgr_withPointsKSP( RETURNS SETOF RECORD AS $BODY$ SELECT seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost - FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), $4, $5, $6, $7, $8); + FROM _pgr_withPointsKSP_v4(_pgr_get_statement($1), _pgr_get_statement($2), _pgr_get_statement($3), $4, $5, $6, $7, $8); $BODY$ LANGUAGE SQL VOLATILE STRICT COST 100 @@ -264,38 +264,3 @@ IS 'pgr_withPointsKSP - details := false - Documentation: - ${PROJECT_DOC_LINK}/pgr_withPointsKSP.html'; - ---v2.6 -CREATE FUNCTION pgr_withPointsKSP( - TEXT, -- edges_sql (required) - TEXT, -- points_sql (required) - BIGINT, -- from_vid (required) - BIGINT, -- to_vid (required) - INTEGER, -- K (required) - - directed BOOLEAN DEFAULT true, - heap_paths BOOLEAN DEFAULT false, - driving_side CHAR DEFAULT 'b', - details BOOLEAN DEFAULT false, - - OUT seq INTEGER, OUT path_id INTEGER, OUT path_seq INTEGER, - OUT node BIGINT, OUT edge BIGINT, - OUT cost FLOAT, OUT agg_cost FLOAT) -RETURNS SETOF RECORD AS -$BODY$ -BEGIN - RAISE WARNING 'pgr_withPointsKSP(text,text,bigint,bigint,integer,boolean,boolean,char,boolean) deprecated signature on v3.6.0'; - RETURN QUERY - SELECT a.seq, a.path_id, a.path_seq, a.node, a.edge, a.cost, a.agg_cost - FROM _pgr_withPointsKSP(_pgr_get_statement($1), _pgr_get_statement($2), $3, $4, $5, $6, $7, $8, $9) AS a; -END -$BODY$ -LANGUAGE plpgsql VOLATILE STRICT -COST 100 -ROWS 1000; - --- COMMENTS - -COMMENT ON FUNCTION pgr_withPointsKSP(TEXT, TEXT, BIGINT, BIGINT, INTEGER, BOOLEAN, BOOLEAN, CHAR, BOOLEAN) -IS 'pgr_withPointsKSP deprecated signature on v3.6.0 -- Documentation: ${PROJECT_DOC_LINK}/pgr_withPointsKSP.html'; diff --git a/sql/scripts/build-extension-update-files.pl b/sql/scripts/build-extension-update-files.pl index c30d98d5d99..89869e524a4 100755 --- a/sql/scripts/build-extension-update-files.pl +++ b/sql/scripts/build-extension-update-files.pl @@ -236,7 +236,6 @@ sub generate_upgrade_script { # updating to 3.6+ if ($old_minor < 3.6) { - push @commands, drop_special_case_function("pgr_withpointsksp(text, text, bigint, bigint, integer, boolean, boolean, char, boolean)"); push @commands, drop_special_case_function("pgr_astar(text,anyarray,bigint,boolean,integer,double precision,double precision)"); push @commands, drop_special_case_function("pgr_astar(text,bigint,anyarray,boolean,integer,double precision,double precision)"); push @commands, drop_special_case_function("pgr_astar(text,bigint,bigint,boolean,integer,double precision,double precision)"); diff --git a/sql/sigs/pgrouting--4.0.sig b/sql/sigs/pgrouting--4.0.sig index a37a17c4055..e139466f418 100644 --- a/sql/sigs/pgrouting--4.0.sig +++ b/sql/sigs/pgrouting--4.0.sig @@ -282,14 +282,12 @@ pgr_withpointsdd(text,text,anyarray,double precision,character,boolean,boolean,b pgr_withpointsdd(text,text,bigint,double precision,character,boolean,boolean) _pgr_withpointsddv4(text,text,anyarray,double precision,character,boolean,boolean,boolean) pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean) -_pgr_withpointsksp(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean,boolean) pgr_withpointsksp(text,text,anyarray,bigint,integer,character,boolean,boolean,boolean) pgr_withpointsksp(text,text,bigint,anyarray,integer,character,boolean,boolean,boolean) -_pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) -pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,character,boolean) pgr_withpointsksp(text,text,bigint,bigint,integer,character,boolean,boolean,boolean) -_pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean) pgr_withpointsksp(text,text,text,integer,character,boolean,boolean,boolean) +_pgr_withpointsksp_v4(text,text,anyarray,anyarray,integer,character,boolean,boolean,boolean) +_pgr_withpointsksp_v4(text,text,text,integer,character,boolean,boolean,boolean) pgr_withpoints(text,text,anyarray,anyarray,boolean,character,boolean) _pgr_withpoints(text,text,anyarray,anyarray,boolean,character,boolean,boolean,boolean) pgr_withpoints(text,text,anyarray,bigint,boolean,character,boolean) diff --git a/src/ksp/withPoints_ksp.c b/src/ksp/withPoints_ksp.c index 316bf102b58..00ad59ba75d 100644 --- a/src/ksp/withPoints_ksp.c +++ b/src/ksp/withPoints_ksp.c @@ -39,8 +39,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include "drivers/withPoints/get_new_queries.h" #include "drivers/yen/withPoints_ksp_driver.h" -PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1(_pgr_withpointsksp); +PGDLLEXPORT Datum _pgr_withpointsksp_v4(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_withpointsksp_v4); static void @@ -139,8 +139,119 @@ process( pgr_SPI_finish(); } +PGDLLEXPORT Datum _pgr_withpointsksp_v4(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + Path_rt *result_tuples = 0; + size_t result_count = 0; + + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + funcctx = SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + if (PG_NARGS() == 9) { + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + NULL, + PG_GETARG_ARRAYTYPE_P(2), + PG_GETARG_ARRAYTYPE_P(3), + NULL, NULL, + PG_GETARG_INT32(4), + text_to_cstring(PG_GETARG_TEXT_P(5)), + PG_GETARG_BOOL(6), + PG_GETARG_BOOL(7), + PG_GETARG_BOOL(8), + &result_tuples, + &result_count); + } else if (PG_NARGS() == 8) { + process( + text_to_cstring(PG_GETARG_TEXT_P(0)), + text_to_cstring(PG_GETARG_TEXT_P(1)), + text_to_cstring(PG_GETARG_TEXT_P(2)), + NULL, NULL, + NULL, NULL, + PG_GETARG_INT32(3), + text_to_cstring(PG_GETARG_TEXT_P(4)), + PG_GETARG_BOOL(5), + PG_GETARG_BOOL(6), + PG_GETARG_BOOL(7), + &result_tuples, + &result_count); + } + funcctx->max_calls = result_count; + funcctx->user_fctx = result_tuples; + if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("function returning record called in context that cannot accept type record"))); + } + + funcctx->tuple_desc = tuple_desc; + MemoryContextSwitchTo(oldcontext); + } + + funcctx = SRF_PERCALL_SETUP(); + tuple_desc = funcctx->tuple_desc; + result_tuples = (Path_rt*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + + size_t n = 9; + + values = palloc(n * sizeof(Datum)); + nulls = palloc(n * sizeof(bool)); + + size_t i; + for (i = 0; i < n; ++i) { + nulls[i] = false; + } + + int64_t path_id = 1; + if (funcctx->call_cntr != 0) { + if (result_tuples[funcctx->call_cntr - 1].edge == -1) { + path_id = result_tuples[funcctx->call_cntr - 1].start_id + 1; + } else { + path_id = result_tuples[funcctx->call_cntr - 1].start_id; + } + } + int64_t seq = funcctx->call_cntr == 0? 1 : result_tuples[funcctx->call_cntr - 1].end_id; + + values[0] = Int32GetDatum((int32_t)funcctx->call_cntr + 1); + values[1] = Int32GetDatum((int32_t)path_id); + values[2] = Int32GetDatum((int32_t)seq); + values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id); + values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id); + values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].node); + values[6] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge); + values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost); + values[8] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost); + + result_tuples[funcctx->call_cntr].start_id = path_id; + result_tuples[funcctx->call_cntr].end_id = result_tuples[funcctx->call_cntr].edge < 0? 1 : seq + 1; + + tuple = heap_form_tuple(tuple_desc, values, nulls); + result = HeapTupleGetDatum(tuple); + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); + } +} + +/* + * TODO (v5) v5 remove deprecated code + * TODO (v4 last micro) warn about deprecated code + */ +PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_withpointsksp); PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS) { FuncCallContext *funcctx; @@ -208,12 +319,12 @@ PGDLLEXPORT Datum _pgr_withpointsksp(PG_FUNCTION_ARGS) { funcctx->max_calls = result_count; funcctx->user_fctx = result_tuples; - if (get_call_result_type(fcinfo, NULL, &tuple_desc) - != TYPEFUNC_COMPOSITE) + if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context " "that cannot accept type record"))); + } funcctx->tuple_desc = tuple_desc; MemoryContextSwitchTo(oldcontext); diff --git a/tools/testers/general_pgtap_tests.sql b/tools/testers/general_pgtap_tests.sql index 3c71b21a622..c329e76f1ce 100644 --- a/tools/testers/general_pgtap_tests.sql +++ b/tools/testers/general_pgtap_tests.sql @@ -113,7 +113,7 @@ RETURNS TEXT AS $BODY$ SELECT set_has(format($$ SELECT proargnames from pg_catalog.pg_proc where proname = '%1$s' - $$, $1), $2, $1 || ': Function args names'); + $$, $1), $2, $1 || ': Function has args names'); $BODY$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION function_returns_geom(TEXT)