Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed pgr_pointsAsPolygon breaking when comparing strings in WHERE clause #1193

Merged
merged 3 commits into from
Mar 29, 2019
Merged

Conversation

iboates
Copy link
Contributor

@iboates iboates commented Mar 8, 2019

Fixes #1192 .

Changes proposed in this pull request:

  • Replace single quotes in the query passed to pgr_pointsAsPolygon() with escaped quotes, stopping a failure if a string comparison is specified in its WHERE clause in the subsequent call to pgr_alphaShape()

@pgRouting/admins

@iboates iboates changed the title fixed pgr_alphashape breaking when comparing strings in WHERE clause fixed pgr_pointsAsPolygon breaking when comparing strings in WHERE clause Mar 8, 2019
@iboates
Copy link
Contributor Author

iboates commented Mar 8, 2019

You can use this query to test with & without this update.

Before, it should throw a syntax error from pgr_alphaShape. After, it should execute as normal.

CREATE TABLE public.alphashape_fix_points (
    id bigint,
    text_col text,
    the_geom public.geometry(Point,3003)
);

INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (314, 'bar', '0101000020BB0B000021D0019EC1DC34417032CFFC89E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (102, 'foo', '0101000020BB0B0000BC9FD33AB2DC34418E9F3117A0E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (154, 'foo', '0101000020BB0B000095F46493E8DC3441C12686009EE55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (155, 'foo', '0101000020BB0B00001323185411DD34416C91D66695E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (156, 'foo', '0101000020BB0B0000C6003C87D0DC3441AF61D39E90E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (157, 'foo', '0101000020BB0B00008A7AD07FFADC3441301C9D128BE55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (161, 'foo', '0101000020BB0B00000E23A4F1E0DC34416B866E7FA2E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (190, 'bar', '0101000020BB0B0000C90607B0DBDC3441B94BD31B97E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (191, 'bar', '0101000020BB0B0000F438DD6204DD3441D064C81E91E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (237, 'bar', '0101000020BB0B0000734B2DA702DD34416F1074FD8FE55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (251, 'bar', '0101000020BB0B0000B77FE51FF4DC34415AC8EBFE83E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (276, 'bar', '0101000020BB0B0000AE212EF2EBDC344101CE9DA2A0E55241');
INSERT INTO public.alphashape_fix_points (id, text_col, the_geom) VALUES (285, 'bar', '0101000020BB0B00003E7ECA0CCCDC34414BF56E23A1E55241');

SELECT
    pgr_pointsAsPolygon(
        'SELECT
            id::INT4,
            ST_X(the_geom)::float AS x,
            ST_Y(the_geom)::float AS y
        FROM
            work.cur_net_vertices_pgr
        WHERE
            text_col =  ''foo'';'
);

@cvvergara cvvergara added this to the Release 2.7.0 milestone Mar 8, 2019
@cvvergara
Copy link
Member

Hello @iboates
I really don't understand the error being fixed, but I trust you :)

There is a typo on a test file (I really dont know how it came to pgRouting
https://github.com/pgRouting/pgrouting/blob/master/pgtap/common/hasnt_v2_signatures.sql#L33
Can you change from this:

SELECT hasnt_function('pgr_tsp',ARRAY['(double precision[]', 'integer', 'integer']);

to this

SELECT hasnt_function('pgr_tsp',ARRAY['double precision[]', 'integer', 'integer']);

in your PR, so that tests pass and then I am able to merge please

FYI,
This function will be deprecated on v3.0.0
because of #1188

I would really appreciate if you try the new function on some real data
https://docs.pgrouting.org/dev/en/pgr_alphaShape.html

@iboates
Copy link
Contributor Author

iboates commented Mar 9, 2019

@cvvergara Is there still a separate function for pgr_alphaShape and pgr_pointsFromPolygon? All I see is a single function for pgr_alphaShape here: https://github.com/pgRouting/pgrouting/blob/develop/sql/alpha_shape/alphaShape.sql

@cvvergara
Copy link
Member

cvvergara commented Mar 9, 2019

@iboates
we are only keeping one function
when those functions were introduced:
pgr_pointsAsPolygons calls the pgr_alphaShape that does the calculation, like the backend, but with the name pgr_pointsAsPolygons it could easily call ST_ConcaveHull which gives a polygon as result or ST_ConvexHull which also give a polygon as result.

_pgr_alphaShape (its the backend & does the calculation) & pgr_alphaShape(pre calculates the delauny triangles and calls the backend function) <--- so things look like this now (on v3.0.0 for sep)

@iboates
Copy link
Contributor Author

iboates commented Mar 24, 2019

@cvvergara I tested on the 3.0.0 development docker image and it is no longer an issue. The fact that the geometry is passed directly and not via a SQL string means that there is no problem with characters becoming unescaped.

@iboates
Copy link
Contributor Author

iboates commented Mar 24, 2019

@cvvergara Tests now pass

@cvvergara cvvergara merged commit 72c1e3d into pgRouting:master Mar 29, 2019
@cvvergara cvvergara modified the milestones: Release 2.7.0, Release 2.6.3 Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pgr_pointsAsPolygon doesn't play nice if you have string comparisons in the WHERE clause
2 participants