From 5226af7c866b6f7601f83849e9398fe44f9ab6fe Mon Sep 17 00:00:00 2001 From: Carla Iriberri Date: Thu, 12 Nov 2015 18:45:27 +0100 Subject: [PATCH] Adds client functions for named places, pcodes and ips --- client/expected/30_namedplaces_test.out | 50 ++++++++++++++++++++ client/expected/40_postalcodes_test.out | 34 ++++++++++++++ client/expected/50_ipaddresses_test.out | 18 +++++++ client/sql/0.0.1/30_namedplaces.sql | 62 +++++++++++++++++++++++++ client/sql/0.0.1/40_postalcodes.sql | 45 ++++++++++++++++++ client/sql/0.0.1/50_ipaddresses.sql | 27 +++++++++++ client/sql/30_namedplaces_test.sql | 30 ++++++++++++ client/sql/40_postalcodes_test.sql | 20 ++++++++ client/sql/50_ipaddresses_test.sql | 12 +++++ 9 files changed, 298 insertions(+) create mode 100644 client/expected/30_namedplaces_test.out create mode 100644 client/expected/40_postalcodes_test.out create mode 100644 client/expected/50_ipaddresses_test.out create mode 100644 client/sql/0.0.1/30_namedplaces.sql create mode 100644 client/sql/0.0.1/40_postalcodes.sql create mode 100644 client/sql/0.0.1/50_ipaddresses.sql create mode 100644 client/sql/30_namedplaces_test.sql create mode 100644 client/sql/40_postalcodes_test.sql create mode 100644 client/sql/50_ipaddresses_test.sql diff --git a/client/expected/30_namedplaces_test.out b/client/expected/30_namedplaces_test.out new file mode 100644 index 0000000..7bbd2f8 --- /dev/null +++ b/client/expected/30_namedplaces_test.out @@ -0,0 +1,50 @@ +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', city_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', city_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %, %)', user_id, 'some_transaction_id', city_name, admin1_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocoder_client.geocode_namedplace_point('Elx'); +NOTICE: cdb_geocoder_client._geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text) line 5 at SQL statement + geocode_namedplace_point +-------------------------- + +(1 row) + +SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Spain'); +NOTICE: cdb_geocoder_client._geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text) line 5 at SQL statement + geocode_namedplace_point +-------------------------- + +(1 row) + +SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia', 'Spain'); +NOTICE: cdb_geocoder_client._geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, Elx, Valencia, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, admin1_name, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_namedplace_point(text,text,text) line 5 at SQL statement + geocode_namedplace_point +-------------------------- + +(1 row) + diff --git a/client/expected/40_postalcodes_test.out b/client/expected/40_postalcodes_test.out new file mode 100644 index 0000000..ec5a808 --- /dev/null +++ b/client/expected/40_postalcodes_test.out @@ -0,0 +1,34 @@ +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code integer, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocoder_client.geocode_postalcode_polygon('03204', 'Spain'); +NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 03204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(text,text) line 5 at SQL statement + geocode_postalcode_polygon +---------------------------- + +(1 row) + +SELECT cdb_geocoder_client.geocode_postalcode_polygon(3204, 'Spain'); +NOTICE: cdb_geocoder_client._geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_postalcode_polygon invoked with params (postgres, some_transaction_id, 3204, Spain) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name)" +PL/pgSQL function cdb_geocoder_client.geocode_postalcode_polygon(integer,text) line 5 at SQL statement + geocode_postalcode_polygon +---------------------------- + +(1 row) + diff --git a/client/expected/50_ipaddresses_test.out b/client/expected/50_ipaddresses_test.out new file mode 100644 index 0000000..badc382 --- /dev/null +++ b/client/expected/50_ipaddresses_test.out @@ -0,0 +1,18 @@ +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ip(user_id name, tx_id bigint, ip_address text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; +-- Exercise the public and the proxied function +SELECT cdb_geocoder_client.geocode_ip('8.8.8.8'); +NOTICE: cdb_geocoder_client._geocode_ip(3): [contrib_regression] REMOTE NOTICE: cbd_geocoder_server.geocode_namedplace_point invoked with params (postgres, some_transaction_id, 8.8.8.8) +CONTEXT: SQL statement "SELECT cdb_geocoder_client._geocode_ip(session_user, txid_current(), ip_address)" +PL/pgSQL function cdb_geocoder_client.geocode_ip(text) line 5 at SQL statement + geocode_ip +------------ + +(1 row) + diff --git a/client/sql/0.0.1/30_namedplaces.sql b/client/sql/0.0.1/30_namedplaces.sql new file mode 100644 index 0000000..8ac6a9d --- /dev/null +++ b/client/sql/0.0.1/30_namedplaces.sql @@ -0,0 +1,62 @@ +-- +-- Public geocoder API function +-- +-- These are the only ones with permissions to publicuser role +-- and should also be the only ones with SECURITY DEFINER + +---- geocode_namedplace_point(city_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; +BEGIN + SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +---- geocode_namedplace_point(city_name text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text, country_name text) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; +BEGIN + SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, country_name) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +---- geocode_namedplace_point(city_name text, admin1_name text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_namedplace_point(city_name text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; +BEGIN + SELECT cdb_geocoder_client._geocode_namedplace_point(session_user, txid_current(), city_name, admin1_name, country_name) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; +-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions] + +-------------------------------------------------------------------------------- + +---- geocode_namedplace_point(city_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_namedplace_point(user_id name, tx_id bigint, city_name text) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.geocode_namedplace_point(user_id, tx_id, city_name); +$$ LANGUAGE plproxy; + +---- geocode_namedplace_point(city_name text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.geocode_namedplace_point(user_id, tx_id, city_name, country_name); +$$ LANGUAGE plproxy; + +---- geocode_namedplace_point(city_name text, admin1_name text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.geocode_namedplace_point(user_id, tx_id, city_name, admin1_name, country_name); +$$ LANGUAGE plproxy; \ No newline at end of file diff --git a/client/sql/0.0.1/40_postalcodes.sql b/client/sql/0.0.1/40_postalcodes.sql new file mode 100644 index 0000000..26b404b --- /dev/null +++ b/client/sql/0.0.1/40_postalcodes.sql @@ -0,0 +1,45 @@ +-- +-- Public geocoder API function +-- +-- These are the only ones with permissions to publicuser role +-- and should also be the only ones with SECURITY DEFINER + +---- geocode_postalcode_polygon(postal_code text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_postalcode_polygon(postal_code text, country_name text) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; +BEGIN + SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +---- geocode_postalcode_polygon(postal_code integer, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_postalcode_polygon(postal_code integer, country_name text) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; +BEGIN + SELECT cdb_geocoder_client._geocode_postalcode_polygon(session_user, txid_current(), postal_code, country_name) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions] + +-------------------------------------------------------------------------------- + +---- geocode_postalcode_polygon(postal_code text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.geocode_postalcode_polygon(user_id, tx_id, postal_code, country_name); +$$ LANGUAGE plproxy; + +---- geocode_postalcode_polygon(postal_code integer, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code integer, country_name text) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.geocode_postalcode_polygon(user_id, tx_id, postal_code, country_name); +$$ LANGUAGE plproxy; diff --git a/client/sql/0.0.1/50_ipaddresses.sql b/client/sql/0.0.1/50_ipaddresses.sql new file mode 100644 index 0000000..c7b0c53 --- /dev/null +++ b/client/sql/0.0.1/50_ipaddresses.sql @@ -0,0 +1,27 @@ +-- +-- Public geocoder API function +-- +-- These are the only ones with permissions to publicuser role +-- and should also be the only ones with SECURITY DEFINER + +---- geocode_ip(city_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_ip(ip_address text) +RETURNS Geometry AS $$ +DECLARE + ret Geometry; +BEGIN + SELECT cdb_geocoder_client._geocode_ip(session_user, txid_current(), ip_address) INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions] + +-------------------------------------------------------------------------------- + +---- geocode_ip(ip_address text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_ip(user_id name, tx_id bigint, ip_address text) +RETURNS Geometry AS $$ + CONNECT cdb_geocoder_client._server_conn_str(); + SELECT cdb_geocoder_server.geocode_ip(user_id, tx_id, ip_address); +$$ LANGUAGE plproxy; diff --git a/client/sql/30_namedplaces_test.sql b/client/sql/30_namedplaces_test.sql new file mode 100644 index 0000000..f0f8004 --- /dev/null +++ b/client/sql/30_namedplaces_test.sql @@ -0,0 +1,30 @@ +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', city_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %)', user_id, 'some_transaction_id', city_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_namedplace_point(user_id name, tx_id bigint, city_name text, admin1_name text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %, %, %)', user_id, 'some_transaction_id', city_name, admin1_name, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +-- Exercise the public and the proxied function +SELECT cdb_geocoder_client.geocode_namedplace_point('Elx'); +SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Spain'); +SELECT cdb_geocoder_client.geocode_namedplace_point('Elx', 'Valencia', 'Spain'); + diff --git a/client/sql/40_postalcodes_test.sql b/client/sql/40_postalcodes_test.sql new file mode 100644 index 0000000..a402397 --- /dev/null +++ b/client/sql/40_postalcodes_test.sql @@ -0,0 +1,20 @@ +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code text, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_postalcode_polygon(user_id name, tx_id bigint, postal_code integer, country_name text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_postalcode_polygon invoked with params (%, %, %, %)', user_id, 'some_transaction_id', postal_code, country_name; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + +-- Exercise the public and the proxied function +SELECT cdb_geocoder_client.geocode_postalcode_polygon('03204', 'Spain'); +SELECT cdb_geocoder_client.geocode_postalcode_polygon(3204, 'Spain'); diff --git a/client/sql/50_ipaddresses_test.sql b/client/sql/50_ipaddresses_test.sql new file mode 100644 index 0000000..2b545f7 --- /dev/null +++ b/client/sql/50_ipaddresses_test.sql @@ -0,0 +1,12 @@ +-- Mock the server functions +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_ip(user_id name, tx_id bigint, ip_address text) +RETURNS Geometry AS $$ +BEGIN + RAISE NOTICE 'cbd_geocoder_server.geocode_namedplace_point invoked with params (%, %, %)', user_id, 'some_transaction_id', ip_address; + RETURN NULL; +END; +$$ LANGUAGE 'plpgsql'; + + +-- Exercise the public and the proxied function +SELECT cdb_geocoder_client.geocode_ip('8.8.8.8'); \ No newline at end of file