Skip to content

Commit

Permalink
Fix Query Extension JSON syntax (#220)
Browse files Browse the repository at this point in the history
* fix support for query extension passing in JSON
  • Loading branch information
Phil Varner authored Jun 6, 2022
1 parent a41acb2 commit 6a1295e
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 18 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Search sortby parameter now has correct typing and correctly handles both GET and POST JSON parameter formats. [#175](https://github.com/stac-utils/pystac-client/pull/175)
- Search fields parameter now has correct typing and correctly handles both GET and POST JSON parameter formats. [#184](https://github.com/stac-utils/pystac-client/pull/184)
- Search query parameter now has correct typing and handles Query Extension JSON format. [#220](https://github.com/stac-utils/pystac-client/pull/220)
- Search sortby parameter now has correct typing and handles both GET and POST JSON parameter formats. [#175](https://github.com/stac-utils/pystac-client/pull/175)
- Search fields parameter now has correct typing and handles both GET and POST JSON parameter formats. [#184](https://github.com/stac-utils/pystac-client/pull/184)
- Use pytest configuration to skip benchmarks by default (instead of a `skip` mark) [#168](https://github.com/stac-utils/pystac-client/pull/168)

## [v0.3.5] - 2022-05-26
Expand Down
39 changes: 23 additions & 16 deletions pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
IDs = Tuple[str, ...]
IDsLike = Union[IDs, str, List[str], Iterator[str]]

Intersects = dict
Intersects = Dict[str, Any]
IntersectsLike = Union[str, object, Intersects]
# todo: after 3.7 is dropped, replace object with GeoInterface

Query = dict
Query = Dict[str, Any]
QueryLike = Union[Query, List[str]]

FilterLangLike = str
Expand Down Expand Up @@ -289,24 +289,31 @@ def get_parameters(self) -> Dict[str, Any]:
raise Exception(f"Unsupported method {self.method}")

@staticmethod
def _format_query(value: List[QueryLike]) -> Optional[Dict[str, Any]]:
def _format_query(value: QueryLike) -> Optional[Dict[str, Any]]:
if value is None:
return None

if isinstance(value, list):
query = {}
elif isinstance(value, dict):
return value
elif isinstance(value, list):
query: Dict[str, Any] = {}
for q in value:
for op in OPS:
parts = q.split(op)
if len(parts) == 2:
param = parts[0]
val = parts[1]
if param == "gsd":
val = float(val)
query = dict_merge(query, {parts[0]: {OP_MAP[op]: val}})
break
if isinstance(q, str):
try:
query = dict_merge(query, json.loads(q))
except json.decoder.JSONDecodeError:
for op in OPS:
parts = q.split(op)
if len(parts) == 2:
param = parts[0]
val: Union[str, float] = parts[1]
if param == "gsd":
val = float(val)
query = dict_merge(query, {parts[0]: {OP_MAP[op]: val}})
break
else:
raise Exception("Unsupported query format, must be a List[str].")
else:
query = value
raise Exception("Unsupported query format, must be a Dict or List[str].")

return query

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
interactions:
- request:
body: '{"limit": 1, "bbox": [-73.21, 43.99, -73.12, 44.05], "query": {"eo:cloud_cover":
{"gte": 0, "lte": 1}}}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '103'
Content-Type:
- application/json
User-Agent:
- python-requests/2.27.1
method: POST
uri: https://planetarycomputer.microsoft.com/api/stac/v1/search
response:
body:
string: !!binary |
H4sIAFo4mmIC/9VcC2/bOBL+K4KBW7SoLeth+XUoDmmz28shfWzs7h2uCARGom1eJdEl5STdRf/7
zVCSZcuSLdt51N3tbiJxhvPNfBwOKYl/NeLvc9oYNn6jJF4I+pYHAfVixqNGszFJrsnG8MtfDeZD
q8u3Rt+9tEafXMO0DdtwLcOyDMfsu4bljk2Qubnh99C+1bP1vtU1+qZtNzuWbgxsp+c0Wz1DH1iW
Df/2m52Objlmx3SumwUrQE/Aoq9Jx4IGcMdbNSxtTebzgHkEL7b/J9WdmaATuDOL47kcttvzgEQ0
JuK7x8P5IqZCD5knuOSTWIdLbTJnbRkTr31rtvMeZBvEfEnilme1Aqvxo5lZMSeCRvFzWiA4f7T+
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T
QjGZQIaNkxIwwP+bOI3E/Ct+CK4gDnceLPwTHbV8fDepl6ES/D9tlxfS6VsAAA==
headers:
Content-Encoding:
- gzip
Content-Length:
- '3523'
Content-Type:
- application/geo+json
Date:
- Fri, 03 Jun 2022 16:36:02 GMT
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
Vary:
- Accept-Encoding
X-Azure-Ref:
- 0WTiaYgAAAAAMaZ2ggs6HR4ti4CNcjpnLTU5aMjIxMDYwNjEzMDMxADkyN2FiZmE2LTE5ZjYtNGFmMS1hMDlkLWM5NTlkOWExZTY0NA==
X-Cache:
- CONFIG_NOCACHE
status:
code: 200
message: OK
- request:
body: '{"limit": 1, "bbox": [-73.21, 43.99, -73.12, 44.05], "query": {"eo:cloud_cover":
{"gte": 0, "lte": 1}}}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '103'
Content-Type:
- application/json
User-Agent:
- python-requests/2.27.1
method: POST
uri: https://planetarycomputer.microsoft.com/api/stac/v1/search
response:
body:
string: !!binary |
H4sIAKg4mmIC/9VcC2/bOBL+K4KBW7SoLeth+XUoDmmz28shfWzs7h2uCARGom1eJdEl5STdRf/7
zVCSZcuSLdt51N3tbiJxhvPNfBwOKYl/NeLvc9oYNn6jJF4I+pYHAfVixqNGszFJrsnG8MtfDeZD
q8u3Rt+9tEafXMO0DdtwLcOyDMfsu4bljk2Qubnh99C+1bP1vtU1+qZtNzuWbgxsp+c0Wz1DH1iW
Df/2m52Objlmx3SumwUrQE/Aoq9Jx4IGcMdbNSxtTebzgHkEL7b/J9WdmaATuDOL47kcttvzgEQ0
JuK7x8P5IqZCD5knuOSTWIdLbTJnbRkTr31rtvMeZBvEfEnilme1Aqvxo5lZMSeCRvFzWiA4f7T+
V7qRNJiUdzOl/NUjQm2zmIayvYtouaUeCLSI3DTH50znYto2Dd0xut32p8HHd2/eve8iLBYHiOsy
6Vnrtwbax8uL9vjiaqTlQ0CztEt6S4PWagBu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/geo+json
Date:
- Fri, 03 Jun 2022 16:36:57 GMT
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
Vary:
- Accept-Encoding
X-Azure-Ref:
- 0qDiaYgAAAACuMFSv+tPOTZWaGVhgl17dTU5aMjIxMDYwNjExMDIxADkyN2FiZmE2LTE5ZjYtNGFmMS1hMDlkLWM5NTlkOWExZTY0NA==
X-Cache:
- CONFIG_NOCACHE
status:
code: 200
message: OK
version: 1
40 changes: 40 additions & 0 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,43 @@ def test_query_shortcut_syntax(self) -> None:
assert len(items1) == 1
assert len(items2) == 1
assert items1[0].id == items2[0].id

@pytest.mark.vcr
def test_query_json_syntax(self) -> None:

# with a list of json strs (format of CLI argument to ItemSearch)
search = ItemSearch(
url=SEARCH_URL,
bbox=(-73.21, 43.99, -73.12, 44.05),
query=['{"eo:cloud_cover": { "gte": 0, "lte": 1 }}'],
max_items=1,
)
item1 = list(search.items())[0]
assert item1.properties["eo:cloud_cover"] <= 1

# with a single dict
search = ItemSearch(
url=SEARCH_URL,
bbox=(-73.21, 43.99, -73.12, 44.05),
query={"eo:cloud_cover": {"gte": 0, "lte": 1}},
max_items=1,
)
item2 = list(search.items())[0]
assert item2.properties["eo:cloud_cover"] <= 1

assert item1.id == item2.id


def test_query_json_syntax() -> None:
assert ItemSearch._format_query(['{"eo:cloud_cover": { "gte": 0, "lte": 1 }}']) == {
"eo:cloud_cover": {"gte": 0, "lte": 1}
}
assert ItemSearch._format_query({"eo:cloud_cover": {"gte": 0, "lte": 1}}) == {
"eo:cloud_cover": {"gte": 0, "lte": 1}
}
assert ItemSearch._format_query(["eo:cloud_cover<=1"]) == {
"eo:cloud_cover": {"lte": "1"}
}
assert ItemSearch._format_query(["eo:cloud_cover<=1", "eo:cloud_cover>0"]) == {
"eo:cloud_cover": {"lte": "1", "gt": "0"}
}

0 comments on commit 6a1295e

Please sign in to comment.