Skip to content

Commit

Permalink
rename variable to make pgstac compatible with pg>=14 (#151)
Browse files Browse the repository at this point in the history
* rename variable to make pgstac compatible with pg>=14

* update tests

* add table change to migration, change version to 0.6.11

* update changelog

Co-authored-by: David Bitner <[email protected]>
  • Loading branch information
vincentsarago and bitner authored Dec 6, 2022
1 parent a140e1e commit da8d693
Show file tree
Hide file tree
Showing 16 changed files with 3,103 additions and 24 deletions.
19 changes: 10 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v0.6.11]

### Fixed
- update pypgstac requirements to support python 3.11 [142](https://github.com/stac-utils/pgstac/pull/142)
- rename pgstac setting `default-filter-lang` to `default_filter_lang` to allow pgstac on postgresql>=14

## [v0.6.10]

### Fixed
Expand All @@ -17,24 +24,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added
- Add get_queryables function to return a composite queryables json for either a single collection (text), a list of collections(text[]), or for the full repository (null::text).

- Add missing_queryables(collection text, tablesample int) function to help identify if there are any properties in a collection without entries in the queryables table. The tablesample parameter is an int <=100 that is the approximate percentage of the collection to scan to look for missing queryables rather than reading every item.

- Add missing_queryables(tablesample int) function that scans all collections using a sample of records to identify missing queryables.



## [v0.6.7]

### Added
- Add get_queryables function to return a composite queryables json for either a single collection (text), a list of collections(text[]), or for the full repository (null::text).

- Add missing_queryables(collection text, tablesample int) function to help identify if there are any properties in a collection without entries in the queryables table. The tablesample parameter is an int <=100 that is the approximate percentage of the collection to scan to look for missing queryables rather than reading every item.

- Add missing_queryables(tablesample int) function that scans all collections using a sample of records to identify missing queryables.



## [v0.6.6]

### Added
Expand Down Expand Up @@ -236,7 +235,9 @@ _TODO_

- Fixed issue with pypgstac loads which caused some writes to fail ([#18](https://github.com/stac-utils/pgstac/pull/18))

[unreleased]: https://github.com/stac-utils/pgstac/compare/v0.6.8...HEAD
[unreleased]: https://github.com/stac-utils/pgstac/compare/v0.6.10...HEAD
[v0.6.10]: https://github.com//stac-utils/pgstac/compare/v0.6.9...v0.6.10
[v0.6.9]: https://github.com//stac-utils/pgstac/compare/v0.6.8...v0.6.9
[v0.6.8]: https://github.com//stac-utils/pgstac/compare/v0.6.7...v0.6.8
[v0.6.7]: https://github.com//stac-utils/pgstac/compare/v0.6.6...v0.6.7
[v0.6.6]: https://github.com//stac-utils/pgstac/compare/v0.6.5...v0.6.6
Expand Down
87 changes: 87 additions & 0 deletions pypgstac/pypgstac/migrations/pgstac.0.6.10-0.6.11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
SET SEARCH_PATH to pgstac, public;
set check_function_bodies = off;

UPDATE pgstac_settings SET name='default_filter_lang' WHERE name='default-filter-lang';

CREATE OR REPLACE FUNCTION pgstac.stac_search_to_where(j jsonb)
RETURNS text
LANGUAGE plpgsql
STABLE
AS $function$
DECLARE
where_segments text[];
_where text;
dtrange tstzrange;
collections text[];
geom geometry;
sdate timestamptz;
edate timestamptz;
filterlang text;
filter jsonb := j->'filter';
BEGIN
IF j ? 'ids' THEN
where_segments := where_segments || format('id = ANY (%L) ', to_text_array(j->'ids'));
END IF;

IF j ? 'collections' THEN
collections := to_text_array(j->'collections');
where_segments := where_segments || format('collection = ANY (%L) ', collections);
END IF;

IF j ? 'datetime' THEN
dtrange := parse_dtrange(j->'datetime');
sdate := lower(dtrange);
edate := upper(dtrange);

where_segments := where_segments || format(' datetime <= %L::timestamptz AND end_datetime >= %L::timestamptz ',
edate,
sdate
);
END IF;

geom := stac_geom(j);
IF geom IS NOT NULL THEN
where_segments := where_segments || format('st_intersects(geometry, %L)',geom);
END IF;

filterlang := COALESCE(
j->>'filter-lang',
get_setting('default_filter_lang', j->'conf')
);
IF NOT filter @? '$.**.op' THEN
filterlang := 'cql-json';
END IF;

IF filterlang NOT IN ('cql-json','cql2-json') AND j ? 'filter' THEN
RAISE EXCEPTION '% is not a supported filter-lang. Please use cql-json or cql2-json.', filterlang;
END IF;

IF j ? 'query' AND j ? 'filter' THEN
RAISE EXCEPTION 'Can only use either query or filter at one time.';
END IF;

IF j ? 'query' THEN
filter := query_to_cql2(j->'query');
ELSIF filterlang = 'cql-json' THEN
filter := cql1_to_cql2(filter);
END IF;
RAISE NOTICE 'FILTER: %', filter;
where_segments := where_segments || cql2_query(filter);
IF cardinality(where_segments) < 1 THEN
RETURN ' TRUE ';
END IF;

_where := array_to_string(array_remove(where_segments, NULL), ' AND ');

IF _where IS NULL OR BTRIM(_where) = '' THEN
RETURN ' TRUE ';
END IF;
RETURN _where;

END;
$function$
;



SELECT set_version('0.6.11');
Loading

0 comments on commit da8d693

Please sign in to comment.