Refactor OBS_GetAvailableTimespans

This commit is contained in:
Antonio 2018-02-14 13:45:48 +01:00 committed by Mario de Frutos
parent 17345f4fca
commit 7aac256892
4 changed files with 27 additions and 8 deletions

View File

@ -28,8 +28,8 @@ Run the tests with `make test`.
Update extension in a working database with:
```
ALTER EXTENSION observatory VERSION TO 'current';
ALTER EXTENSION observatory VERSION TO 'dev';
ALTER EXTENSION observatory UPDATE TO 'current';
ALTER EXTENSION observatory UPDATE TO 'dev';
```
Note: we keep the current development version install as 'dev' always;

View File

@ -1,3 +1,11 @@
1.9.0 (2018-02-14)
------------------
__Improvements__
* Improved `OBS_GetAvailableTimespans` for the DO Timespans project ([bigmetadata/#422](https://github.com/CartoDB/bigmetadata/issues/422))
* Fixed documentation
1.8.0 (2017-10-18)
------------------

View File

@ -1,5 +1,5 @@
comment = 'CartoDB Observatory backend extension'
default_version = '1.8.0'
default_version = '1.9.0'
requires = 'postgis'
superuser = true
schema = cdb_observatory

View File

@ -405,6 +405,13 @@ BEGIN
END
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS cdb_observatory.OBS_GetAvailableTimespans(
bounds GEOMETRY,
filter_tags TEXT[],
numer_id TEXT,
denom_id TEXT,
geom_id TEXT
);
CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetAvailableTimespans(
bounds GEOMETRY DEFAULT NULL,
filter_tags TEXT[] DEFAULT NULL,
@ -424,7 +431,9 @@ CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetAvailableTimespans(
timespan_tags JSONB,
valid_numer BOOLEAN,
valid_denom BOOLEAN,
valid_geom BOOLEAN
valid_geom BOOLEAN,
timespan_alias TEXT,
timespan_range DATERANGE
) AS $$
DECLARE
geom_clause TEXT;
@ -448,12 +457,14 @@ BEGIN
NULL::TEXT timespan_aggregate,
NULL::TEXT timespan_license,
NULL::TEXT timespan_source,
NULL::TEXT timespan_type,
timespan_type::TEXT,
NULL::JSONB timespan_extra,
NULL::JSONB timespan_tags,
$1 = ANY(numers) valid_numer,
$2 = ANY(denoms) valid_denom,
$3 = ANY(geoms) valid_geom_id
COALESCE($1 = ANY(numers), false) valid_numer,
COALESCE($2 = ANY(denoms), false) valid_denom,
COALESCE($3 = ANY(geoms), false) valid_geom_id,
timespan_alias::TEXT,
timespan_range::DATERANGE
FROM observatory.obs_meta_timespan
WHERE %s (timespan_tags ?& $4 OR CARDINALITY($4) = 0)
$string$, geom_clause)