Skip to content

Commit e3303e2

Browse files
Catch collections not collection in CQL filters (#43)
* add tests for collections search * add next token * add next token * add more tests * fix bad transformation for collections
1 parent be27663 commit e3303e2

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

sql/004_search.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ IF j ? 'id' THEN
146146
);
147147
newprops := jsonb_insert(newprops, '{1}', newprop);
148148
END IF;
149-
IF j ? 'collection' THEN
149+
IF j ? 'collections' THEN
150150
newprop := jsonb_build_object(
151151
'in',
152152
jsonb_build_array(
153153
'{"property":"collection"}'::jsonb,
154-
j->'collection'
154+
j->'collections'
155155
)
156156
);
157157
newprops := jsonb_insert(newprops, '{1}', newprop);
@@ -188,7 +188,7 @@ IF newprops IS NOT NULL AND jsonb_array_length(newprops) > 0 THEN
188188
j,
189189
'{filter}',
190190
cql_and_append(j, jsonb_build_object('and', newprops))
191-
) - '{id,collection,datetime,bbox,intersects}'::text[];
191+
) - '{id,collections,datetime,bbox,intersects}'::text[];
192192
END IF;
193193

194194
return j;

test/pgtap/004_search.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ SELECT results_eq($$
4040
'Test that id gets added to cql filter when cql filter does exist'
4141
);
4242

43+
SELECT results_eq($$
44+
SELECT add_filters_to_cql('{"collections":["a","b"]}'::jsonb);
45+
$$,$$
46+
SELECT '{"filter":{"and": [{"in": [{"property": "collection"}, ["a", "b"]]}]}}'::jsonb;
47+
$$,
48+
'Test that collections gets added to cql filter when cql filter does not exist'
49+
);
50+
51+
SELECT results_eq($$
52+
SELECT add_filters_to_cql('{"collection":["a","b"]}'::jsonb);
53+
$$,$$
54+
SELECT '{"collection": ["a", "b"]}'::jsonb;
55+
$$,
56+
'Test that collection are not added to cql filter'
57+
);
58+
59+
4360
SELECT has_function('pgstac'::name, 'cql_and_append', ARRAY['jsonb','jsonb']);
4461

4562
SELECT has_function('pgstac'::name, 'query_to_cqlfilter', ARRAY['jsonb']);
@@ -137,6 +154,22 @@ SELECT results_eq($$
137154
'Test lt as a filter on a numeric field with order by'
138155
);
139156

157+
SELECT results_eq($$
158+
select s from search('{"collections":["pgstac-test-collection"],"fields":{"include":["id"]}, "limit": 1}') s;
159+
$$,$$
160+
select '{"next": "20200307aC0870130w361200", "prev": null, "type": "FeatureCollection", "context": {"limit": 1, "matched": 100, "returned": 1}, "features": [{"id": "20200307aC0870130w361200"}]}'::jsonb
161+
$$,
162+
'Test collections search with unknow collection'
163+
);
164+
165+
SELECT results_eq($$
166+
select s from search('{"collections":["something"]}') s;
167+
$$,$$
168+
select '{"next": null, "prev": null, "type": "FeatureCollection", "context": {"limit": 10, "matched": 0, "returned": 0}, "features": []}'::jsonb
169+
$$,
170+
'Test collections search with unknow collection'
171+
);
172+
140173
/* template
141174
SELECT results_eq($$
142175

0 commit comments

Comments
 (0)