Compare commits
9 Commits
0.2.0-serv
...
0.3.0-serv
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7544b3c4ab | ||
|
|
86d20a6ac2 | ||
|
|
142affc95e | ||
|
|
95c23edd1b | ||
|
|
4b31a15027 | ||
|
|
2994a1b402 | ||
|
|
2a9d6c14bd | ||
|
|
17b8b5942e | ||
|
|
cbfe1b600f |
@@ -1,6 +1,6 @@
|
||||
# Makefile to generate the extension out of separate sql source files.
|
||||
# Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed.
|
||||
EXTENSION = cdb_geocoder_client
|
||||
EXTENSION = cdb_dataservices_client
|
||||
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
||||
|
||||
# The new version to be generated from templates
|
||||
@@ -11,9 +11,9 @@ NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
|
||||
# for installation from scratch, upgrades and downgrades.
|
||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||
cdb_geocoder_client--0.0.1.sql \
|
||||
cdb_geocoder_client--0.1.0--0.0.1.sql \
|
||||
cdb_geocoder_client--0.0.1--0.1.0.sql
|
||||
cdb_dataservices_client--0.0.1.sql \
|
||||
cdb_dataservices_client--0.1.0--0.0.1.sql \
|
||||
cdb_dataservices_client--0.0.1--0.1.0.sql
|
||||
|
||||
|
||||
REGRESS = $(notdir $(basename $(wildcard test/$(EXTVERSION)/sql/*test.sql)))
|
||||
@@ -28,9 +28,9 @@ include $(PGXS)
|
||||
SOURCES_DATA_DIR = sql/$(EXTVERSION)
|
||||
|
||||
# The interface definition is used along with some templates to automatically generate code
|
||||
RENDERER = ../sql-template-renderer
|
||||
INTERFACE_FILE = ../interface_$(EXTVERSION).yaml
|
||||
TEMPLATE_DIR = templates
|
||||
RENDERER = renderer/sql-template-renderer
|
||||
INTERFACE_FILE = renderer/interfaces/interface_$(EXTVERSION).yaml
|
||||
TEMPLATE_DIR = renderer/templates
|
||||
TEMPLATE_FILES = $(wildcard $(TEMPLATE_DIR)/*.erb)
|
||||
GENERATED_SQL_FILES = $(patsubst $(TEMPLATE_DIR)/%.erb, $(SOURCES_DATA_DIR)/%.sql, $(TEMPLATE_FILES))
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# CartoDB geocoder API client extension
|
||||
Postgres extension for the CartoDB geocoder API, client side.
|
||||
# CartoDB dataservices API client extension
|
||||
Postgres extension for the CartoDB dataservices API, client side.
|
||||
|
||||
## Dependencies
|
||||
This extension is thought to be used on top of CartoDB geocoder extension, for the multiples available geocoders (internal, nokia, etc).
|
||||
@@ -37,7 +37,7 @@ psql -U postgres cartodb_dev_user_fe3b850a-01c0-48f9-8a26-a82f09e9b53f_db
|
||||
and then:
|
||||
|
||||
```sql
|
||||
CREATE EXTENSION cdb_geocoder_client;
|
||||
CREATE EXTENSION cdb_dataservices_client;
|
||||
```
|
||||
|
||||
The extension creation in the user's db requires **superuser** privileges.
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
-- The purpose of this function is to retrieve the username and organization name from
|
||||
-- a) schema where he/her is the owner in case is an organization user
|
||||
-- b) entity_name from the cdb_conf database in case is a non organization user
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_entity_config()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
||||
RETURNS record AS $$
|
||||
DECLARE
|
||||
result cdb_geocoder_client._entity_config;
|
||||
result cdb_dataservices_client._entity_config;
|
||||
is_organization boolean;
|
||||
username text;
|
||||
organization_name text;
|
||||
@@ -31,7 +31,7 @@ BEGIN
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -41,20 +41,20 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_street_point (username, organization_name, searchtext, city, state_province, country);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_street_point (username, organization_name, searchtext, city, state_province, country);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser;
|
||||
@@ -1,12 +1,12 @@
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_client" to load this file. \quit
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_client" to load this file. \quit
|
||||
--
|
||||
-- Geocoder server connection config
|
||||
--
|
||||
-- The purpose of this function is provide to the PL/Proxy functions
|
||||
-- the connection string needed to connect with the server
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._server_conn_str()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._server_conn_str()
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
db_connection_str text;
|
||||
@@ -15,7 +15,7 @@ BEGIN
|
||||
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
|
||||
RETURN db_connection_str;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';CREATE TYPE cdb_geocoder_client._entity_config AS (
|
||||
$$ LANGUAGE 'plpgsql';CREATE TYPE cdb_dataservices_client._entity_config AS (
|
||||
username text,
|
||||
organization_name text
|
||||
);
|
||||
@@ -26,10 +26,10 @@ $$ LANGUAGE 'plpgsql';CREATE TYPE cdb_geocoder_client._entity_config AS (
|
||||
-- The purpose of this function is to retrieve the username and organization name from
|
||||
-- a) schema where he/her is the owner in case is an organization user
|
||||
-- b) entity_name from the cdb_conf database in case is a non organization user
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_entity_config()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
||||
RETURNS record AS $$
|
||||
DECLARE
|
||||
result cdb_geocoder_client._entity_config;
|
||||
result cdb_dataservices_client._entity_config;
|
||||
is_organization boolean;
|
||||
username text;
|
||||
organization_name text;
|
||||
@@ -57,7 +57,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_admin0_polygon (country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_admin0_polygon (country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -67,12 +67,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_admin0_polygon(username, orgname, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -83,7 +83,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon (admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon (admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -93,12 +93,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -109,7 +109,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon (admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon (admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -119,12 +119,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -135,7 +135,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point (city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point (city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -145,12 +145,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -161,7 +161,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point (city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point (city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -171,12 +171,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -187,7 +187,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point (city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point (city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -197,12 +197,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -213,7 +213,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_polygon (postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_polygon (postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -223,12 +223,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -239,7 +239,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_point (postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_point (postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -249,12 +249,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
@@ -265,7 +265,7 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client.cdb_geocode_ipaddress_point (ip_address text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_ipaddress_point (ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -275,85 +275,85 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_geocoder_client._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address) INTO ret;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_ipaddress_point(username, orgname, ip_address) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_admin0_polygon (username text, organization_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin0_polygon (username text, organization_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_admin0_polygon (username, organization_name, country_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_admin0_polygon (username, organization_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name, country_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_namedplace_point (username, organization_name, city_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_namedplace_point (username, organization_name, city_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_namedplace_point (username, organization_name, city_name, country_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_namedplace_point (username, organization_name, city_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_namedplace_point (username, organization_name, city_name, admin1_name, country_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_namedplace_point (username, organization_name, city_name, admin1_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_postalcode_polygon (username text, organization_name text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_postalcode_polygon (username text, organization_name text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_postalcode_polygon (username, organization_name, postal_code, country_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_postalcode_polygon (username, organization_name, postal_code, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_postalcode_point (username text, organization_name text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_postalcode_point (username text, organization_name text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_postalcode_point (username, organization_name, postal_code, country_name);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_postalcode_point (username, organization_name, postal_code, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_geocode_ipaddress_point (username text, organization_name text, ip_address text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_ipaddress_point (username text, organization_name text, ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_geocoder_client._server_conn_str();
|
||||
SELECT cdb_geocoder_server.cdb_geocode_ipaddress_point (username, organization_name, ip_address);
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_ipaddress_point (username, organization_name, ip_address);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
-- Make sure by default there are no permissions for publicuser
|
||||
-- NOTE: this happens at extension creation time, as part of an implicit transaction.
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser CASCADE;
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser CASCADE;
|
||||
|
||||
-- Grant permissions on the schema to publicuser (but just the schema)
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_client TO publicuser;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_client TO publicuser;
|
||||
|
||||
-- Revoke execute permissions on all functions in the schema by default
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_admin0_polygon(country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon(admin1_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_admin1_polygon(admin1_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point(city_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point(city_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_polygon(postal_code text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_postalcode_point(postal_code text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_geocoder_client.cdb_geocode_ipaddress_point(ip_address text) TO publicuser;
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_admin0_polygon(country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon(admin1_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon(admin1_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point(city_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point(city_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_polygon(postal_code text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_point(postal_code text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_ipaddress_point(ip_address text) TO publicuser;
|
||||
@@ -1,8 +1,8 @@
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_client.cdb_geocode_street_point (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_client._cdb_geocode_street_point (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_geocode_street_point (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_street_point (text, text, text, text);
|
||||
-- This functions could exists due a first deploy with this name
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_client.cdb_geocode_street_point_v2 (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_client._cdb_geocode_street_point_v2 (text, text, text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_geocode_street_point_v2 (text, text, text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_geocode_street_point_v2 (text, text, text, text, text, text);
|
||||
|
||||
--
|
||||
-- Get entity config function
|
||||
@@ -10,10 +10,10 @@ DROP FUNCTION IF EXISTS cdb_geocoder_client._cdb_geocode_street_point_v2 (text,
|
||||
-- The purpose of this function is to retrieve the username and organization name from
|
||||
-- a) schema where he/her is the owner in case is an organization user
|
||||
-- b) entity_name from the cdb_conf database in case is a non organization user
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_entity_config()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
||||
RETURNS record AS $$
|
||||
DECLARE
|
||||
result cdb_geocoder_client._entity_config;
|
||||
result cdb_dataservices_client._entity_config;
|
||||
is_organization boolean;
|
||||
username text;
|
||||
organization_name text;
|
||||
395
client/cdb_dataservices_client--0.1.0.sql
Normal file
395
client/cdb_dataservices_client--0.1.0.sql
Normal file
@@ -0,0 +1,395 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_client" to load this file. \quit
|
||||
--
|
||||
-- Geocoder server connection config
|
||||
--
|
||||
-- The purpose of this function is provide to the PL/Proxy functions
|
||||
-- the connection string needed to connect with the server
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._server_conn_str()
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
db_connection_str text;
|
||||
BEGIN
|
||||
SELECT cartodb.cdb_conf_getconf('geocoder_server_config')->'connection_str' INTO db_connection_str;
|
||||
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
|
||||
RETURN db_connection_str;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE TYPE cdb_dataservices_client._entity_config AS (
|
||||
username text,
|
||||
organization_name text
|
||||
);
|
||||
|
||||
--
|
||||
-- Get entity config function
|
||||
--
|
||||
-- The purpose of this function is to retrieve the username and organization name from
|
||||
-- a) schema where he/her is the owner in case is an organization user
|
||||
-- b) entity_name from the cdb_conf database in case is a non organization user
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
||||
RETURNS record AS $$
|
||||
DECLARE
|
||||
result cdb_dataservices_client._entity_config;
|
||||
is_organization boolean;
|
||||
username text;
|
||||
organization_name text;
|
||||
BEGIN
|
||||
SELECT cartodb.cdb_conf_getconf('user_config')->'is_organization' INTO is_organization;
|
||||
IF is_organization IS NULL THEN
|
||||
RAISE EXCEPTION 'User must have user configuration in the config table';
|
||||
ELSIF is_organization = TRUE THEN
|
||||
SELECT nspname
|
||||
FROM pg_namespace s
|
||||
LEFT JOIN pg_roles r ON s.nspowner = r.oid
|
||||
WHERE r.rolname = session_user INTO username;
|
||||
SELECT cartodb.cdb_conf_getconf('user_config')->>'entity_name' INTO organization_name;
|
||||
ELSE
|
||||
SELECT cartodb.cdb_conf_getconf('user_config')->>'entity_name' INTO username;
|
||||
organization_name = NULL;
|
||||
END IF;
|
||||
result.username = username;
|
||||
result.organization_name = organization_name;
|
||||
RETURN result;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_admin0_polygon (country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_admin0_polygon(username, orgname, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon (admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon (admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point (city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point (city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point (city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_polygon (postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_point (postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_ipaddress_point (ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_ipaddress_point(username, orgname, ip_address) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
--
|
||||
-- Public geocoder API function
|
||||
--
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_geocode_street_point (searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
username text;
|
||||
orgname text;
|
||||
BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin0_polygon (username text, organization_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_admin0_polygon (username, organization_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_admin1_polygon (username text, organization_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_admin1_polygon (username, organization_name, admin1_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_namedplace_point (username, organization_name, city_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_namedplace_point (username, organization_name, city_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_namedplace_point (username text, organization_name text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_namedplace_point (username, organization_name, city_name, admin1_name, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_postalcode_polygon (username text, organization_name text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_postalcode_polygon (username, organization_name, postal_code, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_postalcode_point (username text, organization_name text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_postalcode_point (username, organization_name, postal_code, country_name);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_ipaddress_point (username text, organization_name text, ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_ipaddress_point (username, organization_name, ip_address);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_street_point (username text, organization_name text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT cdb_dataservices_client._server_conn_str();
|
||||
SELECT cdb_dataservices_server.cdb_geocode_street_point (username, organization_name, searchtext, city, state_province, country);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
-- Make sure by default there are no permissions for publicuser
|
||||
-- NOTE: this happens at extension creation time, as part of an implicit transaction.
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser CASCADE;
|
||||
|
||||
-- Grant permissions on the schema to publicuser (but just the schema)
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_client TO publicuser;
|
||||
|
||||
-- Revoke execute permissions on all functions in the schema by default
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_admin0_polygon(country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon(admin1_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_admin1_polygon(admin1_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point(city_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point(city_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_polygon(postal_code text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_postalcode_point(postal_code text, country_name text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_ipaddress_point(ip_address text) TO publicuser;
|
||||
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_geocode_street_point(searchtext text, city text, state_province text, country text) TO publicuser;
|
||||
5
client/cdb_dataservices_client.control
Normal file
5
client/cdb_dataservices_client.control
Normal file
@@ -0,0 +1,5 @@
|
||||
comment = 'CartoDB dataservices client API extension'
|
||||
default_version = '0.1.0'
|
||||
requires = 'plproxy, cartodb'
|
||||
superuser = true
|
||||
schema = cdb_dataservices_client
|
||||
@@ -1,6 +0,0 @@
|
||||
# CartoDB geocoder client API extension
|
||||
comment = 'CartoDB geocoder client API extension'
|
||||
default_version = '0.1.0'
|
||||
requires = 'plproxy, cartodb'
|
||||
superuser = true
|
||||
schema = cdb_geocoder_client
|
||||
@@ -8,7 +8,8 @@ require 'erb'
|
||||
|
||||
class SqlTemplateRenderer
|
||||
|
||||
GEOCODER_CLIENT_SCHEMA = 'cdb_geocoder_client'
|
||||
DATASERVICES_CLIENT_SCHEMA = 'cdb_dataservices_client'
|
||||
DATASERVICES_SERVER_SCHEMA = 'cdb_dataservices_server'
|
||||
|
||||
def initialize(template_file, function_signature)
|
||||
@function_signature = function_signature
|
||||
@@ -4,7 +4,7 @@
|
||||
-- These are the only ones with permissions to publicuser role
|
||||
-- and should also be the only ones with SECURITY DEFINER
|
||||
|
||||
CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default %>)
|
||||
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default %>)
|
||||
RETURNS <%= return_type %> AS $$
|
||||
DECLARE
|
||||
ret <%= return_type %>;
|
||||
@@ -14,12 +14,12 @@ BEGIN
|
||||
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||
RAISE EXCEPTION 'The api_key must be provided';
|
||||
END IF;
|
||||
SELECT u, o INTO username, orgname FROM <%= GEOCODER_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text);
|
||||
SELECT u, o INTO username, orgname FROM <%= DATASERVICES_CLIENT_SCHEMA %>._cdb_entity_config() AS (u text, o text);
|
||||
-- JSON value stored "" is taken as literal
|
||||
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||
END IF;
|
||||
SELECT <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret;
|
||||
SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
6
client/renderer/templates/30_plproxy_functions.erb
Normal file
6
client/renderer/templates/30_plproxy_functions.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (username text, organization_name text, <%= params_with_type_and_default %>)
|
||||
RETURNS <%= return_type %> AS $$
|
||||
CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str();
|
||||
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name, <%= params %>);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
1
client/renderer/templates/90_grant_execute.erb
Normal file
1
client/renderer/templates/90_grant_execute.erb
Normal file
@@ -0,0 +1 @@
|
||||
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type %>) TO publicuser;
|
||||
@@ -1,3 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_client" to load this file. \quit
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_client" to load this file. \quit
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
-- The purpose of this function is provide to the PL/Proxy functions
|
||||
-- the connection string needed to connect with the server
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._server_conn_str()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._server_conn_str()
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
db_connection_str text;
|
||||
@@ -13,4 +13,4 @@ BEGIN
|
||||
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
|
||||
RETURN db_connection_str;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TYPE cdb_geocoder_client._entity_config AS (
|
||||
CREATE TYPE cdb_dataservices_client._entity_config AS (
|
||||
username text,
|
||||
organization_name text
|
||||
);
|
||||
@@ -9,10 +9,10 @@ CREATE TYPE cdb_geocoder_client._entity_config AS (
|
||||
-- The purpose of this function is to retrieve the username and organization name from
|
||||
-- a) schema where he/her is the owner in case is an organization user
|
||||
-- b) entity_name from the cdb_conf database in case is a non organization user
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_entity_config()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
||||
RETURNS record AS $$
|
||||
DECLARE
|
||||
result cdb_geocoder_client._entity_config;
|
||||
result cdb_dataservices_client._entity_config;
|
||||
is_organization boolean;
|
||||
username text;
|
||||
organization_name text;
|
||||
@@ -34,4 +34,4 @@ BEGIN
|
||||
result.organization_name = organization_name;
|
||||
RETURN result;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
-- Make sure by default there are no permissions for publicuser
|
||||
-- NOTE: this happens at extension creation time, as part of an implicit transaction.
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser CASCADE;
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser CASCADE;
|
||||
|
||||
-- Grant permissions on the schema to publicuser (but just the schema)
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_client TO publicuser;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_client TO publicuser;
|
||||
|
||||
-- Revoke execute permissions on all functions in the schema by default
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser;
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_client" to load this file. \quit
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_client" to load this file. \quit
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
-- The purpose of this function is provide to the PL/Proxy functions
|
||||
-- the connection string needed to connect with the server
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._server_conn_str()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._server_conn_str()
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
db_connection_str text;
|
||||
@@ -13,4 +13,4 @@ BEGIN
|
||||
SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str;
|
||||
RETURN db_connection_str;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TYPE cdb_geocoder_client._entity_config AS (
|
||||
CREATE TYPE cdb_dataservices_client._entity_config AS (
|
||||
username text,
|
||||
organization_name text
|
||||
);
|
||||
@@ -9,10 +9,10 @@ CREATE TYPE cdb_geocoder_client._entity_config AS (
|
||||
-- The purpose of this function is to retrieve the username and organization name from
|
||||
-- a) schema where he/her is the owner in case is an organization user
|
||||
-- b) entity_name from the cdb_conf database in case is a non organization user
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_client._cdb_entity_config()
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_entity_config()
|
||||
RETURNS record AS $$
|
||||
DECLARE
|
||||
result cdb_geocoder_client._entity_config;
|
||||
result cdb_dataservices_client._entity_config;
|
||||
is_organization boolean;
|
||||
username text;
|
||||
organization_name text;
|
||||
@@ -34,4 +34,4 @@ BEGIN
|
||||
result.organization_name = organization_name;
|
||||
RETURN result;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
-- Make sure by default there are no permissions for publicuser
|
||||
-- NOTE: this happens at extension creation time, as part of an implicit transaction.
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser CASCADE;
|
||||
REVOKE ALL PRIVILEGES ON SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser CASCADE;
|
||||
|
||||
-- Grant permissions on the schema to publicuser (but just the schema)
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_client TO publicuser;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_client TO publicuser;
|
||||
|
||||
-- Revoke execute permissions on all functions in the schema by default
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_client FROM PUBLIC, publicuser;
|
||||
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_client FROM PUBLIC, publicuser;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>._<%= name %> (username text, organization_name text, <%= params_with_type_and_default %>)
|
||||
RETURNS <%= return_type %> AS $$
|
||||
CONNECT <%= GEOCODER_CLIENT_SCHEMA %>._server_conn_str();
|
||||
SELECT cdb_geocoder_server.<%= name %> (username, organization_name, <%= params %>);
|
||||
$$ LANGUAGE plproxy;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
GRANT EXECUTE ON FUNCTION <%= GEOCODER_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type %>) TO publicuser;
|
||||
@@ -5,7 +5,7 @@ CREATE EXTENSION plpythonu;
|
||||
CREATE EXTENSION cartodb;
|
||||
CREATE EXTENSION plproxy;
|
||||
-- Install the extension
|
||||
CREATE EXTENSION cdb_geocoder_client;
|
||||
CREATE EXTENSION cdb_dataservices_client;
|
||||
-- Mock the server connection to point to this very test db
|
||||
SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}');
|
||||
cdb_conf_setconf
|
||||
@@ -21,9 +21,9 @@ SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "enti
|
||||
(1 row)
|
||||
|
||||
-- Mock the server schema
|
||||
CREATE SCHEMA cdb_geocoder_server;
|
||||
CREATE SCHEMA cdb_dataservices_server;
|
||||
-- Create a test user to check permissions
|
||||
DROP ROLE IF EXISTS test_regular_user;
|
||||
CREATE ROLE test_regular_user;
|
||||
GRANT publicuser TO test_regular_user;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server function
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_admin0_polygon('Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params ("test_user", <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params ("test_user", <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin0_polygon
|
||||
----------------------------
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_admin1_polygon('California');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
@@ -26,8 +26,8 @@ PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_admin1_polygon('California', 'United States');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_namedplace_point('Elx');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -33,8 +33,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -42,8 +42,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL stateme
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_polygon
|
||||
--------------------------------
|
||||
@@ -26,8 +26,8 @@ PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL state
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_point
|
||||
------------------------------
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params ("test_user", <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params ("test_user", <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement
|
||||
cdb_geocode_ipaddress_point
|
||||
-----------------------------
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
-- Use regular user role
|
||||
SET ROLE test_regular_user;
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Exercise the public function
|
||||
-- it is public, it shall work
|
||||
SELECT cdb_geocode_admin0_polygon('Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params ("test_user", <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params ("test_user", <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin0_polygon
|
||||
----------------------------
|
||||
@@ -14,8 +14,8 @@ PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_admin1_polygon('California');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
@@ -23,8 +23,8 @@ PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_admin1_polygon('California', 'United States');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params ("test_user", <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
@@ -32,8 +32,8 @@ PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -41,8 +41,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Valencia)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Valencia)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -50,8 +50,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL stateme
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params ("test_user", <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -59,8 +59,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL st
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_polygon
|
||||
--------------------------------
|
||||
@@ -68,8 +68,8 @@ PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL state
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params ("test_user", <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_point
|
||||
------------------------------
|
||||
@@ -77,8 +77,8 @@ PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL stateme
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params ("test_user", <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params ("test_user", <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement
|
||||
cdb_geocode_ipaddress_point
|
||||
-----------------------------
|
||||
|
||||
@@ -6,7 +6,7 @@ CREATE EXTENSION cartodb;
|
||||
CREATE EXTENSION plproxy;
|
||||
|
||||
-- Install the extension
|
||||
CREATE EXTENSION cdb_geocoder_client;
|
||||
CREATE EXTENSION cdb_dataservices_client;
|
||||
|
||||
-- Mock the server connection to point to this very test db
|
||||
SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}');
|
||||
@@ -14,10 +14,10 @@ SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "d
|
||||
SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}');
|
||||
|
||||
-- Mock the server schema
|
||||
CREATE SCHEMA cdb_geocoder_server;
|
||||
CREATE SCHEMA cdb_dataservices_server;
|
||||
|
||||
-- Create a test user to check permissions
|
||||
DROP ROLE IF EXISTS test_regular_user;
|
||||
CREATE ROLE test_regular_user;
|
||||
GRANT publicuser TO test_regular_user;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server function
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
SET ROLE test_regular_user;
|
||||
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Exercise the public function
|
||||
-- it is public, it shall work
|
||||
|
||||
@@ -5,7 +5,7 @@ CREATE EXTENSION plpythonu;
|
||||
CREATE EXTENSION cartodb;
|
||||
CREATE EXTENSION plproxy;
|
||||
-- Install the extension
|
||||
CREATE EXTENSION cdb_geocoder_client;
|
||||
CREATE EXTENSION cdb_dataservices_client;
|
||||
-- Mock the server connection to point to this very test db
|
||||
SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}');
|
||||
cdb_conf_setconf
|
||||
@@ -21,9 +21,9 @@ SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "enti
|
||||
(1 row)
|
||||
|
||||
-- Mock the server schema
|
||||
CREATE SCHEMA cdb_geocoder_server;
|
||||
CREATE SCHEMA cdb_dataservices_server;
|
||||
-- Create a test user to check permissions
|
||||
DROP ROLE IF EXISTS test_regular_user;
|
||||
CREATE ROLE test_regular_user;
|
||||
GRANT publicuser TO test_regular_user;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server function
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_admin0_polygon('Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (test_user, <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (test_user, <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin0_polygon
|
||||
----------------------------
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_admin1_polygon('California');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
@@ -26,8 +26,8 @@ PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_admin1_polygon('California', 'United States');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_namedplace_point('Elx');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -33,8 +33,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -42,8 +42,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL stateme
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_polygon
|
||||
--------------------------------
|
||||
@@ -26,8 +26,8 @@ PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL state
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_point
|
||||
------------------------------
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (test_user, <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (test_user, <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement
|
||||
cdb_geocode_ipaddress_point
|
||||
-----------------------------
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (%, %, %, %, %, %)', username, orgname, searchtext, city, state_province, country;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (%, %, %, %, %, %)', username, orgname, searchtext, city, state_province, country;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Exercise the public and the proxied function
|
||||
SELECT cdb_geocode_street_point('One street, 1');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, 1, <NULL>, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, 1, <NULL>, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -19,8 +19,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -28,8 +28,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city', 'state');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -37,8 +37,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -46,8 +46,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -55,8 +55,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street, 1');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, 1, <NULL>, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, 1, <NULL>, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -64,8 +64,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -73,8 +73,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city', 'state');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -82,8 +82,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city', 'state', 'country');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, state, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
@@ -91,8 +91,8 @@ PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL s
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('One street', 'city', NULL, 'country');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, One street, city, <NULL>, country)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
-- Use regular user role
|
||||
SET ROLE test_regular_user;
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
-- Exercise the public function
|
||||
-- it is public, it shall work
|
||||
SELECT cdb_geocode_admin0_polygon('Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (test_user, <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin0_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (test_user, <NULL>, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin0_polygon(username, orgname, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin0_polygon
|
||||
----------------------------
|
||||
@@ -14,8 +14,8 @@ PL/pgSQL function cdb_geocode_admin0_polygon(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_admin1_polygon('California');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
@@ -23,8 +23,8 @@ PL/pgSQL function cdb_geocode_admin1_polygon(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_admin1_polygon('California', 'United States');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_admin1_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (test_user, <NULL>, California, United States)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_admin1_polygon(username, orgname, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_admin1_polygon
|
||||
----------------------------
|
||||
@@ -32,8 +32,8 @@ PL/pgSQL function cdb_geocode_admin1_polygon(text,text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -41,8 +41,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Valencia)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Valencia)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -50,8 +50,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text,text) line 15 at SQL stateme
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_namedplace_point('Elx', 'Valencia', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_namedplace_point(5): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (test_user, <NULL>, Elx, Valencia, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_namedplace_point(username, orgname, city_name, admin1_name, country_name)"
|
||||
PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_namedplace_point
|
||||
------------------------------
|
||||
@@ -59,8 +59,8 @@ PL/pgSQL function cdb_geocode_namedplace_point(text,text,text) line 15 at SQL st
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_postalcode_polygon('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_polygon(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_polygon
|
||||
--------------------------------
|
||||
@@ -68,8 +68,8 @@ PL/pgSQL function cdb_geocode_postalcode_polygon(text,text) line 15 at SQL state
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_postalcode_point('03204', 'Spain');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_postalcode_point(4): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params (test_user, <NULL>, 03204, Spain)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_postalcode_point(username, orgname, postal_code, country_name)"
|
||||
PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL statement
|
||||
cdb_geocode_postalcode_point
|
||||
------------------------------
|
||||
@@ -77,8 +77,8 @@ PL/pgSQL function cdb_geocode_postalcode_point(text,text) line 15 at SQL stateme
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_ipaddress_point('8.8.8.8');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (test_user, <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_ipaddress_point(3): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (test_user, <NULL>, 8.8.8.8)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_ipaddress_point(username, orgname, ip_address)"
|
||||
PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement
|
||||
cdb_geocode_ipaddress_point
|
||||
-----------------------------
|
||||
@@ -86,8 +86,8 @@ PL/pgSQL function cdb_geocode_ipaddress_point(text) line 15 at SQL statement
|
||||
(1 row)
|
||||
|
||||
SELECT cdb_geocode_street_point('one street, 1');
|
||||
NOTICE: cdb_geocoder_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, one street, 1, <NULL>, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_geocoder_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
NOTICE: cdb_dataservices_client._cdb_geocode_street_point(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (test_user, <NULL>, one street, 1, <NULL>, <NULL>, <NULL>)
|
||||
CONTEXT: SQL statement "SELECT cdb_dataservices_client._cdb_geocode_street_point(username, orgname, searchtext, city, state_province, country)"
|
||||
PL/pgSQL function cdb_geocode_street_point(text,text,text,text) line 15 at SQL statement
|
||||
cdb_geocode_street_point
|
||||
--------------------------
|
||||
|
||||
@@ -6,7 +6,7 @@ CREATE EXTENSION cartodb;
|
||||
CREATE EXTENSION plproxy;
|
||||
|
||||
-- Install the extension
|
||||
CREATE EXTENSION cdb_geocoder_client;
|
||||
CREATE EXTENSION cdb_dataservices_client;
|
||||
|
||||
-- Mock the server connection to point to this very test db
|
||||
SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "dbname=contrib_regression host=127.0.0.1 user=postgres"}');
|
||||
@@ -14,10 +14,10 @@ SELECT cartodb.cdb_conf_setconf('geocoder_server_config', '{"connection_str": "d
|
||||
SELECT cartodb.cdb_conf_setconf('user_config', '{"is_organization": false, "entity_name": "test_user"}');
|
||||
|
||||
-- Mock the server schema
|
||||
CREATE SCHEMA cdb_geocoder_server;
|
||||
CREATE SCHEMA cdb_dataservices_server;
|
||||
|
||||
-- Create a test user to check permissions
|
||||
DROP ROLE IF EXISTS test_regular_user;
|
||||
CREATE ROLE test_regular_user;
|
||||
GRANT publicuser TO test_regular_user;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
ALTER ROLE test_regular_user SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server function
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin0_polygon invoked with params (%, %, %)', username, orgname, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %)', username, orgname, admin1_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_admin1_polygon invoked with params (%, %, %, %)', username, orgname, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %)', username, orgname, city_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %)', username, orgname, city_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_namedplace_point invoked with params (%, %, %, %, %)', username, orgname, city_name, admin1_name, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_polygon invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, postal_code text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_postalcode_point invoked with params (%, %, %, %)', username, orgname, postal_code, country_name;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip_address text)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_ipaddress_point invoked with params (%, %, %)', username, orgname, ip_address;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Mock the server functions
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point (username text, orgname text, searchtext text, city text DEFAULT NULL, state_province text DEFAULT NULL, country text DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
BEGIN
|
||||
RAISE NOTICE 'cdb_geocoder_server.cdb_geocode_geocoder_street_point invoked with params (%, %, %, %, %, %)', username, orgname, searchtext, city, state_province, country;
|
||||
RAISE NOTICE 'cdb_dataservices_server.cdb_geocode_geocoder_street_point invoked with params (%, %, %, %, %, %)', username, orgname, searchtext, city, state_province, country;
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
SET ROLE test_regular_user;
|
||||
|
||||
-- Add to the search path the schema
|
||||
SET search_path TO public,cartodb,cdb_geocoder_client;
|
||||
SET search_path TO public,cartodb,cdb_dataservices_client;
|
||||
|
||||
-- Exercise the public function
|
||||
-- it is public, it shall work
|
||||
|
||||
1
server/extension/.gitignore
vendored
1
server/extension/.gitignore
vendored
@@ -4,3 +4,4 @@ regression.out
|
||||
cdb_geocoder_server--0.0.1.sql
|
||||
cdb_geocoder_server--0.1.0.sql
|
||||
cdb_geocoder_server--0.2.0.sql
|
||||
cdb_geocoder_server--0.3.0.sql
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Makefile to generate the extension out of separate sql source files.
|
||||
# Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed.
|
||||
EXTENSION = cdb_geocoder_server
|
||||
EXTENSION = cdb_dataservices_server
|
||||
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
||||
|
||||
# The new version to be generated from templates
|
||||
@@ -11,13 +11,15 @@ NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
|
||||
# for installation from scratch, upgrades and downgrades.
|
||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||
cdb_geocoder_server--0.0.1.sql \
|
||||
cdb_geocoder_server--0.1.0.sql \
|
||||
cdb_geocoder_server--0.1.0--0.0.1.sql \
|
||||
cdb_geocoder_server--0.0.1--0.1.0.sql \
|
||||
cdb_geocoder_server--0.2.0--0.1.0.sql \
|
||||
cdb_geocoder_server--0.1.0--0.2.0.sql
|
||||
|
||||
cdb_dataservices_server--0.0.1.sql \
|
||||
cdb_dataservices_server--0.1.0.sql \
|
||||
cdb_dataservices_server--0.2.0.sql \
|
||||
cdb_dataservices_server--0.1.0--0.0.1.sql \
|
||||
cdb_dataservices_server--0.0.1--0.1.0.sql \
|
||||
cdb_dataservices_server--0.2.0--0.1.0.sql \
|
||||
cdb_dataservices_server--0.1.0--0.2.0.sql \
|
||||
cdb_dataservices_server--0.2.0--0.3.0.sql \
|
||||
cdb_dataservices_server--0.3.0--0.2.0.sql
|
||||
|
||||
REGRESS = $(notdir $(basename $(wildcard test/$(EXTVERSION)/sql/*test.sql)))
|
||||
TEST_DIR = test/$(EXTVERSION)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# CartoDB geocoder API server extension
|
||||
Postgres extension for the CartoDB geocoder API, server side.
|
||||
# CartoDB dataservices API server extension
|
||||
Postgres extension for the CartoDB dataservices API, server side.
|
||||
|
||||
## Dependencies
|
||||
This extension is thought to be used on top of CartoDB geocoder extension, for the internal geocoder.
|
||||
@@ -39,7 +39,7 @@ psql -U postgres cartodb_dev_user_fe3b850a-01c0-48f9-8a26-a82f09e9b53f_db
|
||||
and then:
|
||||
|
||||
```sql
|
||||
CREATE EXTENSION cdb_geocoder_server;
|
||||
CREATE EXTENSION cdb_dataservices_server;
|
||||
```
|
||||
|
||||
The extension creation in the user's db requires **superuser** privileges.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf_query = "SELECT cartodb.CDB_Conf_GetConf('{0}') as conf".format(config_key)
|
||||
conf = plpy.execute(conf_query)[0]['conf']
|
||||
if conf is None:
|
||||
@@ -18,7 +18,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -27,10 +27,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_geocoder import redis_helper
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = redis_helper.RedisHelper(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
@@ -49,7 +49,7 @@ RETURNS boolean AS $$
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -57,7 +57,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_geocoder import config_helper
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
@@ -75,26 +75,26 @@ RETURNS boolean AS $$
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server.cdb_geocode_street_point(TEXT, TEXT, TEXT, TEXT);
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_geocode_street_point(TEXT, TEXT, TEXT, TEXT);
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
plpy.execute("SELECT cdb_geocoder_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
elif user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Requested geocoder is not available')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from heremaps import heremapsgeocoder
|
||||
from cartodb_geocoder import quota_service
|
||||
@@ -128,15 +128,15 @@ RETURNS Geometry AS $$
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.error('Google geocoder is not available yet')
|
||||
return None
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- We apply again the grants to include the new functions
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit
|
||||
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
@@ -9,8 +9,8 @@ CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf()
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf()
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('redis_conf') conf")[0]['conf']
|
||||
if conf is None:
|
||||
plpy.error("There is no redis configuration defined")
|
||||
@@ -27,7 +27,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
if user_id in GD and 'redis_connection' in GD[user_id]:
|
||||
return False
|
||||
@@ -35,7 +35,7 @@ RETURNS boolean AS $$
|
||||
from cartodb_geocoder import redis_helper
|
||||
config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf() c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf() c;""")[0]
|
||||
redis_connection = redis_helper.RedisHelper(config_params['sentinel_host'],
|
||||
config_params['sentinel_port'],
|
||||
config_params['sentinel_master_id'],
|
||||
@@ -44,13 +44,13 @@ RETURNS boolean AS $$
|
||||
GD[user_id] = {'redis_connection': redis_connection}
|
||||
return True
|
||||
$$ LANGUAGE plpythonu;-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry
|
||||
AS $$
|
||||
import json
|
||||
from heremaps import heremapsgeocoder
|
||||
|
||||
heremaps_conf = json.loads(plpy.execute("SELECT cdb_geocoder_server._get_conf('heremaps')", 1)[0]['get_conf'])
|
||||
heremaps_conf = json.loads(plpy.execute("SELECT cdb_dataservices_server._get_conf('heremaps')", 1)[0]['get_conf'])
|
||||
|
||||
app_id = heremaps_conf['geocoder']['app_id']
|
||||
app_code = heremaps_conf['geocoder']['app_code']
|
||||
@@ -66,7 +66,7 @@ AS $$
|
||||
return point['st_setsrid']
|
||||
$$ LANGUAGE plpythonu;-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -75,7 +75,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._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
@@ -87,7 +87,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -104,7 +104,7 @@ $$ LANGUAGE plpgsql;
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -113,7 +113,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._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
@@ -121,7 +121,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -130,7 +130,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._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
@@ -143,7 +143,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -167,7 +167,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -193,7 +193,7 @@ $$ LANGUAGE plpgsql;
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -202,7 +202,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._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from geocode_namedplace')
|
||||
@@ -210,7 +210,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -219,7 +219,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._cdb_geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -227,7 +227,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -236,7 +236,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._cdb_geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -249,7 +249,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -268,7 +268,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -288,7 +288,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -313,7 +313,7 @@ $$ LANGUAGE plpgsql;
|
||||
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -322,14 +322,14 @@ 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._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -338,14 +338,14 @@ 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._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -354,14 +354,14 @@ 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._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -370,7 +370,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._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
@@ -382,7 +382,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -403,7 +403,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -428,7 +428,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -449,7 +449,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -475,7 +475,7 @@ END
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -484,7 +484,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._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
@@ -496,7 +496,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_ipaddress_point(ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -531,9 +531,9 @@ BEGIN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
END$$;
|
||||
29
server/extension/cdb_dataservices_server--0.1.0--0.0.1.sql
Normal file
29
server/extension/cdb_dataservices_server--0.1.0--0.0.1.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._get_redis_conf_v2(text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._connect_to_redis(text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._get_geocoder_config(text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_geocode_street_point_v2(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_here_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_dataservices_server._cdb_google_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry
|
||||
AS $$
|
||||
import json
|
||||
from heremaps import heremapsgeocoder
|
||||
|
||||
heremaps_conf = json.loads(plpy.execute("SELECT cdb_dataservices_server._get_conf('heremaps')", 1)[0]['get_conf'])
|
||||
|
||||
app_id = heremaps_conf['geocoder']['app_id']
|
||||
app_code = heremaps_conf['geocoder']['app_code']
|
||||
|
||||
geocoder = heremapsgeocoder.Geocoder(app_id, app_code)
|
||||
|
||||
results = geocoder.geocode_address(searchtext=searchtext, city=city, state=state_province, country=country)
|
||||
coordinates = geocoder.extract_lng_lat_from_result(results[0])
|
||||
|
||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
|
||||
return point['st_setsrid']
|
||||
$$ LANGUAGE plpythonu;
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -7,7 +7,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_services.metrics import GeocoderConfig
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
@@ -25,7 +25,7 @@ RETURNS boolean AS $$
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -34,10 +34,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_services.tools import RedisConnection
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = RedisConnection(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
@@ -55,7 +55,7 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.here import HereMapsGeocoder
|
||||
from cartodb_services.metrics import QuotaService
|
||||
@@ -90,7 +90,7 @@ RETURNS Geometry AS $$
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.google import GoogleMapsGeocoder
|
||||
from cartodb_services.metrics import QuotaService
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit
|
||||
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
@@ -9,8 +9,8 @@ CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf_query = "SELECT cartodb.CDB_Conf_GetConf('{0}') as conf".format(config_key)
|
||||
conf = plpy.execute(conf_query)[0]['conf']
|
||||
if conf is None:
|
||||
@@ -28,7 +28,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -37,10 +37,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_geocoder import redis_helper
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = redis_helper.RedisHelper(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
@@ -58,7 +58,7 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -66,7 +66,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_geocoder import config_helper
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
@@ -83,25 +83,25 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
plpy.execute("SELECT cdb_geocoder_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
elif user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Requested geocoder is not available')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from heremaps import heremapsgeocoder
|
||||
from cartodb_geocoder import quota_service
|
||||
@@ -135,14 +135,14 @@ RETURNS Geometry AS $$
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.error('Google geocoder is not available yet')
|
||||
return None
|
||||
$$ LANGUAGE plpythonu;
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -151,7 +151,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._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
@@ -163,7 +163,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -180,7 +180,7 @@ $$ LANGUAGE plpgsql;
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -189,7 +189,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._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
@@ -197,7 +197,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -206,7 +206,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._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
@@ -219,7 +219,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -243,7 +243,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -269,7 +269,7 @@ $$ LANGUAGE plpgsql;
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -278,7 +278,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._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from geocode_namedplace')
|
||||
@@ -286,7 +286,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -295,7 +295,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._cdb_geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -303,7 +303,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -312,7 +312,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._cdb_geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -325,7 +325,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -344,7 +344,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -364,7 +364,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -389,7 +389,7 @@ $$ LANGUAGE plpgsql;
|
||||
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -398,14 +398,14 @@ 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._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -414,14 +414,14 @@ 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._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -430,14 +430,14 @@ 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._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -446,7 +446,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._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
@@ -458,7 +458,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -479,7 +479,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -504,7 +504,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -525,7 +525,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -551,7 +551,7 @@ END
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -560,7 +560,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._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
@@ -572,7 +572,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_ipaddress_point(ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -607,9 +607,9 @@ BEGIN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
END$$;
|
||||
@@ -1,5 +1,5 @@
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -7,7 +7,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_geocoder import config_helper
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
@@ -25,7 +25,7 @@ RETURNS boolean AS $$
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -34,10 +34,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_geocoder import redis_helper
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = redis_helper.RedisHelper(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
@@ -55,7 +55,7 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from heremaps import heremapsgeocoder
|
||||
from cartodb_geocoder import quota_service
|
||||
@@ -88,7 +88,7 @@ RETURNS Geometry AS $$
|
||||
plpy.error(error_msg)
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.error('Google geocoder is not available yet')
|
||||
return None
|
||||
340
server/extension/cdb_dataservices_server--0.2.0--0.3.0.sql
Normal file
340
server/extension/cdb_dataservices_server--0.2.0--0.3.0.sql
Normal file
@@ -0,0 +1,340 @@
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1), trim($2)) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1)) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2)) AS mypoint", ["text", "text"])
|
||||
rv = plpy.execute(plan, [city_name, country_name], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2), trim($3)) AS mypoint", ["text", "text", "text"])
|
||||
rv = plpy.execute(plan, [city_name, admin1_name, country_name], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1), trim($2)) AS mypoint", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1)) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1), trim($2)) AS mypolygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
@@ -1,7 +1,7 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit
|
||||
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
@@ -10,8 +10,8 @@ CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf_query = "SELECT cartodb.CDB_Conf_GetConf('{0}') as conf".format(config_key)
|
||||
conf = plpy.execute(conf_query)[0]['conf']
|
||||
if conf is None:
|
||||
@@ -29,7 +29,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -38,10 +38,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_services.tools import RedisConnection
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = RedisConnection(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
@@ -59,7 +59,7 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -67,7 +67,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_services.metrics import GeocoderConfig
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
@@ -84,25 +84,25 @@ RETURNS boolean AS $$
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point_v2(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
plpy.execute("SELECT cdb_geocoder_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
elif user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Requested geocoder is not available')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.here import HereMapsGeocoder
|
||||
from cartodb_services.metrics import QuotaService
|
||||
@@ -137,7 +137,7 @@ RETURNS Geometry AS $$
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.google import GoogleMapsGeocoder
|
||||
from cartodb_services.metrics import QuotaService
|
||||
@@ -169,7 +169,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -178,7 +178,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._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
@@ -190,7 +190,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -207,7 +207,7 @@ $$ LANGUAGE plpgsql;
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -216,7 +216,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._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
@@ -224,7 +224,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -233,7 +233,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._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
@@ -246,7 +246,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -270,7 +270,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -296,7 +296,7 @@ $$ LANGUAGE plpgsql;
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -305,7 +305,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._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from geocode_namedplace')
|
||||
@@ -313,7 +313,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -322,7 +322,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._cdb_geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -330,7 +330,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -339,7 +339,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._cdb_geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -352,7 +352,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -371,7 +371,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -391,7 +391,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -416,7 +416,7 @@ $$ LANGUAGE plpgsql;
|
||||
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -425,14 +425,14 @@ 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._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -441,14 +441,14 @@ 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._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -457,14 +457,14 @@ 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._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -473,7 +473,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._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
@@ -485,7 +485,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -506,7 +506,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -531,7 +531,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -552,7 +552,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -578,7 +578,7 @@ END
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -587,7 +587,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._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
@@ -599,7 +599,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_ipaddress_point(ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -634,9 +634,9 @@ BEGIN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
END$$;
|
||||
175
server/extension/cdb_dataservices_server--0.3.0--0.2.0.sql
Normal file
175
server/extension/cdb_dataservices_server--0.3.0--0.2.0.sql
Normal file
@@ -0,0 +1,175 @@
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
return rv[0]["mypolygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
return rv[0]["mypolygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
return rv[0]["mypolygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_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;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_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;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_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')
|
||||
return rv[0]["mypoint"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
|
||||
#--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_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
795
server/extension/cdb_dataservices_server--0.3.0.sql
Normal file
795
server/extension/cdb_dataservices_server--0.3.0.sql
Normal file
@@ -0,0 +1,795 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
redis_db text,
|
||||
timeout float
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf_query = "SELECT cartodb.CDB_Conf_GetConf('{0}') as conf".format(config_key)
|
||||
conf = plpy.execute(conf_query)[0]['conf']
|
||||
if conf is None:
|
||||
plpy.error("There is no redis configuration defined")
|
||||
else:
|
||||
import json
|
||||
params = json.loads(conf)
|
||||
return {
|
||||
"sentinel_host": params['sentinel_host'],
|
||||
"sentinel_port": params['sentinel_port'],
|
||||
"sentinel_master_id": params['sentinel_master_id'],
|
||||
"timeout": params['timeout'],
|
||||
"redis_db": params['redis_db']
|
||||
}
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
return False
|
||||
else:
|
||||
from cartodb_services.tools import RedisConnection
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = RedisConnection(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
timeout=metadata_config_params['timeout'],
|
||||
redis_db=metadata_config_params['redis_db']).redis_connection()
|
||||
redis_metrics_connection = RedisConnection(metrics_config_params['sentinel_host'],
|
||||
metrics_config_params['sentinel_port'],
|
||||
metrics_config_params['sentinel_master_id'],
|
||||
timeout=metrics_config_params['timeout'],
|
||||
redis_db=metrics_config_params['redis_db']).redis_connection()
|
||||
GD[cache_key] = {
|
||||
'redis_metadata_connection': redis_metadata_connection,
|
||||
'redis_metrics_connection': redis_metrics_connection,
|
||||
}
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
return False
|
||||
else:
|
||||
import json
|
||||
from cartodb_services.quota import GeocoderConfig
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
heremaps_app_id = None
|
||||
heremaps_app_code = None
|
||||
else:
|
||||
heremaps_conf = json.loads(heremaps_conf_json)
|
||||
heremaps_app_id = heremaps_conf['app_id']
|
||||
heremaps_app_code = heremaps_conf['app_code']
|
||||
geocoder_config = GeocoderConfig(redis_conn, username, orgname, heremaps_app_id, heremaps_app_code)
|
||||
# --Think about the security concerns with this kind of global cache, it should be only available
|
||||
# --for this user session but...
|
||||
GD[cache_key] = geocoder_config
|
||||
return True
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
elif user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Requested geocoder is not available')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.here import HereMapsGeocoder
|
||||
from cartodb_services.quota import QuotaService
|
||||
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
# -- Check the quota
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
if not quota_service.check_user_quota():
|
||||
plpy.error('You have reach the limit of your quota')
|
||||
|
||||
try:
|
||||
geocoder = HereMapsGeocoder(user_geocoder_config.heremaps_app_id, user_geocoder_config.heremaps_app_code)
|
||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city, state=state_province, country=country)
|
||||
if coordinates:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
return point['st_setsrid']
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using here maps geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.google import GoogleMapsGeocoder
|
||||
from cartodb_services.quota import QuotaService
|
||||
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
|
||||
try:
|
||||
geocoder = GoogleMapsGeocoder(user_geocoder_config.google_client_id, user_geocoder_config.google_api_key)
|
||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city, state=state_province, country=country)
|
||||
if coordinates:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
return point['st_setsrid']
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using google maps geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
BEGIN
|
||||
SELECT n.the_geom as geom INTO ret
|
||||
FROM (SELECT q, lower(regexp_replace(q, '[^a-zA-Z\u00C0-\u00ff]+', '', 'g'))::text x
|
||||
FROM (SELECT country_name q) g) d
|
||||
LEFT OUTER JOIN admin0_synonyms s ON name_ = d.x
|
||||
LEFT OUTER JOIN ne_admin0_v3 n ON s.adm0_a3 = n.adm0_a3 GROUP BY d.q, n.the_geom, s.adm0_a3;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1), trim($2)) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
BEGIN
|
||||
SELECT geom INTO ret
|
||||
FROM (
|
||||
SELECT q, (
|
||||
SELECT the_geom
|
||||
FROM global_province_polygons
|
||||
WHERE d.c = ANY (synonyms)
|
||||
ORDER BY frequency DESC LIMIT 1
|
||||
) geom
|
||||
FROM (
|
||||
SELECT
|
||||
trim(replace(lower(admin1_name),'.',' ')) c, admin1_name q
|
||||
) d
|
||||
) v;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
BEGIN
|
||||
WITH p AS (SELECT r.c, r.q, (SELECT iso3 FROM country_decoder WHERE lower(country_name) = ANY (synonyms)) i FROM (SELECT trim(replace(lower(admin1_name),'.',' ')) c, country_name q) r)
|
||||
SELECT
|
||||
geom INTO ret
|
||||
FROM (
|
||||
SELECT
|
||||
q, (
|
||||
SELECT the_geom
|
||||
FROM global_province_polygons
|
||||
WHERE p.c = ANY (synonyms)
|
||||
AND iso3 = p.i
|
||||
ORDER BY frequency DESC LIMIT 1
|
||||
) geom
|
||||
FROM p) n;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1)) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2)) AS mypoint", ["text", "text"])
|
||||
rv = plpy.execute(plan, [city_name, country_name], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2), trim($3)) AS mypoint", ["text", "text", "text"])
|
||||
rv = plpy.execute(plan, [city_name, admin1_name, country_name], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
BEGIN
|
||||
SELECT geom INTO ret
|
||||
FROM (
|
||||
WITH best AS (SELECT s AS q, (SELECT the_geom FROM global_cities_points_limited gp WHERE gp.lowername = lower(p.s) ORDER BY population DESC LIMIT 1) AS geom FROM (SELECT city_name as s) p),
|
||||
next AS (SELECT p.s AS q, (SELECT gp.the_geom FROM global_cities_points_limited gp, global_cities_alternates_limited ga WHERE lower(p.s) = ga.lowername AND ga.geoname_id = gp.geoname_id ORDER BY preferred DESC LIMIT 1) geom FROM (SELECT city_name as s) p WHERE p.s NOT IN (SELECT q FROM best WHERE geom IS NOT NULL))
|
||||
SELECT q, geom, TRUE AS success FROM best WHERE geom IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT q, geom, CASE WHEN geom IS NULL THEN FALSE ELSE TRUE END AS success FROM next
|
||||
) v;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
BEGIN
|
||||
SELECT geom INTO ret
|
||||
FROM (
|
||||
WITH p AS (SELECT r.s, r.c, (SELECT iso2 FROM country_decoder WHERE lower(r.c) = ANY (synonyms)) i FROM (SELECT city_name AS s, country_name::text AS c) r),
|
||||
best AS (SELECT p.s AS q, p.c AS c, (SELECT gp.the_geom AS geom FROM global_cities_points_limited gp WHERE gp.lowername = lower(p.s) AND gp.iso2 = p.i ORDER BY population DESC LIMIT 1) AS geom FROM p),
|
||||
next AS (SELECT p.s AS q, p.c AS c, (SELECT gp.the_geom FROM global_cities_points_limited gp, global_cities_alternates_limited ga WHERE lower(p.s) = ga.lowername AND gp.iso2 = p.i AND ga.geoname_id = gp.geoname_id ORDER BY preferred DESC LIMIT 1) geom FROM p WHERE p.s NOT IN (SELECT q FROM best WHERE c = p.c AND geom IS NOT NULL))
|
||||
SELECT geom FROM best WHERE geom IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT geom FROM next
|
||||
) v;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
BEGIN
|
||||
SELECT geom INTO ret
|
||||
FROM (
|
||||
WITH inputcountry AS (
|
||||
SELECT iso2 as isoTwo FROM country_decoder WHERE lower(country_name) = ANY (synonyms) LIMIT 1
|
||||
),
|
||||
p AS (
|
||||
SELECT r.s, r.a1, (SELECT admin1 FROM admin1_decoder, inputcountry WHERE lower(r.a1) = ANY (synonyms) AND admin1_decoder.iso2 = inputcountry.isoTwo LIMIT 1) i FROM (SELECT city_name AS s, admin1_name::text AS a1) r),
|
||||
best AS (SELECT p.s AS q, p.a1 as a1, (SELECT gp.the_geom AS geom FROM global_cities_points_limited gp WHERE gp.lowername = lower(p.s) AND gp.admin1 = p.i ORDER BY population DESC LIMIT 1) AS geom FROM p),
|
||||
next AS (SELECT p.s AS q, p.a1 AS a1, (SELECT gp.the_geom FROM global_cities_points_limited gp, global_cities_alternates_limited ga WHERE lower(p.s) = ga.lowername AND ga.admin1 = p.i AND ga.geoname_id = gp.geoname_id ORDER BY preferred DESC LIMIT 1) geom FROM p WHERE p.s NOT IN (SELECT q FROM best WHERE geom IS NOT NULL))
|
||||
SELECT geom FROM best WHERE geom IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT geom FROM next
|
||||
) v;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1), trim($2)) AS mypoint", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1)) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1), trim($2)) AS mypolygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
result = rv[0]["mypolygon"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code 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)
|
||||
LIMIT 1
|
||||
) geom
|
||||
FROM (SELECT code q) d
|
||||
) v;
|
||||
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_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;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_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 cdb_dataservices_server._cdb_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;
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.metrics import QuotaService
|
||||
from cartodb_services.metrics import InternalGeocoderConfig
|
||||
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
user_geocoder_config = InternalGeocoderConfig(redis_conn, username, orgname)
|
||||
|
||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||
try:
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
result = rv[0]["mypoint"]
|
||||
if result:
|
||||
quota_service.increment_success_geocoder_use()
|
||||
return result
|
||||
else:
|
||||
quota_service.increment_empty_geocoder_use()
|
||||
return None
|
||||
except BaseException as e:
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to geocode using admin0 geocoder: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
new_ip INET;
|
||||
BEGIN
|
||||
BEGIN
|
||||
IF family(ip::inet) = 6 THEN
|
||||
new_ip := ip::inet;
|
||||
ELSE
|
||||
new_ip := ('::ffff:' || ip)::inet;
|
||||
END IF;
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
SELECT NULL as geom INTO ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
|
||||
WITH
|
||||
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;
|
||||
RETURN ret;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT *
|
||||
FROM pg_catalog.pg_user
|
||||
WHERE usename = 'geocoder_api') THEN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
5
server/extension/cdb_dataservices_server.control
Normal file
5
server/extension/cdb_dataservices_server.control
Normal file
@@ -0,0 +1,5 @@
|
||||
comment = 'CartoDB dataservices server extension'
|
||||
default_version = '0.3.0'
|
||||
requires = 'plpythonu, postgis, cdb_geocoder'
|
||||
superuser = true
|
||||
schema = cdb_dataservices_server
|
||||
@@ -1,29 +0,0 @@
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server._get_redis_conf_v2(text);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server._connect_to_redis(text);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server._get_geocoder_config(text, text);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server.cdb_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server.cdb_geocode_street_point_v2(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server._cdb_here_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
DROP FUNCTION IF EXISTS cdb_geocoder_server._cdb_google_geocode_street_point(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT);
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry
|
||||
AS $$
|
||||
import json
|
||||
from heremaps import heremapsgeocoder
|
||||
|
||||
heremaps_conf = json.loads(plpy.execute("SELECT cdb_geocoder_server._get_conf('heremaps')", 1)[0]['get_conf'])
|
||||
|
||||
app_id = heremaps_conf['geocoder']['app_id']
|
||||
app_code = heremaps_conf['geocoder']['app_code']
|
||||
|
||||
geocoder = heremapsgeocoder.Geocoder(app_id, app_code)
|
||||
|
||||
results = geocoder.geocode_address(searchtext=searchtext, city=city, state=state_province, country=country)
|
||||
coordinates = geocoder.extract_lng_lat_from_result(results[0])
|
||||
|
||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
|
||||
return point['st_setsrid']
|
||||
$$ LANGUAGE plpythonu;
|
||||
@@ -1,6 +0,0 @@
|
||||
# cdb geocoder server extension
|
||||
comment = 'CartoDB server geocoder extension'
|
||||
default_version = '0.2.0'
|
||||
requires = 'plpythonu, postgis, cdb_geocoder'
|
||||
superuser = true
|
||||
schema = cdb_geocoder_server
|
||||
@@ -1,3 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
@@ -7,8 +7,8 @@ CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf()
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf()
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('redis_conf') conf")[0]['conf']
|
||||
if conf is None:
|
||||
plpy.error("There is no redis configuration defined")
|
||||
@@ -25,7 +25,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
if user_id in GD and 'redis_connection' in GD[user_id]:
|
||||
return False
|
||||
@@ -33,7 +33,7 @@ RETURNS boolean AS $$
|
||||
from cartodb_geocoder import redis_helper
|
||||
config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf() c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf() c;""")[0]
|
||||
redis_connection = redis_helper.RedisHelper(config_params['sentinel_host'],
|
||||
config_params['sentinel_port'],
|
||||
config_params['sentinel_master_id'],
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry
|
||||
AS $$
|
||||
import json
|
||||
from heremaps import heremapsgeocoder
|
||||
|
||||
heremaps_conf = json.loads(plpy.execute("SELECT cdb_geocoder_server._get_conf('heremaps')", 1)[0]['get_conf'])
|
||||
heremaps_conf = json.loads(plpy.execute("SELECT cdb_dataservices_server._get_conf('heremaps')", 1)[0]['get_conf'])
|
||||
|
||||
app_id = heremaps_conf['geocoder']['app_id']
|
||||
app_code = heremaps_conf['geocoder']['app_code']
|
||||
@@ -19,4 +19,4 @@ AS $$
|
||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||
|
||||
return point['st_setsrid']
|
||||
$$ LANGUAGE plpythonu;
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,7 +9,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._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
@@ -21,7 +21,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -10,7 +10,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._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
@@ -18,7 +18,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -27,7 +27,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._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
@@ -40,7 +40,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -64,7 +64,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -10,7 +10,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._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from geocode_namedplace')
|
||||
@@ -18,7 +18,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -27,7 +27,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._cdb_geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -35,7 +35,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -44,7 +44,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._cdb_geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -57,7 +57,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -76,7 +76,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -96,7 +96,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,14 +9,14 @@ 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._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -25,14 +25,14 @@ 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._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -41,14 +41,14 @@ 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._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -57,7 +57,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._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
@@ -69,7 +69,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -90,7 +90,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -115,7 +115,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -136,7 +136,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,7 +9,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._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
@@ -21,7 +21,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_ipaddress_point(ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -7,9 +7,9 @@ BEGIN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
END$$;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
@@ -7,8 +7,8 @@ CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf_query = "SELECT cartodb.CDB_Conf_GetConf('{0}') as conf".format(config_key)
|
||||
conf = plpy.execute(conf_query)[0]['conf']
|
||||
if conf is None:
|
||||
@@ -26,7 +26,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -35,10 +35,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_geocoder import redis_helper
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = redis_helper.RedisHelper(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -7,7 +7,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_geocoder import config_helper
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
plpy.execute("SELECT cdb_geocoder_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
elif user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Requested geocoder is not available')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from heremaps import heremapsgeocoder
|
||||
from cartodb_geocoder import quota_service
|
||||
@@ -51,7 +51,7 @@ RETURNS Geometry AS $$
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.error('Google geocoder is not available yet')
|
||||
return None
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,7 +9,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._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
@@ -21,7 +21,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -10,7 +10,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._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
@@ -18,7 +18,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -27,7 +27,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._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
@@ -40,7 +40,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -64,7 +64,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -10,7 +10,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._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from geocode_namedplace')
|
||||
@@ -18,7 +18,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -27,7 +27,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._cdb_geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -35,7 +35,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -44,7 +44,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._cdb_geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -57,7 +57,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -76,7 +76,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -96,7 +96,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,14 +9,14 @@ 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._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -25,14 +25,14 @@ 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._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -41,14 +41,14 @@ 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._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -57,7 +57,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._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
@@ -69,7 +69,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -90,7 +90,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -115,7 +115,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -136,7 +136,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,7 +9,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._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
@@ -21,7 +21,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_ipaddress_point(ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -7,9 +7,9 @@ BEGIN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
END$$;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
CREATE TYPE cdb_dataservices_server._redis_conf_params AS (
|
||||
sentinel_host text,
|
||||
sentinel_port int,
|
||||
sentinel_master_id text,
|
||||
@@ -7,8 +7,8 @@ CREATE TYPE cdb_geocoder_server._redis_conf_params AS (
|
||||
);
|
||||
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_redis_conf_v2(config_key text)
|
||||
RETURNS cdb_dataservices_server._redis_conf_params AS $$
|
||||
conf_query = "SELECT cartodb.CDB_Conf_GetConf('{0}') as conf".format(config_key)
|
||||
conf = plpy.execute(conf_query)[0]['conf']
|
||||
if conf is None:
|
||||
@@ -26,7 +26,7 @@ RETURNS cdb_geocoder_server._redis_conf_params AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
-- Get the connection to redis from cache or create a new one
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._connect_to_redis(user_id text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._connect_to_redis(user_id text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "redis_connection_{0}".format(user_id)
|
||||
if cache_key in GD:
|
||||
@@ -35,10 +35,10 @@ RETURNS boolean AS $$
|
||||
from cartodb_services.tools import RedisConnection
|
||||
metadata_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metadata_config') c;""")[0]
|
||||
metrics_config_params = plpy.execute("""select c.sentinel_host, c.sentinel_port,
|
||||
c.sentinel_master_id, c.timeout, c.redis_db
|
||||
from cdb_geocoder_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
from cdb_dataservices_server._get_redis_conf_v2('redis_metrics_config') c;""")[0]
|
||||
redis_metadata_connection = RedisConnection(metadata_config_params['sentinel_host'],
|
||||
metadata_config_params['sentinel_port'],
|
||||
metadata_config_params['sentinel_master_id'],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- Get the Redis configuration from the _conf table --
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._get_geocoder_config(username text, orgname text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text)
|
||||
RETURNS boolean AS $$
|
||||
cache_key = "user_geocoder_config_{0}".format(username)
|
||||
if cache_key in GD:
|
||||
@@ -7,7 +7,7 @@ RETURNS boolean AS $$
|
||||
else:
|
||||
import json
|
||||
from cartodb_services.metrics import GeocoderConfig
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metadata_connection']
|
||||
heremaps_conf_json = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as heremaps_conf", 1)[0]['heremaps_conf']
|
||||
if not heremaps_conf_json:
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
-- Geocodes a street address given a searchtext and a state and/or country
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_street_point_v2(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.execute("SELECT cdb_geocoder_server._connect_to_redis('{0}')".format(username))
|
||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||
plpy.execute("SELECT cdb_geocoder_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||
|
||||
if user_geocoder_config.heremaps_geocoder:
|
||||
here_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
elif user_geocoder_config.google_geocoder:
|
||||
google_plan = plpy.prepare("SELECT cdb_geocoder_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||
else:
|
||||
plpy.error('Requested geocoder is not available')
|
||||
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.here import HereMapsGeocoder
|
||||
from cartodb_services.metrics import QuotaService
|
||||
@@ -52,7 +52,7 @@ RETURNS Geometry AS $$
|
||||
quota_service.increment_total_geocoder_use()
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||
RETURNS Geometry AS $$
|
||||
from cartodb_services.google import GoogleMapsGeocoder
|
||||
from cartodb_services.metrics import QuotaService
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(username text, orgname text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin0_polygons')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,7 +9,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._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin0_polygons')
|
||||
@@ -21,7 +21,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin0_polygon(country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -10,7 +10,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._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1) AS mypolygon", ["text"])
|
||||
rv = plpy.execute(plan, [admin1_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygons')
|
||||
@@ -18,7 +18,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -27,7 +27,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._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon($1, $2) AS mypolygon", ["text", "text"])
|
||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from cdb_geocode_admin1_polygon(admin1_name text, country_name text)')
|
||||
@@ -40,7 +40,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -64,7 +64,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Interfacess of the server extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -10,7 +10,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._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point($1) AS mypoint", ["text"])
|
||||
rv = plpy.execute(plan, [city_name], 1)
|
||||
|
||||
plpy.debug('Returning from Returning from geocode_namedplace')
|
||||
@@ -18,7 +18,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -27,7 +27,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._cdb_geocode_namedplace_point($1, $2) AS mypoint", ["text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -35,7 +35,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -44,7 +44,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._cdb_geocode_namedplace_point($1, $2, $3) AS mypoint", ["text", "text", "text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_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')
|
||||
@@ -57,7 +57,7 @@ $$ LANGUAGE plpythonu;
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -76,7 +76,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -96,7 +96,7 @@ RETURNS Geometry AS $$
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,14 +9,14 @@ 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._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1) AS point", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -25,14 +25,14 @@ 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._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point($1, $2) AS point", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
return rv[0]["point"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_polygon')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -41,14 +41,14 @@ 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._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1) AS polygon", ["text"])
|
||||
rv = plpy.execute(plan, [code], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_polygon')
|
||||
return rv[0]["polygon"]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_postalcode_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -57,7 +57,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._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon($1, $2) AS polygon", ["TEXT", "TEXT"])
|
||||
rv = plpy.execute(plan, [code, country], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_postalcode_point')
|
||||
@@ -69,7 +69,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -90,7 +90,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -115,7 +115,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
@@ -136,7 +136,7 @@ RETURNS Geometry AS $$
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Interface of the server extension
|
||||
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||
RETURNS Geometry AS $$
|
||||
plpy.debug('Entering _cdb_geocode_ipaddress_point')
|
||||
plpy.debug('user = %s' % username)
|
||||
@@ -9,7 +9,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._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point($1) AS point", ["TEXT"])
|
||||
rv = plpy.execute(plan, [ip], 1)
|
||||
|
||||
plpy.debug('Returning from _cdb_geocode_ipaddress_point')
|
||||
@@ -21,7 +21,7 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
-- Implementation of the server extension
|
||||
-- Note: these functions depend on the cdb_geocoder extension
|
||||
CREATE OR REPLACE FUNCTION cdb_geocoder_server._cdb_geocode_ipaddress_point(ip text)
|
||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_ipaddress_point(ip text)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
|
||||
@@ -7,9 +7,9 @@ BEGIN
|
||||
|
||||
CREATE USER geocoder_api;
|
||||
END IF;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_geocoder_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA cdb_dataservices_server TO geocoder_api;
|
||||
GRANT USAGE ON SCHEMA public TO geocoder_api;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO geocoder_api;
|
||||
END$$;
|
||||
END$$;
|
||||
|
||||
3
server/extension/sql/0.3.0/00_header.sql
Normal file
3
server/extension/sql/0.3.0/00_header.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION cdb_dataservices_server" to load this file. \quit
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user