From 1ffbba2a03bf898dc15e50757b521dd265f49fbc Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Thu, 29 Jun 2017 16:03:19 +0200 Subject: [PATCH] New DO function _OBS_GetNumerators --- ...db_dataservices_client--0.17.0--0.18.0.sql | 28 +++++++++++++++++++ client/renderer/interface.yaml | 15 ++++++++++ .../sql/130_data_observatory_helper.sql | 17 +++++++++++ 3 files changed, 60 insertions(+) diff --git a/client/cdb_dataservices_client--0.17.0--0.18.0.sql b/client/cdb_dataservices_client--0.17.0--0.18.0.sql index a1e5703..62b4b2b 100644 --- a/client/cdb_dataservices_client--0.17.0--0.18.0.sql +++ b/client/cdb_dataservices_client--0.17.0--0.18.0.sql @@ -68,10 +68,16 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER; CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getavailablegeometries_exception_safe (bounds geometry(Geometry, 4326) DEFAULT NULL ,filter_tags text[] DEFAULT NULL ,numer_id text DEFAULT NULL ,denom_id text DEFAULT NULL ,timespan text DEFAULT NULL) RETURNS SETOF cdb_dataservices_client.obs_meta_geometry AS $$ +======= +-- HERE goes your code to upgrade/downgrade +CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getnumerators (bounds geometry(Geometry, 4326) DEFAULT NULL ,section_tags text[] DEFAULT ARRAY[]::TEXT[] ,subsection_tags text[] DEFAULT ARRAY[]::TEXT[] ,other_tags text[] DEFAULT ARRAY[]::TEXT[] ,ids text[] DEFAULT ARRAY[]::TEXT[] ,name text DEFAULT NULL ,denom_id text DEFAULT '' ,geom_id text DEFAULT '' ,timespan text DEFAULT '') +RETURNS SETOF cdb_dataservices_client.obs_meta_numerator AS $$ +>>>>>>> New DO function _OBS_GetNumerators DECLARE username text; orgname text; +<<<<<<< HEAD _returned_sqlstate TEXT; _message_text TEXT; _pg_exception_context TEXT; @@ -198,6 +204,8 @@ DECLARE ret Geometry; username text; orgname text; +======= +>>>>>>> New DO function _OBS_GetNumerators BEGIN IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN RAISE EXCEPTION 'The api_key must be provided'; @@ -208,6 +216,7 @@ BEGIN RAISE EXCEPTION 'Username is a mandatory argument, check it out'; END IF; +<<<<<<< HEAD SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name) INTO ret; RETURN ret; END; $$ LANGUAGE 'plpgsql' SECURITY DEFINER; @@ -238,6 +247,16 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_postalcode_polyg RETURNS Geometry AS $$ DECLARE ret Geometry; +======= + RETURN QUERY SELECT * FROM cdb_dataservices_client.__obs_getnumerators(username, orgname, bounds, section_tags, subsection_tags, other_tags, ids, name, denom_id, geom_id, timespan); +END; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER; + +CREATE OR REPLACE FUNCTION cdb_dataservices_client.__obs_getnumerators_exception_safe (bounds geometry(Geometry, 4326) DEFAULT NULL ,section_tags text[] DEFAULT ARRAY[]::TEXT[] ,subsection_tags text[] DEFAULT ARRAY[]::TEXT[] ,other_tags text[] DEFAULT ARRAY[]::TEXT[] ,ids text[] DEFAULT ARRAY[]::TEXT[] ,name text DEFAULT NULL ,denom_id text DEFAULT '' ,geom_id text DEFAULT '' ,timespan text DEFAULT '') +RETURNS SETOF cdb_dataservices_client.obs_meta_numerator AS $$ +DECLARE + +>>>>>>> New DO function _OBS_GetNumerators username text; orgname text; _returned_sqlstate TEXT; @@ -255,13 +274,18 @@ BEGIN BEGIN +<<<<<<< HEAD SELECT cdb_dataservices_client._cdb_geocode_postalcode_polygon(username, orgname, postal_code, country_name) INTO ret; RETURN ret; +======= + RETURN QUERY SELECT * FROM cdb_dataservices_client.__obs_getnumerators(username, orgname, bounds, section_tags, subsection_tags, other_tags, ids, name, denom_id, geom_id, timespan); +>>>>>>> New DO function _OBS_GetNumerators EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS _returned_sqlstate = RETURNED_SQLSTATE, _message_text = MESSAGE_TEXT, _pg_exception_context = PG_EXCEPTION_CONTEXT; RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context; +<<<<<<< HEAD RETURN ret; END; END; @@ -297,10 +321,14 @@ BEGIN _pg_exception_context = PG_EXCEPTION_CONTEXT; RAISE WARNING USING ERRCODE = _returned_sqlstate, MESSAGE = _message_text, DETAIL = _pg_exception_context; RETURN ret; +======= + +>>>>>>> New DO function _OBS_GetNumerators END; END; $$ LANGUAGE 'plpgsql' SECURITY DEFINER; +<<<<<<< HEAD CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_geocode_postalcode_polygon (username text, orgname text, postal_code double precision, country_name text) RETURNS Geometry AS $$ CONNECT cdb_dataservices_client._server_conn_str(); diff --git a/client/renderer/interface.yaml b/client/renderer/interface.yaml index b94d80f..3cff5bb 100644 --- a/client/renderer/interface.yaml +++ b/client/renderer/interface.yaml @@ -381,6 +381,21 @@ - { name: geom_id, type: text, default: 'NULL' } - { name: timespan, type: text, default: 'NULL'} +- name: _obs_getnumerators + return_type: SETOF cdb_dataservices_client.obs_meta_numerator + multi_row: true + multi_field: true + params: + - { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' } + - { name: section_tags, type: "text[]", default: 'ARRAY[]::TEXT[]' } + - { name: subsection_tags, type: "text[]", default: 'ARRAY[]::TEXT[]' } + - { name: other_tags, type: "text[]", default: 'ARRAY[]::TEXT[]' } + - { name: ids, type: "text[]", default: 'ARRAY[]::TEXT[]' } + - { name: name, type: text, default: 'NULL' } + - { name: denom_id, type: text, default: "''" } + - { name: geom_id, type: text, default: "''" } + - { name: timespan, type: text, default: "''"} + - name: obs_getavailabledenominators return_type: SETOF cdb_dataservices_client.obs_meta_denominator multi_row: true diff --git a/server/extension/sql/130_data_observatory_helper.sql b/server/extension/sql/130_data_observatory_helper.sql index c387a91..5711f60 100644 --- a/server/extension/sql/130_data_observatory_helper.sql +++ b/server/extension/sql/130_data_observatory_helper.sql @@ -20,6 +20,23 @@ RETURNS SETOF cdb_dataservices_server.obs_meta_numerator AS $$ SELECT * FROM cdb_observatory.OBS_GetAvailableNumerators(bounds, filter_tags, denom_id, geom_id, timespan); $$ LANGUAGE plproxy; +CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetNumerators( + username TEXT, + orgname TEXT, + bounds geometry(Geometry, 4326) DEFAULT NULL, + section_tags TEXT[] DEFAULT ARRAY[]::TEXT[], + subsection_tags TEXT[] DEFAULT ARRAY[]::TEXT[], + other_tags TEXT[] DEFAULT ARRAY[]::TEXT[], + ids TEXT[] DEFAULT ARRAY[]::TEXT[], + name TEXT DEFAULT NULL, + denom_id TEXT DEFAULT '', + geom_id TEXT DEFAULT '', + timespan TEXT DEFAULT '') +RETURNS SETOF cdb_dataservices_server.obs_meta_numerator AS $$ + CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); + SELECT * FROM cdb_observatory._OBS_GetNumerators(bounds, section_tags, subsection_tags, other_tags, ids, name, denom_id, geom_id, timespan); +$$ LANGUAGE plproxy; + CREATE TYPE cdb_dataservices_server.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean); CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableDenominators(