diff --git a/client/Makefile b/client/Makefile index ff0d56e..76fcf8c 100644 --- a/client/Makefile +++ b/client/Makefile @@ -13,8 +13,8 @@ OLD_VERSIONS = $(wildcard old_versions/*.sql) # @see http://www.postgresql.org/docs/current/static/extend-pgxs.html DATA = $(NEW_EXTENSION_ARTIFACT) \ $(OLD_VERSIONS) \ - cdb_dataservices_client--0.5.0--0.6.0.sql \ - cdb_dataservices_client--0.6.0--0.5.0.sql + cdb_dataservices_client--0.6.0--0.7.0.sql \ + cdb_dataservices_client--0.7.0--0.6.0.sql REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql))) diff --git a/client/cdb_dataservices_client--0.6.0--0.7.0.sql b/client/cdb_dataservices_client--0.6.0--0.7.0.sql new file mode 100644 index 0000000..ea1b959 --- /dev/null +++ b/client/cdb_dataservices_client--0.6.0--0.7.0.sql @@ -0,0 +1,35 @@ +--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 "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.7.0'" to load this file. \quit + +CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_getmeasurebyid (geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL) +RETURNS numeric AS $$ +DECLARE + ret numeric; + 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._obs_getmeasurebyid(username, orgname, geom_ref, measure_id, boundary_id, time_span) INTO ret; + RETURN ret; + +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getmeasurebyid (username text, organization_name text, geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL) +RETURNS numeric AS $$ + CONNECT cdb_dataservices_client._server_conn_str(); + + SELECT cdb_dataservices_server.obs_getmeasurebyid (username, organization_name, geom_ref, measure_id, boundary_id, time_span); + +$$ LANGUAGE plproxy; + +GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_getmeasurebyid(geom_ref text, measure_id text, boundary_id text, time_span text) TO publicuser; \ No newline at end of file diff --git a/client/cdb_dataservices_client--0.7.0--0.6.0.sql b/client/cdb_dataservices_client--0.7.0--0.6.0.sql new file mode 100644 index 0000000..56a836c --- /dev/null +++ b/client/cdb_dataservices_client--0.7.0--0.6.0.sql @@ -0,0 +1,5 @@ +--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 "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.6.0'" to load this file. \quit +DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getmeasurebyid (text, text, text, text); +DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getmeasurebyid (text, text, text, text); diff --git a/client/cdb_dataservices_client.control b/client/cdb_dataservices_client.control index 926eddc..8773088 100644 --- a/client/cdb_dataservices_client.control +++ b/client/cdb_dataservices_client.control @@ -1,5 +1,5 @@ comment = 'CartoDB dataservices client API extension' -default_version = '0.6.0' +default_version = '0.7.0' requires = 'plproxy, cartodb' superuser = true schema = cdb_dataservices_client diff --git a/client/cdb_dataservices_client--0.5.0--0.6.0.sql b/client/old_versions/cdb_dataservices_client--0.5.0--0.6.0.sql similarity index 100% rename from client/cdb_dataservices_client--0.5.0--0.6.0.sql rename to client/old_versions/cdb_dataservices_client--0.5.0--0.6.0.sql diff --git a/client/cdb_dataservices_client--0.6.0--0.5.0.sql b/client/old_versions/cdb_dataservices_client--0.6.0--0.5.0.sql similarity index 100% rename from client/cdb_dataservices_client--0.6.0--0.5.0.sql rename to client/old_versions/cdb_dataservices_client--0.6.0--0.5.0.sql diff --git a/client/cdb_dataservices_client--0.6.0.sql b/client/old_versions/cdb_dataservices_client--0.6.0.sql similarity index 100% rename from client/cdb_dataservices_client--0.6.0.sql rename to client/old_versions/cdb_dataservices_client--0.6.0.sql diff --git a/client/renderer/interface.yaml b/client/renderer/interface.yaml index 2192fde..a2990bc 100644 --- a/client/renderer/interface.yaml +++ b/client/renderer/interface.yaml @@ -210,6 +210,14 @@ - { name: boundary_id, type: text, default: 'NULL' } - { name: time_span, type: text, default: 'NULL'} +- name: obs_getmeasurebyid + return_type: numeric + params: + - { name: geom_ref, type: text } + - { name: measure_id, type: text } + - { name: boundary_id, type: text} + - { name: time_span, type: text, default: 'NULL'} + - name: obs_getcategory return_type: text params: diff --git a/client/test/expected/90_data_observatory_test.out b/client/test/expected/90_data_observatory_test.out index dcbed19..75af3a9 100644 --- a/client/test/expected/90_data_observatory_test.out +++ b/client/test/expected/90_data_observatory_test.out @@ -102,6 +102,16 @@ BEGIN RETURN ret; END; $$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getmeasurebyid (username text, orgname text, geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL) +RETURNS numeric AS $$ +DECLARE + ret numeric; +BEGIN + RAISE NOTICE 'cdb_dataservices_server.obs_getmeasurebyid invoked with params (%, %, %, %, %, %)', username, orgname, geom_ref, measure_id, boundary_id, time_span; + SELECT 10923.093200390833950::numeric INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql'; CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getcategory (username text, orgname text, geom Geometry, category_id text, boundary_id text DEFAULT NULL, time_span text DEFAULT NULL) RETURNS text AS $$ DECLARE @@ -266,6 +276,15 @@ PL/pgSQL function obs_getmeasure(geometry,text,text,text,text) line 16 at SQL st 10923.093200390833950 (1 row) +SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text); +NOTICE: cdb_dataservices_client._obs_getmeasurebyid(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.obs_getmeasurebyid invoked with params (test_user, , 36047, us.census.acs.B01001001, us.census.tiger.county, ) +CONTEXT: SQL statement "SELECT cdb_dataservices_client._obs_getmeasurebyid(username, orgname, geom_ref, measure_id, boundary_id, time_span)" +PL/pgSQL function obs_getmeasurebyid(text,text,text,text) line 16 at SQL statement + obs_getmeasurebyid +----------------------- + 10923.093200390833950 +(1 row) + SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text); NOTICE: cdb_dataservices_client._obs_getcategory(6): [contrib_regression] REMOTE NOTICE: cdb_dataservices_server.obs_getcategory invoked with params (test_user, , 0101000020E6100000548B8862F27B52C0DDD1FF722D5A4440, us.census.spielman_singleton_segments.X10, , ) CONTEXT: SQL statement "SELECT cdb_dataservices_client._obs_getcategory(username, orgname, geom, category_id, boundary_id, time_span)" diff --git a/client/test/sql/90_data_observatory_test.sql b/client/test/sql/90_data_observatory_test.sql index 620c24c..5eff910 100644 --- a/client/test/sql/90_data_observatory_test.sql +++ b/client/test/sql/90_data_observatory_test.sql @@ -115,6 +115,17 @@ BEGIN END; $$ LANGUAGE 'plpgsql'; +CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getmeasurebyid (username text, orgname text, geom_ref text, measure_id text, boundary_id text, time_span text DEFAULT NULL) +RETURNS numeric AS $$ +DECLARE + ret numeric; +BEGIN + RAISE NOTICE 'cdb_dataservices_server.obs_getmeasurebyid invoked with params (%, %, %, %, %, %)', username, orgname, geom_ref, measure_id, boundary_id, time_span; + SELECT 10923.093200390833950::numeric INTO ret; + RETURN ret; +END; +$$ LANGUAGE 'plpgsql'; + CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_getcategory (username text, orgname text, geom Geometry, category_id text, boundary_id text DEFAULT NULL, time_span text DEFAULT NULL) RETURNS text AS $$ DECLARE @@ -196,6 +207,7 @@ SELECT obs_getboundariesbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704 SELECT obs_getpointsbygeometry(ST_MakeEnvelope(-73.9452409744, 40.6988851644, -73.9280319214, 40.7101254524, 4326), 'us.census.tiger.census_tract'::text); SELECT obs_getpointsbypointandradius(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 500::numeric, 'us.census.tiger.census_tract'::text); SELECT obs_getmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.acs.B01001001'::text); +SELECT obs_getmeasurebyid('36047'::text, 'us.census.acs.B01001001'::text, 'us.census.tiger.county'::text); SELECT obs_getcategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'us.census.spielman_singleton_segments.X10'::text); SELECT obs_getuscensusmeasure(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'male population'::text); SELECT obs_getuscensuscategory(ST_SetSRID(ST_Point(-73.936669 , 40.704512), 4326), 'Spielman-Singleton Segments: 10 Clusters'::text);