Skip to content

Commit

Permalink
(SQL) _pgr_withPointsVia: removal of deprecated internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvergara committed Feb 6, 2025
1 parent 54dc6d8 commit 99b4f25
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 148 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ 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)
* _trsp(text,text,anyarray,anyarray,boolean)
* _v4trsp(text,text,anyarray,anyarray,boolean)
* _v4trsp(text,text,text,boolean)
Expand Down
1 change: 1 addition & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ 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)
* _trsp(text,text,anyarray,anyarray,boolean)
* _v4trsp(text,text,anyarray,anyarray,boolean)
* _v4trsp(text,text,text,boolean)
Expand Down
1 change: 0 additions & 1 deletion sql/sigs/pgrouting--4.0.sig
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,5 @@ pgr_withpoints(text,text,bigint,anyarray,boolean,character,boolean)
pgr_withpoints(text,text,bigint,bigint,boolean,character,boolean)
pgr_withpoints(text,text,text,boolean,character,boolean)
_pgr_withpoints(text,text,text,boolean,character,boolean,boolean)
_pgr_withpointsvia(text,bigint[],double precision[],boolean)
_pgr_withpointsvia(text,text,anyarray,boolean,boolean,boolean,character,boolean)
pgr_withpointsvia(text,text,anyarray,boolean,boolean,boolean,character,boolean)
147 changes: 0 additions & 147 deletions sql/withPoints/withPointsVia.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,150 +77,3 @@ IS 'pgr_withPointsVia
- Documentation:
- ${PROJECT_DOC_LINK}/pgr_withPointsVia.html
';

--v2.6
CREATE FUNCTION _pgr_withPointsVia(
sql TEXT,
via_edges BIGINT[],
fraction FLOAT[],
directed BOOLEAN DEFAULT TRUE,

OUT seq INTEGER,
OUT path_id INTEGER,
OUT path_seq INTEGER,
OUT start_vid BIGINT,
OUT end_vid BIGINT,
OUT node BIGINT,
OUT edge BIGINT,
OUT cost FLOAT,
OUT agg_cost FLOAT,
OUT route_agg_cost FLOAT)

RETURNS SETOF RECORD AS
$BODY$
DECLARE
has_rcost boolean;
sql_new_vertices text := ' ';
sql_on_vertex text;
v_union text := ' ';
dummyrec record;
rec1 record;
via_vertices int[];
sql_safe text;
new_edges text;
BEGIN
BEGIN
sql_safe = 'SELECT id, source, target, cost, reverse_cost FROM ('|| sql || ') AS __a';

EXECUTE 'select reverse_cost, pg_typeof(reverse_cost)::text as rev_type from ('||sql_safe||' ) AS __b__ limit 1 ' INTO rec1;
has_rcost := true;
EXCEPTION
WHEN OTHERS THEN
has_rcost = false;
END;


IF array_length(via_edges, 1) != array_length(fraction, 1) then
RAISE EXCEPTION 'The length of via_edges is different of length of via_edges';
END IF;

FOR i IN 1 .. array_length(via_edges, 1)
LOOP
IF fraction[i] = 0 THEN
sql_on_vertex := 'SELECT source FROM ('|| sql || ') __a where id = ' || via_edges[i];
EXECUTE sql_on_vertex into dummyrec;
via_vertices[i] = dummyrec.source;
ELSE IF fraction[i] = 1 THEN
sql_on_vertex := 'SELECT target FROM ('|| sql || ') __a where id = ' || via_edges[i];
EXECUTE sql_on_vertex into dummyrec;
via_vertices[i] = dummyrec.target;
ELSE
via_vertices[i] = -i;
IF has_rcost THEN
sql_new_vertices = sql_new_vertices || v_union ||
'(SELECT id, source, ' || -i || ' AS target, cost * ' || fraction[i] || ' AS cost,
reverse_cost * (1 - ' || fraction[i] || ') AS reverse_cost
FROM (SELECT * FROM (' || sql || ') __b' || i || ' WHERE id = ' || via_edges[i] || ') __a' || i ||')
UNION
(SELECT id, ' || -i || ' AS source, target, cost * (1 -' || fraction[i] || ') AS cost,
reverse_cost * ' || fraction[i] || ' AS reverse_cost
FROM (SELECT * FROM (' || sql || ') __b' || i || ' where id = ' || via_edges[i] || ') __a' || i ||')';
v_union = ' UNION ';
ELSE
sql_new_vertices = sql_new_vertices || v_union ||
'(SELECT id, source, ' || -i || ' AS target, cost * ' || fraction[i] || ' AS cost
FROM (SELECT * FROM (' || sql || ') __b' || i || ' WHERE id = ' || via_edges[i] || ') __a' || i ||')
UNION
(SELECT id, ' || -i || ' AS source, target, cost * (1 -' || fraction[i] || ') AS cost
FROM (SELECT * FROM (' || sql || ') __b' || i || ' WHERE id = ' || via_edges[i] || ') __a' || i ||')';
v_union = ' UNION ';
END IF;
END IF;
END IF;
END LOOP;

IF sql_new_vertices = ' ' THEN
new_edges := sql;
ELSE
IF has_rcost THEN
new_edges:= 'WITH
orig AS ( ' || sql || '),
original AS (SELECT id, source, target, cost, reverse_cost FROM orig),
the_union AS ( ' || sql_new_vertices || '),
first_part AS ( SELECT * FROM (SELECT id, target AS source, lead(target) OVER w AS target,
lead(cost) OVER w - cost AS cost,
lead(cost) OVER w - cost AS reverse_cost
FROM the_union WHERE source > 0 AND cost > 0
WINDOW w AS (PARTITION BY id ORDER BY cost ASC) ) as n2
WHERE target IS NOT NULL),
second_part AS ( SELECT * FROM (SELECT id, lead(source) OVER w AS source, source as target,
reverse_cost - lead(reverse_cost) OVER w AS cost,
reverse_cost - lead(reverse_cost) OVER w AS reverse_cost
FROM the_union WHERE target > 0 and reverse_cost > 0
WINDOW w AS (PARTITION BY id ORDER BY reverse_cost ASC) ) as n2
WHERE source IS NOT NULL),
more_union AS ( SELECT * from (
(SELECT * FROM original)
UNION
(SELECT * FROM the_union)
UNION
(SELECT * FROM first_part)
UNION
(SELECT * FROM second_part) ) _union )
SELECT * FROM more_union';
ELSE
new_edges:= 'WITH
orig AS ( ' || sql || '),
original AS (SELECT id, source, target, cost FROM orig),
the_union AS ( ' || sql_new_vertices || '),
first_part AS ( SELECT * FROM (SELECT id, target AS source, lead(target) OVER w AS target,
lead(cost) OVER w - cost AS cost
FROM the_union WHERE source > 0 AND cost > 0
WINDOW w AS (PARTITION BY id ORDER BY cost ASC) ) as n2
WHERE target IS NOT NULL ),
more_union AS ( SELECT * from (
(SELECT * FROM original)
UNION
(SELECT * FROM the_union)
UNION
(SELECT * FROM first_part) ) _union )
SELECT * FROM more_union';
END IF;
END IF;

sql_new_vertices := sql_new_vertices || v_union || ' (' || sql || ')';

RETURN query SELECT *
FROM pgr_dijkstraVia(new_edges, via_vertices, directed, has_rcost);
END
$BODY$
LANGUAGE plpgsql VOLATILE STRICT
COST 100
ROWS 1000;


-- COMMENTS


COMMENT ON FUNCTION _pgr_withPointsVia(TEXT, BIGINT[], FLOAT[], BOOLEAN)
IS 'pgRouting internal function deprecated on v3.4.0';

0 comments on commit 99b4f25

Please sign in to comment.