Server side part for function obs_getmeasurebyid
This commit is contained in:
@@ -13,8 +13,8 @@ OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
|||||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||||
$(OLD_VERSIONS) \
|
$(OLD_VERSIONS) \
|
||||||
cdb_dataservices_server--0.8.0--0.9.0.sql \
|
cdb_dataservices_server--0.9.0--0.10.0.sql \
|
||||||
cdb_dataservices_server--0.9.0--0.8.0.sql
|
cdb_dataservices_server--0.10.0--0.9.0.sql
|
||||||
|
|
||||||
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
||||||
TEST_DIR = test/
|
TEST_DIR = test/
|
||||||
|
|||||||
@@ -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_server UPDATE TO '0.9.0'" to load this file. \quit
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server._OBS_GetMeasureById(text, text, text, text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.OBS_GetMeasureById(text, text, text, text, text, text);
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
--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_server UPDATE TO '0.10.0'" to load this file. \quit
|
||||||
|
|
||||||
|
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 $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT cdb_observatory.OBS_GetMeasureById(geom_ref, measure_id, boundary_id, time_span);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
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 $$
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
|
||||||
|
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_obs_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_config = GD["user_obs_config_{0}".format(username)]
|
||||||
|
|
||||||
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasureById($1, $2, $3, $4, $5, $6) as measure;", ["text", "text", "text", "text", "text", "text"])
|
||||||
|
result = plpy.execute(obs_plan, [username, orgname, geom_ref, measure_id, boundary_id, time_span])
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result[0]['measure']
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys, traceback
|
||||||
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
error_msg = 'There was an error trying to use OBS_GetMeasureById: {0}'.format(e)
|
||||||
|
plpy.notice(traceback.format_tb(traceback_))
|
||||||
|
plpy.error(error_msg)
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices server extension'
|
comment = 'CartoDB dataservices server extension'
|
||||||
default_version = '0.9.0'
|
default_version = '0.10.0'
|
||||||
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_server
|
schema = cdb_dataservices_server
|
||||||
|
|||||||
@@ -476,3 +476,54 @@ RETURNS NUMERIC AS $$
|
|||||||
finally:
|
finally:
|
||||||
quota_service.increment_total_service_use()
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
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 $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT cdb_observatory.OBS_GetMeasureById(geom_ref, measure_id, boundary_id, time_span);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
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 $$
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
|
||||||
|
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_obs_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_config = GD["user_obs_config_{0}".format(username)]
|
||||||
|
|
||||||
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||||
|
if not quota_service.check_user_quota():
|
||||||
|
plpy.error('You have reached the limit of your quota')
|
||||||
|
|
||||||
|
try:
|
||||||
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasureById($1, $2, $3, $4, $5, $6) as measure;", ["text", "text", "text", "text", "text", "text"])
|
||||||
|
result = plpy.execute(obs_plan, [username, orgname, geom_ref, measure_id, boundary_id, time_span])
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result[0]['measure']
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys, traceback
|
||||||
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
error_msg = 'There was an error trying to use OBS_GetMeasureById: {0}'.format(e)
|
||||||
|
plpy.notice(traceback.format_tb(traceback_))
|
||||||
|
plpy.error(error_msg)
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ SELECT exists(SELECT *
|
|||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getmeasurebyid'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, text, text, text, text');
|
||||||
|
exists
|
||||||
|
--------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
SELECT exists(SELECT *
|
SELECT exists(SELECT *
|
||||||
FROM pg_proc p
|
FROM pg_proc p
|
||||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ SELECT exists(SELECT *
|
|||||||
AND proname = 'obs_getmeasure'
|
AND proname = 'obs_getmeasure'
|
||||||
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text, text, text, text');
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text, text, text, text');
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getmeasurebyid'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, text, text, text, text');
|
||||||
|
|
||||||
SELECT exists(SELECT *
|
SELECT exists(SELECT *
|
||||||
FROM pg_proc p
|
FROM pg_proc p
|
||||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
|||||||
Reference in New Issue
Block a user