From cb19a8ca08ab0ded5e5e4272228074167c794447 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:06:50 +0100 Subject: [PATCH 01/13] Adds postalcode with country --- .../expected/80_postalcode_point_test.out | 32 +++++++++++++ .../sql/0.0.1/80_postalcode_point.sql | 48 +++++++++++++++++++ .../sql/80_postalcode_point_test.sql | 33 +++++++++++++ 3 files changed, 113 insertions(+) diff --git a/server/extension/expected/80_postalcode_point_test.out b/server/extension/expected/80_postalcode_point_test.out index cb43d40..4044d30 100644 --- a/server/extension/expected/80_postalcode_point_test.out +++ b/server/extension/expected/80_postalcode_point_test.out @@ -1,3 +1,8 @@ +-- Make sure dbs are clean +DELETE FROM global_postal_code_points; +DELETE FROM country_decoder; +DELETE FROM available_services; +DELETE FROM admin0_synonyms; -- Check that the public function is callable, even with no data -- It should return NULL SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); @@ -13,6 +18,22 @@ INSERT INTO global_postal_code_points (the_geom, iso3, postal_code, postal_code_ '03204', 3204 ); +INSERT INTO country_decoder (iso3, synonyms) VALUES ( + 'ESP', + Array['spain', 'Spain', 'ESP'] +); +INSERT INTO available_services (adm0_a3, admin0, postal_code_points, postal_code_polygons) VALUES ( + 'ESP', + 't', + 't', + 't' +); +INSERT INTO admin0_synonyms (adm0_a3, name, name_, rank) VALUES ( + 'ESP', + 'Spain', + 'spain', + 3 +); -- This should return the polygon inserted above SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); geocode_postalcode_point @@ -20,3 +41,14 @@ SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current() 0101000020E61000000000000000E040408036B47414764840 (1 row) +SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204', 'spain'); + geocode_postalcode_point +---------------------------------------------------- + 0101000020E61000000000000000E040408036B47414764840 +(1 row) + +-- Clean dbs +DELETE FROM global_postal_code_points; +DELETE FROM country_decoder; +DELETE FROM available_services; +DELETE FROM admin0_synonyms; diff --git a/server/extension/sql/0.0.1/80_postalcode_point.sql b/server/extension/sql/0.0.1/80_postalcode_point.sql index 3b67843..b86930f 100644 --- a/server/extension/sql/0.0.1/80_postalcode_point.sql +++ b/server/extension/sql/0.0.1/80_postalcode_point.sql @@ -1,3 +1,5 @@ +-- TODO geocode_postalcode_polygon(code text, country text) + -- Interface of the server extension CREATE OR REPLACE FUNCTION geocode_postalcode_point(user_id NAME, tx_id BIGINT, code text) @@ -21,6 +23,27 @@ RETURNS Geometry AS $$ return rv[0]["point"] $$ LANGUAGE plpythonu; +CREATE OR REPLACE FUNCTION geocode_postalcode_point(user_id NAME, tx_id BIGINT, code text, country text) +RETURNS Geometry AS $$ + plpy.debug('Entering _geocode_postalcode_point') + plpy.debug('user_id = %s' % user_id) + + #-- Access control + #-- TODO: this should be part of cdb python library + if user_id == 'publicuser': + plpy.error('The api_key must be provided') + + #--TODO: rate limiting check + #--TODO: quota check + + #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"]) + rv = plpy.execute(plan, [code, country], 1) + + plpy.debug('Returning from _geocode_postalcode_point') + return rv[0]["point"] +$$ LANGUAGE plpythonu; + -------------------------------------------------------------------------------- @@ -46,3 +69,28 @@ RETURNS Geometry AS $$ RETURN ret; END $$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION _geocode_postalcode_point(code text, country text) +RETURNS Geometry AS $$ + DECLARE + ret Geometry; + BEGIN + SELECT geom INTO ret + FROM ( + SELECT + q, ( + SELECT the_geom + FROM global_postal_code_points + WHERE postal_code = upper(d.q) + AND iso3 = ( + SELECT iso3 FROM country_decoder WHERE + lower(country) = ANY (synonyms) LIMIT 1 + ) + LIMIT 1 + ) geom + FROM (SELECT code q) d + ) v; + + RETURN ret; +END +$$ LANGUAGE plpgsql; diff --git a/server/extension/sql/80_postalcode_point_test.sql b/server/extension/sql/80_postalcode_point_test.sql index a6e986f..3293178 100644 --- a/server/extension/sql/80_postalcode_point_test.sql +++ b/server/extension/sql/80_postalcode_point_test.sql @@ -1,3 +1,9 @@ +-- Make sure dbs are clean +DELETE FROM global_postal_code_points; +DELETE FROM country_decoder; +DELETE FROM available_services; +DELETE FROM admin0_synonyms; + -- Check that the public function is callable, even with no data -- It should return NULL SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); @@ -10,5 +16,32 @@ INSERT INTO global_postal_code_points (the_geom, iso3, postal_code, postal_code_ 3204 ); +INSERT INTO country_decoder (iso3, synonyms) VALUES ( + 'ESP', + Array['spain', 'Spain', 'ESP'] +); + +INSERT INTO available_services (adm0_a3, admin0, postal_code_points, postal_code_polygons) VALUES ( + 'ESP', + 't', + 't', + 't' +); + +INSERT INTO admin0_synonyms (adm0_a3, name, name_, rank) VALUES ( + 'ESP', + 'Spain', + 'spain', + 3 +); + -- This should return the polygon inserted above SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); + +SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204', 'spain'); + +-- Clean dbs +DELETE FROM global_postal_code_points; +DELETE FROM country_decoder; +DELETE FROM available_services; +DELETE FROM admin0_synonyms; From 20cc610da57ee53448d83285d862a9873e0e3a94 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:20:12 +0100 Subject: [PATCH 02/13] Adds postalcode polygon and renames --- .../expected/60_postalcodes_test.out | 74 ++++++++++++++++ ...90_geocode_ip_test.out => 70_ips_test.out} | 0 .../expected/80_postalcode_point_test.out | 54 ------------ ...ostalcode_point.sql => 60_postalcodes.sql} | 88 +++++++++++++++++++ .../0.0.1/{90_geocode_ip.sql => 70_ips.sql} | 0 ...point_test.sql => 60_postalcodes_test.sql} | 13 +++ ...90_geocode_ip_test.sql => 70_ips_test.sql} | 0 7 files changed, 175 insertions(+), 54 deletions(-) create mode 100644 server/extension/expected/60_postalcodes_test.out rename server/extension/expected/{90_geocode_ip_test.out => 70_ips_test.out} (100%) delete mode 100644 server/extension/expected/80_postalcode_point_test.out rename server/extension/sql/0.0.1/{80_postalcode_point.sql => 60_postalcodes.sql} (52%) rename server/extension/sql/0.0.1/{90_geocode_ip.sql => 70_ips.sql} (100%) rename server/extension/sql/{80_postalcode_point_test.sql => 60_postalcodes_test.sql} (68%) rename server/extension/sql/{90_geocode_ip_test.sql => 70_ips_test.sql} (100%) diff --git a/server/extension/expected/60_postalcodes_test.out b/server/extension/expected/60_postalcodes_test.out new file mode 100644 index 0000000..f777d2b --- /dev/null +++ b/server/extension/expected/60_postalcodes_test.out @@ -0,0 +1,74 @@ +-- Make sure dbs are clean +DELETE FROM global_postal_code_points; +DELETE FROM global_postal_code_polygons; +DELETE FROM country_decoder; +DELETE FROM available_services; +DELETE FROM admin0_synonyms; +-- Check that the public function is callable, even with no data +-- It should return NULL +SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); + geocode_postalcode_point +-------------------------- + +(1 row) + +-- Insert dummy data into ip_address_locations +INSERT INTO global_postal_code_points (the_geom, iso3, postal_code, postal_code_num) VALUES ( + '0101000020E61000000000000000E040408036B47414764840', + 'ESP', + '03204', + 3204 +); +INSERT INTO global_postal_code_polygons (the_geom, iso3, postal_code, postal_code_num) VALUES ( + '0106000020E610000001000000010300000001000000040000000000000000E000C01F383D7839B740400000000000E000C0AA3C0EDE220F3B4000000000004812404FB7FCCD04893D400000000000E000C01F383D7839B74040', + 'ESP', + '03204', + 3204 +); +INSERT INTO country_decoder (iso3, synonyms) VALUES ( + 'ESP', + Array['spain', 'Spain', 'ESP'] +); +INSERT INTO available_services (adm0_a3, admin0, postal_code_points, postal_code_polygons) VALUES ( + 'ESP', + 't', + 't', + 't' +); +INSERT INTO admin0_synonyms (adm0_a3, name, name_, rank) VALUES ( + 'ESP', + 'Spain', + 'spain', + 3 +); +-- This should return the polygon inserted above +SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); + geocode_postalcode_point +---------------------------------------------------- + 0101000020E61000000000000000E040408036B47414764840 +(1 row) + +SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204', 'spain'); + geocode_postalcode_point +---------------------------------------------------- + 0101000020E61000000000000000E040408036B47414764840 +(1 row) + +SELECT cdb_geocoder_server.geocode_postalcode_polygon(session_user, txid_current(), '03204'); + geocode_postalcode_polygon +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 0106000020E610000001000000010300000001000000040000000000000000E000C01F383D7839B740400000000000E000C0AA3C0EDE220F3B4000000000004812404FB7FCCD04893D400000000000E000C01F383D7839B74040 +(1 row) + +SELECT cdb_geocoder_server.geocode_postalcode_polygon(session_user, txid_current(), '03204', 'spain'); + geocode_postalcode_polygon +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 0106000020E610000001000000010300000001000000040000000000000000E000C01F383D7839B740400000000000E000C0AA3C0EDE220F3B4000000000004812404FB7FCCD04893D400000000000E000C01F383D7839B74040 +(1 row) + +-- Clean dbs +DELETE FROM global_postal_code_points; +DELETE FROM global_postal_code_polygons; +DELETE FROM country_decoder; +DELETE FROM available_services; +DELETE FROM admin0_synonyms; diff --git a/server/extension/expected/90_geocode_ip_test.out b/server/extension/expected/70_ips_test.out similarity index 100% rename from server/extension/expected/90_geocode_ip_test.out rename to server/extension/expected/70_ips_test.out diff --git a/server/extension/expected/80_postalcode_point_test.out b/server/extension/expected/80_postalcode_point_test.out deleted file mode 100644 index 4044d30..0000000 --- a/server/extension/expected/80_postalcode_point_test.out +++ /dev/null @@ -1,54 +0,0 @@ --- Make sure dbs are clean -DELETE FROM global_postal_code_points; -DELETE FROM country_decoder; -DELETE FROM available_services; -DELETE FROM admin0_synonyms; --- Check that the public function is callable, even with no data --- It should return NULL -SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); - geocode_postalcode_point --------------------------- - -(1 row) - --- Insert dummy data into ip_address_locations -INSERT INTO global_postal_code_points (the_geom, iso3, postal_code, postal_code_num) VALUES ( - '0101000020E61000000000000000E040408036B47414764840', - 'ESP', - '03204', - 3204 -); -INSERT INTO country_decoder (iso3, synonyms) VALUES ( - 'ESP', - Array['spain', 'Spain', 'ESP'] -); -INSERT INTO available_services (adm0_a3, admin0, postal_code_points, postal_code_polygons) VALUES ( - 'ESP', - 't', - 't', - 't' -); -INSERT INTO admin0_synonyms (adm0_a3, name, name_, rank) VALUES ( - 'ESP', - 'Spain', - 'spain', - 3 -); --- This should return the polygon inserted above -SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204'); - geocode_postalcode_point ----------------------------------------------------- - 0101000020E61000000000000000E040408036B47414764840 -(1 row) - -SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204', 'spain'); - geocode_postalcode_point ----------------------------------------------------- - 0101000020E61000000000000000E040408036B47414764840 -(1 row) - --- Clean dbs -DELETE FROM global_postal_code_points; -DELETE FROM country_decoder; -DELETE FROM available_services; -DELETE FROM admin0_synonyms; diff --git a/server/extension/sql/0.0.1/80_postalcode_point.sql b/server/extension/sql/0.0.1/60_postalcodes.sql similarity index 52% rename from server/extension/sql/0.0.1/80_postalcode_point.sql rename to server/extension/sql/0.0.1/60_postalcodes.sql index b86930f..ca76a8d 100644 --- a/server/extension/sql/0.0.1/80_postalcode_point.sql +++ b/server/extension/sql/0.0.1/60_postalcodes.sql @@ -44,6 +44,48 @@ RETURNS Geometry AS $$ return rv[0]["point"] $$ LANGUAGE plpythonu; +CREATE OR REPLACE FUNCTION geocode_postalcode_polygon(user_id NAME, tx_id BIGINT, code text) +RETURNS Geometry AS $$ + plpy.debug('Entering _geocode_postalcode_polygon') + plpy.debug('user_id = %s' % user_id) + + #-- Access control + #-- TODO: this should be part of cdb python library + if user_id == 'publicuser': + plpy.error('The api_key must be provided') + + #--TODO: rate limiting check + #--TODO: quota check + + #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_postalcode_polygon($1) AS polygon", ["text"]) + rv = plpy.execute(plan, [code], 1) + + plpy.debug('Returning from _geocode_postalcode_polygon') + return rv[0]["polygon"] +$$ LANGUAGE plpythonu; + +CREATE OR REPLACE FUNCTION geocode_postalcode_polygon(user_id NAME, tx_id BIGINT, code text, country text) +RETURNS Geometry AS $$ + plpy.debug('Entering _geocode_postalcode_point') + plpy.debug('user_id = %s' % user_id) + + #-- Access control + #-- TODO: this should be part of cdb python library + if user_id == 'publicuser': + plpy.error('The api_key must be provided') + + #--TODO: rate limiting check + #--TODO: quota check + + #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"]) + rv = plpy.execute(plan, [code, country], 1) + + plpy.debug('Returning from _geocode_postalcode_point') + return rv[0]["polygon"] +$$ LANGUAGE plpythonu; + -------------------------------------------------------------------------------- @@ -94,3 +136,49 @@ RETURNS Geometry AS $$ RETURN ret; END $$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION _geocode_postalcode_polygon(code text) +RETURNS Geometry AS $$ + DECLARE + ret Geometry; + BEGIN + SELECT geom INTO ret + FROM ( + SELECT + q, ( + SELECT the_geom + FROM global_postal_code_polygons + WHERE postal_code = upper(d.q) + LIMIT 1 + ) geom + FROM (SELECT code q) d + ) v; + + RETURN ret; +END +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION _geocode_postalcode_polygon(code text, country text) +RETURNS Geometry AS $$ + DECLARE + ret Geometry; + BEGIN + SELECT geom INTO ret + FROM ( + SELECT + q, ( + SELECT the_geom + FROM global_postal_code_polygons + WHERE postal_code = upper(d.q) + AND iso3 = ( + SELECT iso3 FROM country_decoder WHERE + lower(country) = ANY (synonyms) LIMIT 1 + ) + LIMIT 1 + ) geom + FROM (SELECT code q) d + ) v; + + RETURN ret; +END +$$ LANGUAGE plpgsql; diff --git a/server/extension/sql/0.0.1/90_geocode_ip.sql b/server/extension/sql/0.0.1/70_ips.sql similarity index 100% rename from server/extension/sql/0.0.1/90_geocode_ip.sql rename to server/extension/sql/0.0.1/70_ips.sql diff --git a/server/extension/sql/80_postalcode_point_test.sql b/server/extension/sql/60_postalcodes_test.sql similarity index 68% rename from server/extension/sql/80_postalcode_point_test.sql rename to server/extension/sql/60_postalcodes_test.sql index 3293178..f822d0f 100644 --- a/server/extension/sql/80_postalcode_point_test.sql +++ b/server/extension/sql/60_postalcodes_test.sql @@ -1,5 +1,6 @@ -- Make sure dbs are clean DELETE FROM global_postal_code_points; +DELETE FROM global_postal_code_polygons; DELETE FROM country_decoder; DELETE FROM available_services; DELETE FROM admin0_synonyms; @@ -16,6 +17,13 @@ INSERT INTO global_postal_code_points (the_geom, iso3, postal_code, postal_code_ 3204 ); +INSERT INTO global_postal_code_polygons (the_geom, iso3, postal_code, postal_code_num) VALUES ( + '0106000020E610000001000000010300000001000000040000000000000000E000C01F383D7839B740400000000000E000C0AA3C0EDE220F3B4000000000004812404FB7FCCD04893D400000000000E000C01F383D7839B74040', + 'ESP', + '03204', + 3204 +); + INSERT INTO country_decoder (iso3, synonyms) VALUES ( 'ESP', Array['spain', 'Spain', 'ESP'] @@ -40,8 +48,13 @@ SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current() SELECT cdb_geocoder_server.geocode_postalcode_point(session_user, txid_current(), '03204', 'spain'); +SELECT cdb_geocoder_server.geocode_postalcode_polygon(session_user, txid_current(), '03204'); + +SELECT cdb_geocoder_server.geocode_postalcode_polygon(session_user, txid_current(), '03204', 'spain'); + -- Clean dbs DELETE FROM global_postal_code_points; +DELETE FROM global_postal_code_polygons; DELETE FROM country_decoder; DELETE FROM available_services; DELETE FROM admin0_synonyms; diff --git a/server/extension/sql/90_geocode_ip_test.sql b/server/extension/sql/70_ips_test.sql similarity index 100% rename from server/extension/sql/90_geocode_ip_test.sql rename to server/extension/sql/70_ips_test.sql From b71947bad06daa15ae78cf8e4cdc59940806fe8e Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:29:25 +0100 Subject: [PATCH 03/13] Fixes plural forms --- server/extension/expected/30_admin0_test.out | 10 +++--- server/extension/expected/40_admin1_test.out | 20 +++++------ .../expected/50_namedplaces_test.out | 30 ++++++++-------- .../extension/sql/0.0.1/20_geocode_street.sql | 2 +- server/extension/sql/0.0.1/30_admin0.sql | 6 ++-- server/extension/sql/0.0.1/40_admin1.sql | 26 +++++++------- server/extension/sql/0.0.1/50_namedplaces.sql | 36 +++++++++---------- server/extension/sql/30_admin0_test.sql | 4 +-- server/extension/sql/40_admin1_test.sql | 8 ++--- server/extension/sql/50_namedplaces_test.sql | 14 ++++---- 10 files changed, 78 insertions(+), 78 deletions(-) diff --git a/server/extension/expected/30_admin0_test.out b/server/extension/expected/30_admin0_test.out index 12ba5b6..4b455a5 100644 --- a/server/extension/expected/30_admin0_test.out +++ b/server/extension/expected/30_admin0_test.out @@ -1,8 +1,8 @@ -- Check that the public function is callable, even with no data -- It should return NULL -SELECT cdb_geocoder_server.geocode_admin0_polygons(session_user, txid_current(), 'Spain'); - geocode_admin0_polygons -------------------------- +SELECT cdb_geocoder_server.geocode_admin0_polygon(session_user, txid_current(), 'Spain'); + geocode_admin0_polygon +------------------------ (1 row) @@ -16,8 +16,8 @@ INSERT INTO ne_admin0_v3 (adm0_a3, the_geom) VALUES('ESP', ST_GeomFromText( -71.1031880899493 42.3152774590236))',4326) ); -- This should return the polygon inserted above -SELECT cdb_geocoder_server.geocode_admin0_polygons(session_user, txid_current(), 'Spain'); - geocode_admin0_polygons +SELECT cdb_geocoder_server.geocode_admin0_polygon(session_user, txid_current(), 'Spain'); + geocode_admin0_polygon -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0103000020E61000000100000004000000D0EA37A29AC651C00FD603035B284540FEFCFB379AC651C0C0503E9F5B284540FFDDDD4D96C651C033AC3B284F284540D0EA37A29AC651C00FD603035B284540 (1 row) diff --git a/server/extension/expected/40_admin1_test.out b/server/extension/expected/40_admin1_test.out index 1e5cdc6..7bb29c6 100644 --- a/server/extension/expected/40_admin1_test.out +++ b/server/extension/expected/40_admin1_test.out @@ -1,14 +1,14 @@ -- Check that the public function is callable, even with no data -- It should return NULL -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California'); - geocode_admin1_polygons -------------------------- +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California'); + geocode_admin1_polygon +------------------------ (1 row) -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California', 'United States'); - geocode_admin1_polygons -------------------------- +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California', 'United States'); + geocode_admin1_polygon +------------------------ (1 row) @@ -22,14 +22,14 @@ INSERT INTO global_province_polygons (synonyms, iso3, the_geom) VALUES (Array['c -71.1031880899493 42.3152774590236))',4326) ); -- This should return the polygon inserted above -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California'); - geocode_admin1_polygons +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California'); + geocode_admin1_polygon -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0103000020E61000000100000004000000D0EA37A29AC651C00FD603035B284540FEFCFB379AC651C0C0503E9F5B284540FFDDDD4D96C651C033AC3B284F284540D0EA37A29AC651C00FD603035B284540 (1 row) -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California', 'United States'); - geocode_admin1_polygons +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California', 'United States'); + geocode_admin1_polygon -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0103000020E61000000100000004000000D0EA37A29AC651C00FD603035B284540FEFCFB379AC651C0C0503E9F5B284540FFDDDD4D96C651C033AC3B284F284540D0EA37A29AC651C00FD603035B284540 (1 row) diff --git a/server/extension/expected/50_namedplaces_test.out b/server/extension/expected/50_namedplaces_test.out index 2c1c49c..c8e6c15 100644 --- a/server/extension/expected/50_namedplaces_test.out +++ b/server/extension/expected/50_namedplaces_test.out @@ -1,8 +1,8 @@ -- Check that the public function is callable, even with no data -- It should return NULL -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx'); - geocode_namedplace --------------------- +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); + geocode_namedplace_point +-------------------------- (1 row) @@ -19,38 +19,38 @@ INSERT INTO country_decoder (synonyms, iso2) VALUES (Array['spain'], 'ES'); -- Insert dummy data into admin1 decoder table INSERT INTO admin1_decoder (admin1, synonyms, iso2) VALUES ('Valencia', Array['valencia', 'Valencia'], 'ES'); -- This should return the point inserted above -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx'); - geocode_namedplace +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); + geocode_namedplace_point ---------------------------------------------------- 0101000020E6100000637FD93D7958E63F2ECA6C9049A24340 (1 row) -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche'); - geocode_namedplace +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche'); + geocode_namedplace_point ---------------------------------------------------- 0101000020E6100000637FD93D7958E63F2ECA6C9049A24340 (1 row) -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Spain'); - geocode_namedplace +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Spain'); + geocode_namedplace_point ---------------------------------------------------- 0101000020E6100000637FD93D7958E63F2ECA6C9049A24340 (1 row) -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'Spain'); - geocode_namedplace +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'Spain'); + geocode_namedplace_point ---------------------------------------------------- 0101000020E6100000637FD93D7958E63F2ECA6C9049A24340 (1 row) -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); - geocode_namedplace +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); + geocode_namedplace_point ---------------------------------------------------- 0101000020E6100000637FD93D7958E63F2ECA6C9049A24340 (1 row) -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); - geocode_namedplace +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); + geocode_namedplace_point ---------------------------------------------------- 0101000020E6100000637FD93D7958E63F2ECA6C9049A24340 (1 row) diff --git a/server/extension/sql/0.0.1/20_geocode_street.sql b/server/extension/sql/0.0.1/20_geocode_street.sql index 4bb7ebb..73ce23c 100644 --- a/server/extension/sql/0.0.1/20_geocode_street.sql +++ b/server/extension/sql/0.0.1/20_geocode_street.sql @@ -1,5 +1,5 @@ -- Geocodes a street address given a searchtext and a state and/or country -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_street(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ import json diff --git a/server/extension/sql/0.0.1/30_admin0.sql b/server/extension/sql/0.0.1/30_admin0.sql index c5e4ed6..bb1fc2f 100644 --- a/server/extension/sql/0.0.1/30_admin0.sql +++ b/server/extension/sql/0.0.1/30_admin0.sql @@ -1,6 +1,6 @@ -- Interface of the server extension -CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygons(user_id name, tx_id bigint, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_admin0_polygon(user_id name, tx_id bigint, country_name text) RETURNS Geometry AS $$ plpy.debug('Entering geocode_admin0_polygons') plpy.debug('user_id = %s' % user_id) @@ -14,7 +14,7 @@ RETURNS Geometry AS $$ #--TODO: quota check #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html - plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_admin0_polygons($1) AS mypolygon", ["text"]) + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_admin0_polygon($1) AS mypolygon", ["text"]) rv = plpy.execute(plan, [country_name], 1) plpy.debug('Returning from Returning from geocode_admin0_polygons') @@ -26,7 +26,7 @@ $$ LANGUAGE plpythonu; -- Implementation of the server extension -- Note: these functions depend on the cdb_geocoder extension -CREATE OR REPLACE FUNCTION cdb_geocoder_server._geocode_admin0_polygons(country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_server._geocode_admin0_polygon(country_name text) RETURNS Geometry AS $$ DECLARE ret Geometry; diff --git a/server/extension/sql/0.0.1/40_admin1.sql b/server/extension/sql/0.0.1/40_admin1.sql index 8d29e26..f243eec 100644 --- a/server/extension/sql/0.0.1/40_admin1.sql +++ b/server/extension/sql/0.0.1/40_admin1.sql @@ -1,9 +1,9 @@ -- Interfacess of the server extension ----- geocode_admin1_polygons(admin1_name text) -CREATE OR REPLACE FUNCTION geocode_admin1_polygons(user_id name, tx_id bigint, admin1_name text) +---- geocode_admin1_polygon(admin1_name text) +CREATE OR REPLACE FUNCTION geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text) RETURNS Geometry AS $$ - plpy.debug('Entering geocode_admin1_polygons(admin1_name text)') + plpy.debug('Entering geocode_admin1_polygon(admin1_name text)') plpy.debug('user_id = %s' % user_id) #-- Access control @@ -15,17 +15,17 @@ RETURNS Geometry AS $$ #--TODO: quota check #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html - plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_admin1_polygons($1) AS mypolygon", ["text"]) + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_admin1_polygon($1) AS mypolygon", ["text"]) rv = plpy.execute(plan, [admin1_name], 1) plpy.debug('Returning from Returning from geocode_admin1_polygons') return rv[0]["mypolygon"] $$ LANGUAGE plpythonu; ----- geocode_admin1_polygons(admin1_name text, country_name text) -CREATE OR REPLACE FUNCTION geocode_admin1_polygons(user_id name, tx_id bigint, admin1_name text, country_name text) +---- geocode_admin1_polygon(admin1_name text, country_name text) +CREATE OR REPLACE FUNCTION geocode_admin1_polygon(user_id name, tx_id bigint, admin1_name text, country_name text) RETURNS Geometry AS $$ - plpy.debug('Entering geocode_admin1_polygons(admin1_name text, country_name text)') + plpy.debug('Entering geocode_admin1_polygon(admin1_name text, country_name text)') plpy.debug('user_id = %s' % user_id) #-- Access control @@ -37,10 +37,10 @@ RETURNS Geometry AS $$ #--TODO: quota check #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html - plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_admin1_polygons($1, $2) AS mypolygon", ["text", "text"]) + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"]) rv = plpy.execute(plan, [admin1_name, country_name], 1) - plpy.debug('Returning from Returning from geocode_admin1_polygons(admin1_name text, country_name text)') + plpy.debug('Returning from Returning from geocode_admin1_polygon(admin1_name text, country_name text)') return rv[0]["mypolygon"] $$ LANGUAGE plpythonu; @@ -49,8 +49,8 @@ $$ LANGUAGE plpythonu; -- Implementation of the server extension -- Note: these functions depend on the cdb_geocoder extension ----- geocode_admin1_polygons(admin1_name text) -CREATE OR REPLACE FUNCTION _geocode_admin1_polygons(admin1_name text) +---- geocode_admin1_polygon(admin1_name text) +CREATE OR REPLACE FUNCTION _geocode_admin1_polygon(admin1_name text) RETURNS Geometry AS $$ DECLARE ret Geometry; @@ -73,8 +73,8 @@ RETURNS Geometry AS $$ END $$ LANGUAGE plpgsql; ----- geocode_admin1_polygons(admin1_name text, country_name text) -CREATE OR REPLACE FUNCTION _geocode_admin1_polygons(admin1_name text, country_name text) +---- geocode_admin1_polygon(admin1_name text, country_name text) +CREATE OR REPLACE FUNCTION _geocode_admin1_polygon(admin1_name text, country_name text) RETURNS Geometry AS $$ DECLARE ret Geometry; diff --git a/server/extension/sql/0.0.1/50_namedplaces.sql b/server/extension/sql/0.0.1/50_namedplaces.sql index 124aeea..5a72421 100644 --- a/server/extension/sql/0.0.1/50_namedplaces.sql +++ b/server/extension/sql/0.0.1/50_namedplaces.sql @@ -1,9 +1,9 @@ -- Interfacess of the server extension ----- geocode_namedplace(city_name text) -CREATE OR REPLACE FUNCTION geocode_namedplace(user_id name, tx_id bigint, city_name text) +---- geocode_namedplace_point(city_name text) +CREATE OR REPLACE FUNCTION geocode_namedplace_point(user_id name, tx_id bigint, city_name text) RETURNS Geometry AS $$ - plpy.debug('Entering geocode_namedplace(city_name text)') + plpy.debug('Entering geocode_namedplace_point(city_name text)') plpy.debug('user_id = %s' % user_id) #-- Access control @@ -15,17 +15,17 @@ RETURNS Geometry AS $$ #--TODO: quota check #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html - plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_namedplace($1) AS mypoint", ["text"]) + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_namedplace_point($1) AS mypoint", ["text"]) rv = plpy.execute(plan, [city_name], 1) plpy.debug('Returning from Returning from geocode_namedplace') return rv[0]["mypoint"] $$ LANGUAGE plpythonu; ----- geocode_namedplace(city_name text, country_name text) -CREATE OR REPLACE FUNCTION geocode_namedplace(user_id name, tx_id bigint, city_name text, country_name text) +---- geocode_namedplace_point(city_name text, country_name text) +CREATE OR REPLACE FUNCTION geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text) RETURNS Geometry AS $$ - plpy.debug('Entering geocode_namedplace(city_name text, country_name text)') + plpy.debug('Entering geocode_namedplace_point(city_name text, country_name text)') plpy.debug('user_id = %s' % user_id) #-- Access control @@ -37,17 +37,17 @@ RETURNS Geometry AS $$ #--TODO: quota check #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html - plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_namedplace($1, $2) AS mypoint", ["text", "text"]) + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"]) rv = plpy.execute(plan, [city_name, country_name], 1) plpy.debug('Returning from Returning from geocode_namedplace') return rv[0]["mypoint"] $$ LANGUAGE plpythonu; ----- geocode_namedplace(city_name text, admin1_name text, country_name text) -CREATE OR REPLACE FUNCTION geocode_namedplace(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text) +---- geocode_namedplace_point(city_name text, admin1_name text, country_name text) +CREATE OR REPLACE FUNCTION geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text) RETURNS Geometry AS $$ - plpy.debug('Entering geocode_namedplace(city_name text, admin1_name text, country_name text)') + plpy.debug('Entering geocode_namedplace_point(city_name text, admin1_name text, country_name text)') plpy.debug('user_id = %s' % user_id) #-- Access control @@ -59,7 +59,7 @@ RETURNS Geometry AS $$ #--TODO: quota check #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html - plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_namedplace($1, $2, $3) AS mypoint", ["text", "text", "text"]) + plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"]) rv = plpy.execute(plan, [city_name, admin1_name, country_name], 1) plpy.debug('Returning from Returning from geocode_namedplace') @@ -71,8 +71,8 @@ $$ LANGUAGE plpythonu; -- Implementation of the server extension -- Note: these functions depend on the cdb_geocoder extension ----- geocode_namedplace(city_name text) -CREATE OR REPLACE FUNCTION _geocode_namedplace(city_name text) +---- geocode_namedplace_point(city_name text) +CREATE OR REPLACE FUNCTION _geocode_namedplace_point(city_name text) RETURNS Geometry AS $$ DECLARE ret Geometry; @@ -90,8 +90,8 @@ RETURNS Geometry AS $$ END $$ LANGUAGE plpgsql; ----- geocode_namedplace(city_name text, country_name text) -CREATE OR REPLACE FUNCTION _geocode_namedplace(city_name text, country_name text) +---- geocode_namedplace_point(city_name text, country_name text) +CREATE OR REPLACE FUNCTION _geocode_namedplace_point(city_name text, country_name text) RETURNS Geometry AS $$ DECLARE ret Geometry; @@ -110,8 +110,8 @@ RETURNS Geometry AS $$ END $$ LANGUAGE plpgsql; ----- geocode_namedplace(city_name text, admin1_name text, country_name text) -CREATE OR REPLACE FUNCTION _geocode_namedplace(city_name text, admin1_name text, country_name text) +---- geocode_namedplace_point(city_name text, admin1_name text, country_name text) +CREATE OR REPLACE FUNCTION _geocode_namedplace_point(city_name text, admin1_name text, country_name text) RETURNS Geometry AS $$ DECLARE ret Geometry; diff --git a/server/extension/sql/30_admin0_test.sql b/server/extension/sql/30_admin0_test.sql index 60428e9..5ab9248 100644 --- a/server/extension/sql/30_admin0_test.sql +++ b/server/extension/sql/30_admin0_test.sql @@ -1,6 +1,6 @@ -- Check that the public function is callable, even with no data -- It should return NULL -SELECT cdb_geocoder_server.geocode_admin0_polygons(session_user, txid_current(), 'Spain'); +SELECT cdb_geocoder_server.geocode_admin0_polygon(session_user, txid_current(), 'Spain'); -- Insert some dummy synonym INSERT INTO admin0_synonyms (name, adm0_a3) VALUES ('Spain', 'ESP'); @@ -14,4 +14,4 @@ INSERT INTO ne_admin0_v3 (adm0_a3, the_geom) VALUES('ESP', ST_GeomFromText( ); -- This should return the polygon inserted above -SELECT cdb_geocoder_server.geocode_admin0_polygons(session_user, txid_current(), 'Spain'); +SELECT cdb_geocoder_server.geocode_admin0_polygon(session_user, txid_current(), 'Spain'); diff --git a/server/extension/sql/40_admin1_test.sql b/server/extension/sql/40_admin1_test.sql index 1620766..f84d548 100644 --- a/server/extension/sql/40_admin1_test.sql +++ b/server/extension/sql/40_admin1_test.sql @@ -1,7 +1,7 @@ -- Check that the public function is callable, even with no data -- It should return NULL -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California'); -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California', 'United States'); +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California'); +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California', 'United States'); -- Insert dummy data into country decoder table INSERT INTO country_decoder (synonyms, iso3) VALUES (Array['united states'], 'USA'); @@ -15,8 +15,8 @@ INSERT INTO global_province_polygons (synonyms, iso3, the_geom) VALUES (Array['c ); -- This should return the polygon inserted above -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California'); -SELECT cdb_geocoder_server.geocode_admin1_polygons(session_user, txid_current(), 'California', 'United States'); +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California'); +SELECT cdb_geocoder_server.geocode_admin1_polygon(session_user, txid_current(), 'California', 'United States'); diff --git a/server/extension/sql/50_namedplaces_test.sql b/server/extension/sql/50_namedplaces_test.sql index 7cbc541..503e192 100644 --- a/server/extension/sql/50_namedplaces_test.sql +++ b/server/extension/sql/50_namedplaces_test.sql @@ -1,6 +1,6 @@ -- Check that the public function is callable, even with no data -- It should return NULL -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); -- Insert dummy data into points table INSERT INTO global_cities_points_limited (geoname_id, name, iso2, admin1, admin2, population, lowername, the_geom) VALUES (3128760, 'Elche', 'ES', 'Valencia', 'AL', 34534, 'elche', ST_GeomFromText( @@ -19,9 +19,9 @@ INSERT INTO country_decoder (synonyms, iso2) VALUES (Array['spain'], 'ES'); INSERT INTO admin1_decoder (admin1, synonyms, iso2) VALUES ('Valencia', Array['valencia', 'Valencia'], 'ES'); -- This should return the point inserted above -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Spain'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'Spain'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); From b210182f27cfdc345b306abd5acba1211aead0e7 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:32:36 +0100 Subject: [PATCH 04/13] Adds rule to ignore results/*.out files --- server/extension/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/extension/.gitignore b/server/extension/.gitignore index 692d013..1dcc20d 100644 --- a/server/extension/.gitignore +++ b/server/extension/.gitignore @@ -2,3 +2,5 @@ results/ regression.diffs regression.out cdb_geocoder_server--0.0.1.sql + +result/*.out From 18f6e141a8ee994fcceb31ee727e267a2b0417e2 Mon Sep 17 00:00:00 2001 From: Carla Date: Thu, 12 Nov 2015 11:37:04 +0100 Subject: [PATCH 05/13] Update 50_namedplaces_test.sql --- server/extension/sql/50_namedplaces_test.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/extension/sql/50_namedplaces_test.sql b/server/extension/sql/50_namedplaces_test.sql index 503e192..c040e13 100644 --- a/server/extension/sql/50_namedplaces_test.sql +++ b/server/extension/sql/50_namedplaces_test.sql @@ -1,6 +1,11 @@ -- Check that the public function is callable, even with no data -- It should return NULL SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); +SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche'); +SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); -- Insert dummy data into points table INSERT INTO global_cities_points_limited (geoname_id, name, iso2, admin1, admin2, population, lowername, the_geom) VALUES (3128760, 'Elche', 'ES', 'Valencia', 'AL', 34534, 'elche', ST_GeomFromText( From 4283d3a25b72cc51dc03fcc78a1a75b33ac60f96 Mon Sep 17 00:00:00 2001 From: Carla Date: Thu, 12 Nov 2015 11:37:32 +0100 Subject: [PATCH 06/13] Update 50_namedplaces_test.sql --- server/extension/sql/50_namedplaces_test.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/extension/sql/50_namedplaces_test.sql b/server/extension/sql/50_namedplaces_test.sql index c040e13..cda38b0 100644 --- a/server/extension/sql/50_namedplaces_test.sql +++ b/server/extension/sql/50_namedplaces_test.sql @@ -1,11 +1,11 @@ -- Check that the public function is callable, even with no data -- It should return NULL SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Spain'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'Spain'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); -SELECT cdb_geocoder_server.geocode_namedplace(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); -- Insert dummy data into points table INSERT INTO global_cities_points_limited (geoname_id, name, iso2, admin1, admin2, population, lowername, the_geom) VALUES (3128760, 'Elche', 'ES', 'Valencia', 'AL', 34534, 'elche', ST_GeomFromText( From ec6ebdd6836d0398d72246e8374ced3b00858c02 Mon Sep 17 00:00:00 2001 From: Carla Date: Thu, 12 Nov 2015 11:38:39 +0100 Subject: [PATCH 07/13] Update 50_namedplaces_test.out --- .../expected/50_namedplaces_test.out | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/server/extension/expected/50_namedplaces_test.out b/server/extension/expected/50_namedplaces_test.out index c8e6c15..7adb3e7 100644 --- a/server/extension/expected/50_namedplaces_test.out +++ b/server/extension/expected/50_namedplaces_test.out @@ -2,7 +2,37 @@ -- It should return NULL SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); geocode_namedplace_point --------------------------- +-------------------- + +(1 row) + +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche'); + geocode_namedplace_point +-------------------- + +(1 row) + +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Spain'); + geocode_namedplace_point +-------------------- + +(1 row) + +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'Spain'); + geocode_namedplace_point +-------------------- + +(1 row) + +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); + geocode_namedplace_point +-------------------- + +(1 row) + +SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); + geocode_namedplace_point +-------------------- (1 row) From 84f45f82b430c9b9048a5b1b7bbaa1cb7585769a Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:40:47 +0100 Subject: [PATCH 08/13] Typo in .gitignore --- server/extension/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/server/extension/.gitignore b/server/extension/.gitignore index 1dcc20d..7b6ce39 100644 --- a/server/extension/.gitignore +++ b/server/extension/.gitignore @@ -3,4 +3,3 @@ regression.diffs regression.out cdb_geocoder_server--0.0.1.sql -result/*.out From 1216e5812050cbc6fe0a99ce25e689476d0635e4 Mon Sep 17 00:00:00 2001 From: Carla Iriberri Date: Thu, 12 Nov 2015 11:47:22 +0100 Subject: [PATCH 09/13] Editing test output --- server/extension/expected/50_namedplaces_test.out | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/extension/expected/50_namedplaces_test.out b/server/extension/expected/50_namedplaces_test.out index 7adb3e7..b59bc1b 100644 --- a/server/extension/expected/50_namedplaces_test.out +++ b/server/extension/expected/50_namedplaces_test.out @@ -2,37 +2,37 @@ -- It should return NULL SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx'); geocode_namedplace_point --------------------- +-------------------------- (1 row) SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche'); geocode_namedplace_point --------------------- +-------------------------- (1 row) SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Spain'); geocode_namedplace_point --------------------- +-------------------------- (1 row) SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'Spain'); geocode_namedplace_point --------------------- +-------------------------- (1 row) SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elx', 'Valencia', 'Spain'); geocode_namedplace_point --------------------- +-------------------------- (1 row) SELECT cdb_geocoder_server.geocode_namedplace_point(session_user, txid_current(), 'Elche', 'valencia', 'Spain'); geocode_namedplace_point --------------------- +-------------------------- (1 row) From 4ba76df016b2bd9ebc2a10c538a3f42974ae7473 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:57:28 +0100 Subject: [PATCH 10/13] Improves ip query --- server/extension/sql/0.0.1/70_ips.sql | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/extension/sql/0.0.1/70_ips.sql b/server/extension/sql/0.0.1/70_ips.sql index 6f9a306..2ee215d 100644 --- a/server/extension/sql/0.0.1/70_ips.sql +++ b/server/extension/sql/0.0.1/70_ips.sql @@ -29,7 +29,7 @@ $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION _geocode_ip_point(ip TEXT) RETURNS Geometry AS $$ DECLARE - ret geocode_ip_v1%rowtype; + ret Geometry; new_ips INET[]; old_ips TEXT[]; @@ -46,11 +46,12 @@ RETURNS Geometry AS $$ SELECT ip AS q, NULL as geom, FALSE as success INTO ret; RETURN ret; END; - FOR ret IN WITH ips AS (SELECT unnest(old_ips) s, unnest(new_ips) net), + + WITH + ips AS (SELECT unnest(old_ips) s, unnest(new_ips) net), matches AS (SELECT s, (SELECT the_geom FROM ip_address_locations WHERE network_start_ip <= ips.net ORDER BY network_start_ip DESC LIMIT 1) geom FROM ips) - SELECT s, geom, CASE WHEN geom IS NULL THEN FALSE ELSE TRUE END AS success FROM matches - LOOP - RETURN ret.geom; - END LOOP; + SELECT geom INTO ret + FROM matches; + RETURN ret; END $$ LANGUAGE plpgsql; From 2afb541d8d1e2aef1201164675c1a79b8bddb9f1 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 11:58:32 +0100 Subject: [PATCH 11/13] Fix indentation --- server/extension/sql/0.0.1/70_ips.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/extension/sql/0.0.1/70_ips.sql b/server/extension/sql/0.0.1/70_ips.sql index 2ee215d..65630aa 100644 --- a/server/extension/sql/0.0.1/70_ips.sql +++ b/server/extension/sql/0.0.1/70_ips.sql @@ -50,7 +50,7 @@ RETURNS Geometry AS $$ WITH ips AS (SELECT unnest(old_ips) s, unnest(new_ips) net), matches AS (SELECT s, (SELECT the_geom FROM ip_address_locations WHERE network_start_ip <= ips.net ORDER BY network_start_ip DESC LIMIT 1) geom FROM ips) - SELECT geom INTO ret + SELECT geom INTO ret FROM matches; RETURN ret; END From ff3f5a1f4c2d09cf1770e6f727965c4aa7a4da20 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 12:07:15 +0100 Subject: [PATCH 12/13] Removes unnecessary arrays --- server/extension/sql/0.0.1/70_ips.sql | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/extension/sql/0.0.1/70_ips.sql b/server/extension/sql/0.0.1/70_ips.sql index 65630aa..b40a9aa 100644 --- a/server/extension/sql/0.0.1/70_ips.sql +++ b/server/extension/sql/0.0.1/70_ips.sql @@ -31,16 +31,13 @@ RETURNS Geometry AS $$ DECLARE ret Geometry; - new_ips INET[]; - old_ips TEXT[]; + new_ip INET; BEGIN BEGIN IF family(ip::inet) = 6 THEN - new_ips := array_append(new_ips, ip::inet); - old_ips := array_append(old_ips, ip); + new_ip := ip::inet; ELSE - new_ips := array_append(new_ips, ('::ffff:' || ip)::inet); - old_ips := array_append(old_ips, ip); + new_ip := ('::ffff:' || ip)::inet; END IF; EXCEPTION WHEN OTHERS THEN SELECT ip AS q, NULL as geom, FALSE as success INTO ret; @@ -48,7 +45,7 @@ RETURNS Geometry AS $$ END; WITH - ips AS (SELECT unnest(old_ips) s, unnest(new_ips) net), + ips AS (SELECT ip s, new_ip net), matches AS (SELECT s, (SELECT the_geom FROM ip_address_locations WHERE network_start_ip <= ips.net ORDER BY network_start_ip DESC LIMIT 1) geom FROM ips) SELECT geom INTO ret FROM matches; From c1d4ffb37ad553f59bd77f4db606e9ac6ecf524d Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 12:11:05 +0100 Subject: [PATCH 13/13] Exception typo --- server/extension/sql/0.0.1/70_ips.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/extension/sql/0.0.1/70_ips.sql b/server/extension/sql/0.0.1/70_ips.sql index b40a9aa..cb26833 100644 --- a/server/extension/sql/0.0.1/70_ips.sql +++ b/server/extension/sql/0.0.1/70_ips.sql @@ -40,7 +40,7 @@ RETURNS Geometry AS $$ new_ip := ('::ffff:' || ip)::inet; END IF; EXCEPTION WHEN OTHERS THEN - SELECT ip AS q, NULL as geom, FALSE as success INTO ret; + SELECT NULL as geom INTO ret; RETURN ret; END;