Skip to content

Commit 262aace

Browse files
Merge pull request #39 from developmentseed/numbermatched
Numbermatched Fix
2 parents 85f8271 + b1c6479 commit 262aace

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

tests/routes/test_items.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ def test_items_limit_and_offset(app):
6464
assert body["numberReturned"] == 1
6565
assert ["collection", "self", "prev"] == [link["rel"] for link in body["links"]]
6666

67-
# TODO: Fix
68-
# offset > data
69-
# response = app.get("/collections/public.landsat_wrs/items?offset=20000")
70-
# assert response.status_code == 200
71-
# body = response.json()
72-
# assert len(body["features"]) == 0
73-
# assert body["numberMatched"] == 16269
74-
# assert body["numberReturned"] == 0
67+
# offset overflow, return empty feature collection
68+
response = app.get("/collections/public.landsat_wrs/items?offset=20000")
69+
assert response.status_code == 200
70+
body = response.json()
71+
assert len(body["features"]) == 0
72+
assert body["numberMatched"] == 16269
73+
assert body["numberReturned"] == 0
7574

7675

7776
def test_items_bbox(app):

tifeatures/layer.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -376,18 +376,25 @@ async def query(
376376
)
377377
SELECT json_build_object(
378378
'type', 'FeatureCollection',
379-
'features', json_agg(
380-
json_build_object(
381-
'type', 'Feature',
382-
'id', :id_column,
383-
'geometry', :geometry_q,
384-
'properties', to_jsonb( features.* ) - :geom_columns::text[]
379+
'features',
380+
(
381+
SELECT
382+
json_agg(
383+
json_build_object(
384+
'type', 'Feature',
385+
'id', :id_column,
386+
'geometry', :geometry_q,
387+
'properties', to_jsonb( features.* ) - :geom_columns::text[]
388+
)
389+
)
390+
FROM features
391+
),
392+
'total_count',
393+
(
394+
SELECT count FROM total_count
385395
)
386-
),
387-
'total_count', total_count.count
388-
)
389-
FROM features, total_count
390-
GROUP BY total_count.count;
396+
)
397+
;
391398
"""
392399
q, p = render(
393400
sql_query,
@@ -424,13 +431,10 @@ async def query(
424431
async with pool.acquire() as conn:
425432
items = await conn.fetchval(q, *p)
426433

427-
if items:
428-
return (
429-
FeatureCollection(features=items["features"]),
430-
items["total_count"],
431-
)
432-
else:
433-
return FeatureCollection(features=[]), 0
434+
return (
435+
FeatureCollection(features=items.get("features") or []),
436+
items["total_count"],
437+
)
434438

435439
async def features(
436440
self,

0 commit comments

Comments
 (0)